Edits history of script submission #16451 for ' Bulk create messages (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Bulk create messages
     * Creates a bulk batch of messages.
    
    Any one of the following roles is required for this endpoint:
    
    |Legacy Role|Equivalent Permission Set Role|
    |-----|--------|
    |org.user.message.write|org.permission.message.create|
     */
    export async function main(
      auth: Kustomer,
      body: {
        id?: string;
        externalId?: string;
        customer?: string;
        conversation?: string;
        reference?: { message: string; type: "reply" | "replyAll" | "forward" };
        channel:
          | "email"
          | "sms"
          | "chat"
          | "facebook"
          | "twitter-dm"
          | "twitter-tweet"
          | "voice"
          | "instagram"
          | "whatsapp";
        preview?: string;
        subject?: string;
        direction?: "in" | "out";
        app: string;
        size?: number;
        related?: string;
        status?: "sent" | "received" | "error";
        error?: {
          status?: number;
          code?: string;
          title?: string;
          detail?: string;
          source?: {};
          meta?: {};
          links?: {};
        };
        errorAt?: string;
        auto?: false | true;
        sentAt?: string;
        source?: "bulk" | "satisfaction";
        shortcuts?: string[];
        kbArticles?: string[];
        attachments?:
          | string[]
          | {
              _id: string;
              name: string;
              contentType: string;
              contentLength: number;
              sourceId?: string;
            }[];
        location?: {
          name?: string;
          address?: string;
          address2?: string;
          address3?: string;
          latitude?: number;
          longitude?: number;
          countryCode?: string;
          countryName?: string;
          regionCode?: string;
          regionName?: string;
          cityName?: string;
          zipCode?: string;
          areaCode?: string;
        };
        meta?: {};
        custom?: {};
        sentiment?: { polarity: 0 | 1 | -1; confidence: number };
        createdAt?: string;
        modifiedAt?: string;
        createdBy?: string;
        modifiedBy?: string;
        importedAt?: string;
        lang?: string;
        queue?: {} | {};
      }[],
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/messages/bulk`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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