| 1 | import type * as socialmessaging from "@distilled.cloud/aws/socialmessaging"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { LinkedWhatsAppBusinessAccount } from "./LinkedWhatsAppBusinessAccount.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for `social-messaging:SendWhatsAppMessage`. |
| 8 | * |
| 9 | * Sends a WhatsApp message (text, template, media, or interactive) from one |
| 10 | * of the linked account's phone numbers. The `message` blob is the raw Meta |
| 11 | * Cloud API message payload and is sensitive — pass it as a `Uint8Array` or |
| 12 | * `Redacted<Uint8Array>`. |
| 13 | * |
| 14 | * The caller addresses one of the bound account's phone numbers per |
| 15 | * request; phone-number ARNs are provisioned by Meta under the WABA, so |
| 16 | * the deploy-time half grants `social-messaging:SendWhatsAppMessage` on `*`. |
| 17 | * Provide the implementation with |
| 18 | * `Effect.provide(AWS.SocialMessaging.SendWhatsAppMessageHttp)`. |
| 19 | * ### Sending Messages |
| 20 | * **Example:** Send a Text Message |
| 21 | * ```typescript |
| 22 | * // init — bind the operation to the linked WABA |
| 23 | * const sendMessage = yield* AWS.SocialMessaging.SendWhatsAppMessage(account); |
| 24 | * |
| 25 | * // runtime |
| 26 | * const { messageId } = yield* sendMessage({ |
| 27 | * originationPhoneNumberId: "phone-number-id-0123456789abcdef", |
| 28 | * metaApiVersion: "v20.0", |
| 29 | * message: new TextEncoder().encode( |
| 30 | * JSON.stringify({ |
| 31 | * messaging_product: "whatsapp", |
| 32 | * to: "+12065550100", |
| 33 | * type: "text", |
| 34 | * text: { body: "Hello from Alchemy" }, |
| 35 | * }), |
| 36 | * ), |
| 37 | * }); |
| 38 | * ``` |
| 39 | * |
| 40 | * @binding |
| 41 | */ |
| 42 | export interface SendWhatsAppMessage extends Binding.Service< |
| 43 | SendWhatsAppMessage, |
| 44 | "AWS.SocialMessaging.SendWhatsAppMessage", |
| 45 | ( |
| 46 | account: LinkedWhatsAppBusinessAccount, |
| 47 | ) => Effect.Effect< |
| 48 | ( |
| 49 | request: socialmessaging.SendWhatsAppMessageInput, |
| 50 | ) => Effect.Effect< |
| 51 | socialmessaging.SendWhatsAppMessageOutput, |
| 52 | socialmessaging.SendWhatsAppMessageError |
| 53 | > |
| 54 | > |
| 55 | > {} |
| 56 | export const SendWhatsAppMessage = Binding.Service<SendWhatsAppMessage>( |
| 57 | "AWS.SocialMessaging.SendWhatsAppMessage", |
| 58 | ); |