Edits history of script submission #16770 for ' Update conversation (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Update conversation
     * Updates a conversation based on the unique conversation ID.
     */
    export async function main(
      auth: Kustomer,
      id: string,
      replace: string | undefined,
      body:
        | {
            externalId?: string;
            name?: string;
            direction?: "in" | "out";
            priority?: number;
            satisfaction?: number;
            satisfactionLevel?: {
              form?: string;
              formResponse?: string;
              createdAt: string;
              updatedAt?: string;
              status:
                | "scheduled"
                | "offered"
                | "rated"
                | "commented"
                | "canceled"
                | "unresponded";
              scheduledFor?: string;
              firstAnswer?: string;
              sentAt?: string;
              score?: 0 | 1;
              rating?: number;
              channel?:
                | "email"
                | "sms"
                | "chat"
                | "facebook"
                | "twitter-dm"
                | "twitter-tweet"
                | "voice"
                | "instagram"
                | "instagram-comment"
                | "whatsapp"
                | "form";
              sentBy?: string;
              sentByTeams?: string[];
            };
            suggestedShortcuts?: { shortcutId: string; confidence: number }[];
            status?: "open" | "snoozed" | "done";
            replyChannel?: string;
            subStatus?: string;
            snooze?: {
              time?: string;
              status: "scheduled" | "canceled" | "elapsed";
            };
            tags?: string[];
            suggestedTags?: { tag: string; confidence: number }[];
            sentiment?: { polarity: 0 | 1 | -1; confidence: number };
            assignedUsers?: string[];
            assignedTeams?: string[];
            custom?: {};
            deleted?: false | true;
            ended?: false | true;
            endedAt?: string;
            endedReason?: string;
            endedBy?: string;
            endedByType?: "user" | "customer";
            locked?: false | true;
            rev?: number;
            defaultLang?: string;
            queue?: {};
          }
        | { customer?: string },
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/conversations/${id}`);
      for (const [k, v] of [["replace", replace]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        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