Edits history of script submission #16289 for ' Update a message (gorgias)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gorgias = {
      username: string;
      apiKey: string;
      domain: string;
    };
    /**
     * Update a message
     *
     */
    export async function main(
      auth: Gorgias,
      ticket_id: string,
      id: string,
      action: "force" | "retry" | "cancel" | undefined,
      body: {
        attachments?: {
          content_type: string;
          extra?: {};
          size: number;
          name: string;
          url: string;
          public?: false | true;
        }[];
        body_html?: string;
        body_text?: string;
        channel:
          | "aircall"
          | "api"
          | "chat"
          | "email"
          | "facebook"
          | "facebook-mention"
          | "facebook-messenger"
          | "facebook-recommendations"
          | "help-center"
          | "instagram-ad-comment"
          | "instagram-comment"
          | "instagram-mention"
          | "instagram-direct-message"
          | "internal-note"
          | "phone"
          | "sms"
          | "twitter"
          | "twitter-direct-message"
          | "yotpo-review";
        external_id?: string;
        failed_datetime?: string;
        from_agent: false | true;
        message_id?: string;
        receiver?: { id?: number; email?: string };
        sender?: { id?: number; email?: string };
        sent_datetime?: string;
        source?: {
          from?: { name?: string; address?: string };
          bcc?: { name?: string; address?: string }[];
          type?: string;
          to?: { name?: string; address?: string }[];
          cc?: { name?: string; address?: string }[];
        };
        subject?: string;
        via:
          | "aircall"
          | "api"
          | "chat"
          | "email"
          | "facebook"
          | "facebook-mention"
          | "facebook-messenger"
          | "facebook-recommendations"
          | "help-center"
          | "instagram-ad-comment"
          | "instagram-comment"
          | "instagram-mention"
          | "instagram-direct-message"
          | "internal-note"
          | "phone"
          | "sms"
          | "twitter"
          | "twitter-direct-message"
          | "yotpo-review"
          | "twilio"
          | "zendesk"
          | "form"
          | "self_service"
          | "yotpo"
          | "instagram"
          | "shopify"
          | "gorgias_chat"
          | "rule"
          | "helpdesk";
      },
    ) {
      const url = new URL(
        `https://${auth.domain}.gorgias.com/api/tickets/${ticket_id}/messages/${id}/`,
      );
      for (const [k, v] of [["action", action]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago