UNPKG

meta-cloud-api

Version:
90 lines (86 loc) 3.03 kB
import { R as ResponseSuccess, B as BaseAPI, a as RequesterClass } from './base-BhCbbsxB.js'; import { WabaConfigType } from './shared/types/config.js'; type MediaResponse = { id: string; url: string; mime_type: string; sha256: string; file_size: number; messaging_product: 'whatsapp'; }; type MediasResponse = { data: MediaResponse[]; paging: { cursors: { before: string; after: string; }; }; }; type UploadMediaResponse = { id: string; }; interface MediaClass { getMediaById(mediaId: string, phone_number_id?: string): Promise<MediaResponse>; uploadMedia(file: File, messagingProduct?: string): Promise<UploadMediaResponse>; deleteMedia(mediaId: string, phone_number_id?: string): Promise<ResponseSuccess>; downloadMedia(mediaUrl: string): Promise<Blob>; } /** * API for managing WhatsApp Media. * * This API allows you to: * - Get media information by ID * - Upload media files * - Delete media files * - Download media files from URLs */ declare class MediaApi extends BaseAPI implements MediaClass { private readonly endpoint; constructor(config: WabaConfigType, client: RequesterClass); /** * Retrieve media information by media ID. * * @param mediaId The media ID to retrieve information for * @param phone_number_id Optional phone number ID (defaults to configured one) * @returns Media information including URL, mime type, file size, etc. * * @example * const mediaInfo = await whatsappClient.media.getMediaById('media_id_123'); */ getMediaById(mediaId: string, phone_number_id?: string): Promise<MediaResponse>; /** * Upload a media file to WhatsApp. * * @param file The file to upload * @param messagingProduct The messaging product (default: 'whatsapp') * @returns Upload response containing the media ID * * @example * const file = new File([buffer], 'image.jpg', { type: 'image/jpeg' }); * const result = await whatsappClient.media.uploadMedia(file); */ uploadMedia(file: File, messagingProduct?: string): Promise<UploadMediaResponse>; /** * Delete a media file. * * @param mediaId The media ID to delete * @param phone_number_id Optional phone number ID (defaults to configured one) * @returns Response indicating success or failure * * @example * await whatsappClient.media.deleteMedia('media_id_123'); */ deleteMedia(mediaId: string, phone_number_id?: string): Promise<ResponseSuccess>; /** * Download media from a URL. * * @param mediaUrl The URL to download media from * @returns Blob containing the media data * * @example * const blob = await whatsappClient.media.downloadMedia('https://...'); */ downloadMedia(mediaUrl: string): Promise<Blob>; } export { MediaApi as M, type UploadMediaResponse as U, type MediaClass as a, type MediaResponse as b, type MediasResponse as c };