meta-cloud-api
Version:
TypeScript wrapper for Meta's Cloud API
354 lines (349 loc) • 13.5 kB
TypeScript
import { a as BaseClass, B as BaseAPI } from './base-CdGDdVEl.js';
import { WabaConfigType } from './types/config.js';
import { e as ResponseSuccess, R as RequesterClass } from './request-vYMaEfk5.js';
import { k as BusinessVerticalEnum } from './enums-BZd9T2ul.js';
/**
* Upload session information for creating upload sessions.
*/
interface UploadSession {
id: string;
video?: boolean;
}
/**
* Response from creating an upload session.
*/
interface UploadSessionResponse {
id: string;
}
/**
* Response from uploading business profile media.
*/
interface UploadBusinessProfileResponse {
h: string;
}
/**
* Upload handle information containing file details and handle.
*/
interface UploadHandle {
handle: string;
file_size: number;
upload_result: {
handle_type: string;
name: string;
};
}
/**
* Request parameters for creating upload session.
*/
interface CreateUploadSessionParams {
/**
* Length of the file to be uploaded in bytes.
*/
fileLength: number;
/**
* MIME type of the file (e.g., 'image/jpeg').
*/
fileType: string;
/**
* Name of the file with extension.
*/
fileName: string;
}
/**
* Request parameters for uploading media.
*/
interface UploadMediaParams {
/**
* The upload session ID from createUploadSession response.
*/
uploadId: string;
/**
* The binary data of the file (Buffer).
*/
file: Buffer;
}
/**
* Request parameters for getting upload handle.
*/
interface GetUploadHandleParams {
/**
* The upload session ID from createUploadSession response.
*/
uploadId: string;
}
/**
* Available fields that can be requested when retrieving a business profile.
*/
type BusinessProfileField = 'about' | 'address' | 'description' | 'email' | 'profile_picture_url' | 'websites' | 'vertical';
type BusinessProfileFieldsParam = BusinessProfileField[] | string;
/**
* Business profile data structure containing all profile information.
*/
interface BusinessProfileData {
/**
* The business's About text. This text appears in the business's profile, beneath its profile image,
* phone number, and contact buttons.
* - String cannot be empty
* - Strings must be between 1 and 139 characters
* - Rendered emojis are supported however their unicode values are not.
* Emoji unicode values must be Java- or JavaScript-escape encoded
* - Hyperlinks can be included but will not render as clickable links
* - Markdown is not supported
*/
about?: string;
/**
* Address of the business. Character limit 256.
*/
address?: string;
/**
* Description of the business. Character limit 512.
*/
description?: string;
/**
* The contact email address (in valid email format) of the business. Character limit 128.
*/
email?: string;
/**
* The messaging service used for the request. Always set it to "whatsapp" if you are using
* the WhatsApp Business API.
*/
messaging_product: string;
/**
* Profile picture URL.
*/
profile_picture_url?: string;
/**
* The URLs associated with the business. For instance, a website, Facebook Page, or Instagram.
* - You must include the http:// or https:// portion of the URL
* - There is a maximum of 2 websites with a maximum of 256 characters each
*/
websites?: string[];
/**
* Business category. This can be either an empty string or one of the predefined business categories.
* @see BusinessVerticalEnum for all available options
*/
vertical?: BusinessVerticalEnum | string;
}
/**
* Response structure for business profile GET requests.
*/
interface BusinessProfileResponse {
data: BusinessProfileData[];
}
/**
* Request structure for updating business profile.
*/
interface UpdateBusinessProfileRequest {
/**
* The messaging service used for the request. Always set it to "whatsapp" if you are using
* the WhatsApp Business API.
* @required
*/
messaging_product: string;
/**
* The business's About text. This text appears in the business's profile, beneath its profile image,
* phone number, and contact buttons.
* - String cannot be empty
* - Strings must be between 1 and 139 characters
* - Rendered emojis are supported however their unicode values are not.
* Emoji unicode values must be Java- or JavaScript-escape encoded
* - Hyperlinks can be included but will not render as clickable links
* - Markdown is not supported
*/
about?: string;
/**
* Address of the business. Character limit 256.
*/
address?: string;
/**
* Description of the business. Character limit 512.
*/
description?: string;
/**
* Business category. This can be either an empty string or one of the predefined business categories.
* @see BusinessVerticalEnum for all available options
*/
vertical?: BusinessVerticalEnum | string;
/**
* The contact email address (in valid email format) of the business. Character limit 128.
*/
email?: string;
/**
* The URLs associated with the business. For instance, a website, Facebook Page, or Instagram.
* - You must include the http:// or https:// portion of the URL
* - There is a maximum of 2 websites with a maximum of 256 characters each
*/
websites?: string[];
/**
* Handle of the profile picture. This handle is generated when you upload the binary file
* for the profile picture to Meta using the Resumable Upload API.
*/
profile_picture_handle?: string;
}
declare class BusinessProfileClass extends BaseClass {
/**
* Get your business profile.
* @param fields Specific fields to be returned in the response. If not specified, all fields will be returned.
*/
getBusinessProfile(fields?: BusinessProfileFieldsParam): Promise<BusinessProfileResponse>;
/**
* Update your business profile.
* @param updateRequest The request object containing the fields to update.
*/
updateBusinessProfile(updateRequest: UpdateBusinessProfileRequest): Promise<ResponseSuccess>;
/**
* Create an upload session for profile picture.
* @param fileLength Length of the file to be uploaded in bytes.
* @param fileType MIME type of the file (e.g., 'image/jpeg').
* @param fileName Name of the file.
*/
createUploadSession(fileLength: number, fileType: string, fileName: string): Promise<UploadSessionResponse>;
/**
* Upload media file to the upload session.
* @param uploadId The ID of the upload session.
* @param file The binary data of the file.
*/
uploadMedia(uploadId: string, file: Buffer): Promise<UploadBusinessProfileResponse>;
/**
* Get the upload handle information.
* @param uploadId The ID of the upload session.
*/
getUploadHandle(uploadId: string): Promise<UploadHandle>;
}
/**
* API for managing WhatsApp Business Profiles and profile pictures.
*
* This API allows you to:
* - Get business profile information
* - Update business profile details
* - Upload profile pictures using a three-step process:
* 1. Create an upload session
* 2. Upload the image binary data
* 3. Get the upload handle to use when updating the profile
*/
declare class BusinessProfileApi extends BaseAPI implements BusinessProfileClass {
private readonly endpoint;
constructor(config: WabaConfigType, client: RequesterClass);
/**
* Get your business profile information.
*
* Use this method to retrieve details about your WhatsApp business profile, including
* about text, address, description, email, profile picture URL, websites, and vertical.
*
* @param fields Fields to be returned in the response. If not specified, all fields will be returned.
* Possible values: about, address, description, email, profile_picture_url, websites, vertical
* @returns The business profile information.
*
* @example
* // Get all business profile fields
* const profile = await whatsappClient.businessProfile.getBusinessProfile();
*
* // Get specific business profile fields
* const profile = await whatsappClient.businessProfile.getBusinessProfile('about,address,email');
*
* // Using the BusinessProfileFieldsParam type
* const profile = await whatsappClient.businessProfile.getBusinessProfile(['about', 'address', 'email']);
*/
getBusinessProfile(fields?: BusinessProfileFieldsParam): Promise<BusinessProfileResponse>;
/**
* Update your business profile.
*
* Use this method to update one or more fields of your WhatsApp business profile.
*
* @param updateRequest The request object containing the fields to update.
* - messaging_product: Required. Always set to "whatsapp".
* - about: Optional. Business's About text (1-139 characters).
* - address: Optional. Business address (max 256 characters).
* - description: Optional. Business description (max 512 characters).
* - vertical: Optional. Business category (use BusinessVerticalEnum for type safety).
* - email: Optional. Contact email (valid format, max 128 characters).
* - websites: Optional. Up to 2 URLs (max 256 characters each).
* - profile_picture_handle: Optional. Handle from upload process.
* @returns Response indicating success or failure.
*
* @example
* // Update business profile with multiple fields including vertical using enum
* await whatsappClient.businessProfile.updateBusinessProfile({
* messaging_product: 'whatsapp',
* about: 'We provide excellent service',
* email: 'contact@example.com',
* websites: ['https://example.com'],
* vertical: BusinessVerticalEnum.RETAIL
* });
*/
updateBusinessProfile(updateRequest: UpdateBusinessProfileRequest): Promise<ResponseSuccess>;
/**
* Create an upload session for a profile picture.
*
* This is the first step in the profile picture upload process.
*
* @param fileLength Length of the file to be uploaded in bytes.
* @param fileType MIME type of the file (e.g., 'image/jpeg').
* @param fileName Name of the file with extension.
* @returns Response containing the upload session ID needed for the next step.
*
* @example
* // Create upload session for profile picture
* const session = await whatsappClient.businessProfile.createUploadSession(
* fileBuffer.length,
* 'image/jpeg',
* 'profile.jpg'
* );
* const uploadSessionId = session.upload_session_id;
*/
createUploadSession(fileLength: number, fileType: string, fileName: string): Promise<UploadSessionResponse>;
/**
* Upload media file to the upload session.
*
* This is the second step in the profile picture upload process.
* Upload the binary content of the file to the previously created upload session.
*
* @param uploadId The upload session ID from createUploadSession response.
* @param file The binary data of the file (Buffer).
* @returns Response indicating success or failure.
*
* @example
* // Upload the actual file content
* await whatsappClient.businessProfile.uploadMedia(
* uploadSessionId,
* fileBuffer
* );
*/
uploadMedia(uploadId: string, file: Buffer): Promise<UploadBusinessProfileResponse>;
/**
* Get the upload handle information.
*
* This is the third step in the profile picture upload process.
* After uploading the file, get the handle to use when updating the profile.
*
* @param uploadId The upload session ID from createUploadSession response.
* @returns Response containing the upload handle information.
*
* @example
* // Complete profile picture update process
* // 1. Create upload session
* const session = await whatsappClient.businessProfile.createUploadSession(
* fileBuffer.length, 'image/jpeg', 'profile.jpg'
* );
*
* // 2. Upload the image data
* await whatsappClient.businessProfile.uploadMedia(
* session.upload_session_id, fileBuffer
* );
*
* // 3. Get the handle for the uploaded file
* const handleInfo = await whatsappClient.businessProfile.getUploadHandle(
* session.upload_session_id
* );
*
* // 4. Update profile with new picture and business information
* await whatsappClient.businessProfile.updateBusinessProfile({
* messaging_product: 'whatsapp',
* profile_picture_handle: handleInfo.handle,
* vertical: BusinessVerticalEnum.RESTAURANT,
* about: 'Delicious food served daily'
* });
*/
getUploadHandle(uploadId: string): Promise<UploadHandle>;
}
export { BusinessProfileApi as B, type CreateUploadSessionParams as C, type GetUploadHandleParams as G, type UpdateBusinessProfileRequest as U, BusinessProfileClass as a, type BusinessProfileData as b, type BusinessProfileField as c, type BusinessProfileFieldsParam as d, type BusinessProfileResponse as e, type UploadBusinessProfileResponse as f, type UploadHandle as g, type UploadMediaParams as h, type UploadSession as i, type UploadSessionResponse as j };