UNPKG

meta-cloud-api

Version:
508 lines (504 loc) 14.9 kB
import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js'; import { WabaConfigType } from './shared/types/config.js'; /** * Enum for Flow Status */ declare enum FlowStatusEnum { Draft = "DRAFT", Published = "PUBLISHED", Throttled = "THROTTLED", Blocked = "BLOCKED", Deprecated = "DEPRECATED" } /** * Enum for Flow Categories */ declare enum FlowCategoryEnum { SignUp = "SIGN_UP", SignIn = "SIGN_IN", AppointmentBooking = "APPOINTMENT_BOOKING", LeadGeneration = "LEAD_GENERATION", ContactUs = "CONTACT_US", CustomerSupport = "CUSTOMER_SUPPORT", Survey = "SURVEY", Other = "OTHER" } declare enum FlowActionEnum { INIT = "INIT", BACK = "BACK", DATA_EXCHANGE = "data_exchange" } /** * Enum for Flow Types in webhook handlers * Used to register handlers for specific flow events */ declare enum FlowTypeEnum { /** Health check/ping requests */ Ping = "ping", /** Data exchange requests */ Change = "data_exchange", /** Error notification requests */ Error = "error", /** Match all flow action types */ All = "*" } type FlowType = (typeof FlowTypeEnum)[keyof typeof FlowTypeEnum]; /** * Flow Validation Error Pointer */ interface FlowValidationErrorPointer { line_start: number; line_end: number; column_start: number; column_end: number; path: string; } /** * Flow Validation Error */ interface FlowValidationError { error: string; error_type: string; message: string; line_start: number; line_end: number; column_start: number; column_end: number; pointers: FlowValidationErrorPointer[]; } /** * Flow Item */ interface Flow { id: string; name: string; status: FlowStatusEnum; categories: FlowCategoryEnum[]; validation_errors: FlowValidationError[]; } /** * Pagination Cursors */ interface PaginationCursors { before: string; after: string; } /** * Pagination Object */ interface Pagination { cursors: PaginationCursors; } /** * Flows List Response */ interface FlowsListResponse { data: Flow[]; paging: Pagination; } /** * Flow Asset */ interface FlowAsset { name: string; asset_type: string; download_url: string; } /** * Flow Assets Response */ interface FlowAssetsResponse { data: FlowAsset[]; paging: Pagination; } /** * Flow Preview */ interface FlowPreview { preview_url: string; expires_at: string; } /** * Flow Preview Response */ interface FlowPreviewResponse { preview: FlowPreview; id: string; } /** * Flow Migration Result */ interface FlowMigrationResult { source_name: string; source_id: string; migrated_id: string; } /** * Flow Migration Failure */ interface FlowMigrationFailure { source_name: string; error_code: string; error_message: string; } /** * Create Flow Response */ interface CreateFlowResponse { id: string; success: boolean; validation_errors?: FlowValidationError[]; } /** * Update Flow Response */ interface UpdateFlowResponse { success: boolean; validation_errors?: FlowValidationError[]; } /** * Flow Migration Response */ interface FlowMigrationResponse { migrated_flows: FlowMigrationResult[]; failed_flows: FlowMigrationFailure[]; } /** * Validate Flow JSON Response */ interface ValidateFlowJsonResponse { valid: boolean; success: boolean; validation_errors?: FlowValidationError[]; } /** * WhatsApp Flow Endpoint - Health Check Request * Represents the structure of a health check request */ interface FlowHealthCheckRequest { action: 'ping'; version: '3.0'; } /** * WhatsApp Flow Endpoint - Health Check Response * The expected response structure for health check requests */ interface FlowHealthCheckResponse { data: { status: 'active'; }; } /** * WhatsApp Flow Endpoint - Data Exchange Request * Represents the structure of a data exchange request */ interface FlowDataExchangeRequest { version: '3.0'; action: FlowActionEnum; screen: string; flow_token: string; data?: Record<string, any> & { error_message?: string; }; } /** * WhatsApp Flow Endpoint - Data Exchange Response * The expected response structure for data exchange requests */ interface FlowDataExchangeResponse { screen?: string; data?: Record<string, any | { error_message?: string; }>; } /** * WhatsApp Flow Endpoint - Success Screen Response * The expected response structure for success screen requests */ interface FlowSuccessScreenResponse { screen: 'SUCCESS'; data: { extension_message_response?: { params?: { flow_token: string; [key: string]: string; }; }; }; } /** * WhatsApp Flow Endpoint - Error Notification Request * Represents the structure of an error notification request */ interface FlowErrorNotificationRequest { version: '3.0'; action: Exclude<FlowActionEnum, FlowActionEnum.BACK>; screen: string; flow_token: string; data: { error: string; error_message: string; }; } /** * WhatsApp Flow Endpoint - Error Notification Response * The expected response structure for error notification requests */ interface FlowErrorNotificationResponse { acknowledged: boolean; } /** * WhatsApp Flow Endpoint - Comprehensive Request Object * A combined type that includes all possible fields from different request types * with all fields being optional for flexibility */ interface FlowEndpointRequest { version?: '3.0'; action?: 'ping' | FlowActionEnum; screen?: string; flow_token?: string; data?: Record<string, any> & { error_key?: string; error_message?: string; }; } /** * WhatsApp Flow Endpoint - Response * Union type for all possible response types from a Flow endpoint */ type FlowEndpointResponse = FlowHealthCheckResponse | FlowDataExchangeResponse | FlowErrorNotificationResponse | FlowSuccessScreenResponse; interface FlowClass { /** * List Flows * * @param wabaId - The WABA ID * @returns Promise with the list of flows */ listFlows(wabaId: string): Promise<FlowsListResponse>; /** * Create Flow * * @param wabaId - The WABA ID * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id * @returns Promise with the created flow ID */ createFlow(wabaId: string, data: { name: string; categories?: FlowCategoryEnum[]; endpoint_uri?: string; clone_flow_id?: string; flow_json?: string; publish?: boolean; }): Promise<CreateFlowResponse>; /** * Get Flow * * @param flowId - The flow ID * @param fields - Optional fields to return * @param dateFormat - Optional date format * @returns Promise with the flow details */ getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>; /** * Update Flow Metadata * * @param flowId - The flow ID * @param data - The flow metadata to update * @returns Promise with the success status */ updateFlowMetadata(flowId: string, data: { name?: string; categories?: FlowCategoryEnum[]; endpoint_uri?: string; application_id?: string; }): Promise<ResponseSuccess>; /** * Delete Flow * * @param flowId - The flow ID * @returns Promise with the success status */ deleteFlow(flowId: string): Promise<ResponseSuccess>; /** * List Assets (Get Flow JSON URL) * * @param flowId - The flow ID * @returns Promise with the list of assets */ listAssets(flowId: string): Promise<FlowAssetsResponse>; /** * Update Flow JSON * * @param flowId - The flow ID * @param data - The asset data including asset_type, file, and name * @returns Promise with the success status and validation errors */ updateFlowJson(flowId: string, data: { file: Blob | Buffer | object; name?: string; }): Promise<UpdateFlowResponse>; /** * Validate Flow JSON by attempting an update without publishing. * This is a convenience method; the API doesn't have a dedicated validation endpoint. * * @param flowId - The ID of the Flow (must exist, can be in DRAFT status). * @param flowJsonData - The Flow JSON content as a Buffer, JSON object, or Blob. * @returns Promise indicating if the JSON is valid and includes validation errors if any. */ validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>; /** * Publish Flow * * @param flowId - The flow ID * @returns Promise with the success status */ publishFlow(flowId: string): Promise<ResponseSuccess>; /** * Deprecate Flow * * @param flowId - The flow ID * @returns Promise with the success status */ deprecateFlow(flowId: string): Promise<ResponseSuccess>; /** * Migrate Flows * * @param wabaId - The destination WABA ID * @param data - The migration data including source_waba_id and optional source_flow_names * @returns Promise with migration results */ migrateFlows(wabaId: string, data: { source_waba_id: string; source_flow_names?: string[]; }): Promise<FlowMigrationResponse>; } /** * API for managing WhatsApp Flows. * * This API allows you to: * - List flows * - Create flows * - Get flow details and previews * - Update flow metadata and JSON * - Delete flows * - Publish and deprecate flows * - Migrate flows between WABAs * - Validate flow JSON */ declare class FlowApi extends BaseAPI implements FlowClass { constructor(config: WabaConfigType, client: RequesterClass); /** * List Flows * * @param wabaId - The WABA ID * @returns Promise with the list of flows */ listFlows(wabaId: string): Promise<FlowsListResponse>; /** * Create Flow * * @param wabaId - The WABA ID * @param data - The flow data including name, categories, endpoint_uri, and optional clone_flow_id * @returns Promise with the created flow ID and validation errors if any */ createFlow(wabaId: string, data: { name: string; categories?: FlowCategoryEnum[]; endpoint_uri?: string; clone_flow_id?: string; flow_json?: string; publish?: boolean; }): Promise<CreateFlowResponse>; /** * Get Flow details * * @param flowId - The flow ID * @param fields - Optional fields to return (e.g., 'name,status,preview.invalidate(false)') * @param dateFormat - Optional date format * @returns Promise with the flow details or preview response */ getFlow(flowId: string, fields?: string, dateFormat?: string): Promise<Flow | FlowPreviewResponse>; /** * Get Flow Preview URL * * @param flowId - The flow ID * @param invalidate - Optional. If true, invalidates existing preview and generates a new one. Defaults to false. * @returns Promise with the flow preview details */ getFlowPreview(flowId: string, invalidate?: boolean): Promise<FlowPreviewResponse>; /** * Update Flow Metadata * * @param flowId - The flow ID * @param data - The flow metadata to update (name, categories, endpoint_uri, application_id) * @returns Promise with the success status */ updateFlowMetadata(flowId: string, data: { name?: string; categories?: FlowCategoryEnum[]; endpoint_uri?: string; application_id?: string; }): Promise<ResponseSuccess>; /** * Delete Flow (only works if the Flow is in DRAFT status) * * @param flowId - The flow ID * @returns Promise with the success status */ deleteFlow(flowId: string): Promise<ResponseSuccess>; /** * List Assets (e.g., get Flow JSON download URL) * * @param flowId - The flow ID * @returns Promise with the list of assets */ listAssets(flowId: string): Promise<FlowAssetsResponse>; /** * Update Flow JSON by uploading a file, buffer, JSON object, or Blob. * * @param flowId - The flow ID * @param data - Object containing the file data and optional name. * @param data.file - The Flow JSON content as a Buffer, JSON object, or Blob. * @param data.name - Optional name for the asset, defaults to 'flow.json'. * @returns Promise with the success status and validation errors, if any. */ updateFlowJson(flowId: string, data: { file: Blob | Buffer | object; name?: string; }): Promise<UpdateFlowResponse>; /** * Validate Flow JSON by attempting an update without publishing. * This is a convenience method; the API doesn't have a dedicated validation endpoint. * * @param flowId - The ID of the Flow (must exist, can be in DRAFT status). * @param flowJsonData - The Flow JSON content as a file path (string), Buffer, JSON object, or Blob. * @returns Promise indicating if the JSON is valid and includes validation errors if any. */ validateFlowJson(flowId: string, flowJsonData: Blob | Buffer | object): Promise<ValidateFlowJsonResponse>; /** * Publish Flow * * @param flowId - The flow ID * @returns Promise with the success status */ publishFlow(flowId: string): Promise<ResponseSuccess>; /** * Deprecate Flow * * @param flowId - The flow ID * @returns Promise with the success status */ deprecateFlow(flowId: string): Promise<ResponseSuccess>; /** * Migrate Flows between WABAs * * @param destinationWabaId - The destination WABA ID * @param data - The migration data including source_waba_id and optional source_flow_names * @returns Promise with migration results (successes and failures) */ migrateFlows(destinationWabaId: string, data: { source_waba_id: string; source_flow_names?: string[]; }): Promise<FlowMigrationResponse>; } export { type CreateFlowResponse as C, FlowApi as F, type UpdateFlowResponse as U, type ValidateFlowJsonResponse as V, type Flow as a, type FlowType as b, FlowActionEnum as c, type FlowAssetsResponse as d, FlowCategoryEnum as e, type FlowClass as f, type FlowEndpointRequest as g, type FlowEndpointResponse as h, type FlowMigrationResponse as i, type FlowPreviewResponse as j, type FlowsListResponse as k, FlowStatusEnum as l, type FlowValidationError as m, FlowTypeEnum as n, type FlowDataExchangeRequest as o, type FlowErrorNotificationRequest as p, type FlowHealthCheckRequest as q };