whatsapp-business-serverless
Version:
Connector for the WhatsApp Business APIs with TypeScript support. Serverless version.
111 lines (110 loc) • 5.43 kB
TypeScript
import { BusinessPhoneNumber, BusinessProfile, BusinessProfileFieldsQuery, DefaultResponse, GetBusinessPhoneNumberResponse, GetMediaResponse, HealthStatusResponse, Message, RegisterPhoneArgs, RequestPhoneNumberVerificationCodeArgs, SendMessageResponse, SetUpTwoFactorAuthArgs, UpdateBusinessProfilePayload, UpdateIdentityCheckState, UploadMediaPayload, UploadMediaResponse, VerifyPhoneNumberArgs } from "./types";
import { createRestClient } from "./utils/restClient";
interface WABAClientArgs {
apiToken: string;
phoneId: string;
accountId: string;
}
/**
* Connector for the Whatsapp Cloud API.
*
* documentation: https://developers.facebook.com/docs/whatsapp/cloud-api/guides
*/
export declare class WABAClient {
restClient: ReturnType<typeof createRestClient>;
phoneId: string;
accountId: string;
constructor({ apiToken, phoneId, accountId }: WABAClientArgs);
/**
*
* Retrieves your business profile. Customers can view your business profile by clicking your business's name or number in a conversation thread.
*
* @param fields you can specify which data you want to get from your business. If not passed, defaults to all fields.
*/
getBusinessProfile(fields?: BusinessProfileFieldsQuery): Promise<BusinessProfile>;
/**
* @param payload provide the fields that you wish to update.
*/
updateBusinessProfile(payload: UpdateBusinessProfilePayload): Promise<DefaultResponse>;
/**
* All media files sent through this endpoint are encrypted and persist for 30 days, unless they are deleted earlier.
*
* A successful response returns an object with the uploaded media's ID.
*
* @param file - File object (File API) or Blob for Cloudflare Workers compatibility
* @param type - Media type (image, video, audio, document)
*/
uploadMedia({ file, type }: {
file: File | Blob;
type: string;
}): Promise<UploadMediaResponse>;
/**
* Upload media from a file path (Node.js environments only)
* For Cloudflare Workers, use uploadMedia with File/Blob instead
*
* @deprecated Use uploadMedia with File/Blob for better compatibility
*/
uploadMediaFromPath({ file, type }: Omit<UploadMediaPayload, "messaging_product">): void;
/**
* Retrieves your media’s URL. Use the returned URL to download the media file. Note that clicking this URL (i.e. performing a generic GET) will not return the media; you must include an access token.
*
* A successful response includes an object with a media url. The URL is only valid for 5 minutes.
*/
getMedia(mediaId: string): Promise<GetMediaResponse>;
deleteMedia(mediaId: string): Promise<DefaultResponse>;
/**
* Download media and return as ArrayBuffer (Cloudflare Workers compatible)
* @param mediaUrl your media's URL
* @returns Promise<ArrayBuffer> - The media file as ArrayBuffer
*/
downloadMedia(mediaUrl: string): Promise<ArrayBuffer>;
/**
* Download media to file path (Node.js environments only)
* For Cloudflare Workers, use downloadMedia() to get ArrayBuffer instead
*
* @deprecated Use downloadMedia() for better compatibility
*/
downloadMediaToPath(mediaUrl: string, pathToSaveFile: string): Promise<void>;
/**
* Yu can use the API to send the following free-form messages types:
* Text
* Reaction
* Media
* Location
* Contacts
* Interactive
* Address
* messages
* template
*
* For more information refer here: https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-messages
*
* If you are working with template messages refer here: https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates
*
*/
sendMessage(payload: Omit<Message, "messaging_product">): Promise<SendMessageResponse>;
/**
* When you receive an incoming message from Webhooks,
* you can use the /messages endpoint to mark the message as
* read by changing its status to read. Messages marked as read display two blue check marks alongside their timestamp.
*/
markMessageAsRead(message_id: string): Promise<DefaultResponse>;
getBusinessPhoneNumbers(): Promise<GetBusinessPhoneNumberResponse>;
getSingleBusinessPhoneNumber(phoneNumberId: string): Promise<BusinessPhoneNumber>;
/**
* You may want us to verify a customer's identity before we deliver your message to them.
* You can have us do this by enabling the identity change check setting on your business phone number.
*/
updateIdentityCheckState({ enable_identity_key_check }: UpdateIdentityCheckState): Promise<DefaultResponse>;
requestPhoneNumberVerificationCode({ phoneNumberId, ...payload }: RequestPhoneNumberVerificationCodeArgs): Promise<DefaultResponse>;
verifyPhoneNumberCode({ phoneNumberId, ...payload }: VerifyPhoneNumberArgs): Promise<DefaultResponse>;
registerPhone({ phoneNumberId, ...payload }: RegisterPhoneArgs): Promise<DefaultResponse>;
deregisterPhone(phoneNumber: string): Promise<DefaultResponse>;
setupTwoStepAuth({ phoneNumberId, ...payload }: SetUpTwoFactorAuthArgs): Promise<DefaultResponse>;
/**
*
* @param nodeId is optional, defaults to the account_id
*/
getHealthStatus(nodeId?: string): Promise<HealthStatusResponse>;
}
export {};