Edits history of script submission #22802 for ' List Message Templates (whatsapp_business)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * List Message Templates
     * List the message templates of the WhatsApp Business Account, optionally filtered by name or status.
     */
    export async function main(
      auth: RT.WhatsappBusiness,
      name: string | undefined,
      status:
        | "APPROVED"
        | "PENDING"
        | "REJECTED"
        | "PAUSED"
        | "DISABLED"
        | undefined,
      limit: number | undefined,
      after: string | undefined
    ) {
      const apiVersion = auth.api_version || "v25.0"
      const url = new URL(
        `https://graph.facebook.com/${apiVersion}/${auth.business_account_id}/message_templates`
      )
      url.searchParams.append(
        "fields",
        "id,name,status,category,language,components,quality_score"
      )
      if (name !== undefined && name !== "") {
        url.searchParams.append("name", name)
      }
      if (status !== undefined) {
        url.searchParams.append("status", status)
      }
      url.searchParams.append("limit", String(limit ?? 100))
      if (after !== undefined && after !== "") {
        url.searchParams.append("after", after)
      }
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago