Edits history of script submission #23352 for ' Respond to Event (outlook)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Respond to Event
     * Accept, tentatively accept or decline a meeting invitation you received, optionally with a comment sent to the organizer. The comment is only sent when `send_response` is on, and the organizer cannot respond to their own meeting. Requires Calendars.ReadWrite (a connection default).
     */
    export async function main(
      auth: RT.Outlook,
      event_id: string,
      response_type: "accept" | "tentativelyAccept" | "decline",
      comment: string | undefined,
      send_response: boolean = true
    ) {
      const body: { [key: string]: any } = { sendResponse: send_response }
      // Graph rejects a comment when no response is sent
      if (send_response && comment != null && comment !== "") body.comment = comment
    
      const response = await fetch(
        `https://graph.microsoft.com/v1.0/me/events/${encodeURIComponent(
          event_id
        )}/${response_type}`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify(body),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      // 202 Accepted with an empty body
      return { success: true }
    }
    

    Submitted by hugo989 6 hours ago

  • bunnative
    //native
    
    /**
     * Respond to Event
     * Accept, tentatively accept or decline a meeting invitation you received, optionally with a comment sent to the organizer. The comment is only sent when `send_response` is on, and the organizer cannot respond to their own meeting. Requires Calendars.ReadWrite on the connection.
     */
    export async function main(
      auth: RT.Outlook,
      event_id: string,
      response_type: "accept" | "tentativelyAccept" | "decline",
      comment: string | undefined,
      send_response: boolean = true
    ) {
      const body: { [key: string]: any } = { sendResponse: send_response }
      // Graph rejects a comment when no response is sent
      if (send_response && comment != null && comment !== "") body.comment = comment
    
      const response = await fetch(
        `https://graph.microsoft.com/v1.0/me/events/${encodeURIComponent(
          event_id
        )}/${response_type}`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify(body),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      // 202 Accepted with an empty body
      return { success: true }
    }
    

    Submitted by hugo989 6 hours ago