Edits history of script submission #23843 for ' Create Side Conversation (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Side Conversation
     * Start a side conversation on a ticket (requires the Collaboration add-on, included in Suite Professional and up). `to` is a list of participants of one kind: `{ "email": "person@example.com", "name": "Person" }` for email, `{ "user_id": 123 }` for an agent, `{ "support_group_id": 123, "support_agent_id": 456 }` for a child ticket, `{ "slack_workspace_id": "T123", "slack_channel_id": "C456" }` for Slack, `{ "msteams_channel_id": "19:..." }` for Microsoft Teams.
     */
    export async function main(
      auth: RT.Zendesk,
      ticket_id: number,
      subject: string,
      body: string,
      to: { [key: string]: any }[]
    ) {
      const response = await fetch(
        `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations`,
        {
          method: "POST",
          headers: {
            Authorization: auth.token
              ? `Bearer ${auth.token}`
              : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({ message: { subject, body, to } }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago