# @raphaelvserafim/client-api-whatsapp > With our API, you can send text, audio, video, and image messages quickly and easily. Adapt to your business communication needs comprehensively. Version: 2.0.0 ## Installation npm i @raphaelvserafim/client-api-whatsapp ## Initialization import { Wame, TypeMessage, StatusPresence } from '@raphaelvserafim/client-api-whatsapp'; const wa = new Wame({ server: "https://us.api-wa.me", key: "YOUR_KEY" }); // `WhatsApp` is exported as a deprecated alias of `Wame` (same behavior). ## Multi-channel (WhatsApp / Instagram / Messenger) // `provider` selects the channel: "whatsapp" (default), "instagram", "messenger". // Set it per call on the send body, or as a client default via new Wame({ ..., provider }). await wa.message.send({ type: TypeMessage.TEXT, body: { to, text: "Hi", provider: "instagram" } }); // Supported on: text, template, button, audio, image, video, document sends. // Webhook events expose provider, official, instance (your instance key — route by it, // since instanceId is the IG/Page account id on Instagram/Messenger) and, for messages, // fromUserId + profile + chatType. Instagram story replies carry context.story.url. ## Available Services - wa.instance → InstanceService - wa.message → MessageService - wa.chat → ChatService - wa.call → CallService - wa.label → LabelService - wa.action → ActionService - wa.contact → ContactService - wa.group → GroupService - wa.community → CommunityService - wa.business → BusinessService - wa.newsletter → NewsletterService - wa.status → StatusService - wa.templates → TemplatesService - wa.analytics → AnalyticsService - wa.calling → CallingService - wa.conversation → ConversationService ## wa.instance // connect(): Promise await wa.instance.connect(); // info(): Promise await wa.instance.info(); // logout(): Promise await wa.instance.logout(); // setting(data: { markMessageRead: boolean; saveMedia: boolean; receiveStatusMessage: boolean; receivePresence: boolean }): Promise await wa.instance.setting({ /* data */ }); // updateWebhook(body: WebhookBody): Promise await wa.instance.updateWebhook({ /* WebhookBody */ }); // pairingCode(phoneNumber: string): Promise await wa.instance.pairingCode("phoneNumber"); // addMongoDb(uri: string, dbName: string): Promise await wa.instance.addMongoDb("uri", "dbName"); // setProxy(proxy: string): Promise await wa.instance.setProxy("proxy"); // resync(): Promise await wa.instance.resync(); // restart(): Promise await wa.instance.restart(); // updateProfileStatus(text: string): Promise await wa.instance.updateProfileStatus("text"); // updateProfilePicture(url: string): Promise await wa.instance.updateProfilePicture("url"); // removeProfilePicture(): Promise await wa.instance.removeProfilePicture(); // updateProfileName(name: string): Promise await wa.instance.updateProfileName("name"); // mobileRegisterPrepare(data: MobileRegisterData): Promise await wa.instance.mobileRegisterPrepare({ /* MobileRegisterData */ }); // mobileRequestCode(method: string): Promise await wa.instance.mobileRequestCode("method"); // mobileVerifyCode(code: string): Promise await wa.instance.mobileVerifyCode("code"); // webhookStatistics(): Promise await wa.instance.webhookStatistics(); // importWebSession(session: object): Promise await wa.instance.importWebSession({ /* object */ }); // officialRegister(pin: string): Promise await wa.instance.officialRegister("pin"); // officialDeregister(): Promise await wa.instance.officialDeregister(); // officialTwoStepPin(pin: string): Promise await wa.instance.officialTwoStepPin("pin"); ## wa.message // list(phoneNumber: string, page?: number, limit?: number): Promise await wa.message.list("phoneNumber", 0, 0); // send(data: { type: TypeMessage; body: { to: string; msgId?: string; header?: HeaderMedia; status?: StatusPresence; text?: string; url?: string; caption?: string; mimetype?: string; fileName?: string; contact?: Contact; location?: Location; name?: string; options?: string[]; sections?: Section[]; buttons?: Buttons[]; footer?: string; description?: string; title?: string; buttonText?: string; thumbnailUrl?: string; sourceUrl?: string; referenceId?: string; code?: string; key?: string; merchantName?: string; keyType?: "CNPJ" | "CPF" | "EMAIL" | "PHONE"; subtotal?: string; totalAmount?: string; items?: Items[]; provider?: Provider; }; }, reply?: boolean): Promise await wa.message.send({ /* data */ }, false); // forward(to: string, msgId: string): Promise await wa.message.forward("to", "msgId"); // sendSticker(to: string, url: string): Promise await wa.message.sendSticker("to", "url"); // sendVideoNote(to: string, url: string): Promise await wa.message.sendVideoNote("to", "url"); // sendPoll(to: string, name: string, values: Array, selectableCount?: number): Promise await wa.message.sendPoll("to", "name", [], 0); // sendEvent(data: EventData): Promise await wa.message.sendEvent({ /* EventData */ }); // pin(id: string, duration?: number): Promise await wa.message.pin("id", 0); // sendCallLink(to: string, type: string, caption?: string): Promise await wa.message.sendCallLink("to", "type", "caption"); // sendImageBase64(to: string, base64: string, caption?: string): Promise await wa.message.sendImageBase64("to", "base64", "caption"); // sendAudioBase64(to: string, base64: string): Promise await wa.message.sendAudioBase64("to", "base64"); // sendDocumentBase64(to: string, base64: string, mimetype: string, fileName?: string, caption?: string): Promise await wa.message.sendDocumentBase64("to", "base64", "mimetype", "fileName", "caption"); // sendContacts(data: SendContactsData): Promise await wa.message.sendContacts({ /* SendContactsData */ }); // sendLiveLocation(data: LiveLocationData): Promise await wa.message.sendLiveLocation({ /* LiveLocationData */ }); // unpin(id: string): Promise await wa.message.unpin("id"); // getDetails(messageId: string): Promise await wa.message.getDetails("messageId"); // getMedia(messageId: string, format?: string): Promise await wa.message.getMedia("messageId", "format"); // sendProduct(data: ProductMessageData): Promise await wa.message.sendProduct({ /* ProductMessageData */ }); // sendGroupInvite(data: GroupInviteMessageData): Promise await wa.message.sendGroupInvite({ /* GroupInviteMessageData */ }); // requestPhone(to: string): Promise await wa.message.requestPhone("to"); // createCallLink(type: string): Promise await wa.message.createCallLink("type"); // markRead(messageId: string, typing?: boolean): Promise await wa.message.markRead("messageId", false); // sendTemplate(data: SendTemplateData): Promise await wa.message.sendTemplate({ /* SendTemplateData */ }); // sendOrderDetails(data: OrderDetailsData): Promise await wa.message.sendOrderDetails({ /* OrderDetailsData */ }); // sendOrderStatus(data: OrderStatusData): Promise await wa.message.sendOrderStatus({ /* OrderStatusData */ }); // sendLocationRequest(to: string, text: string): Promise await wa.message.sendLocationRequest("to", "text"); // sendAd(data: AdMessageData): Promise await wa.message.sendAd({ /* AdMessageData */ }); // sendProductList(data: ProductListData): Promise await wa.message.sendProductList({ /* ProductListData */ }); // delete(id: string): Promise await wa.message.delete("id"); // edit(id: string, text: string): Promise await wa.message.edit("id", "text"); // update(id: string, text: string): Promise await wa.message.update("id", "text"); // keep(id: string): Promise await wa.message.keep("id"); ## wa.chat // list(provider?: Provider): Promise await wa.chat.list("whatsapp"); // modify(id: string, action: 'markRead' | 'pin', value: boolean): Promise await wa.chat.modify("id", "markRead", false); // delete(chatId: string): Promise await wa.chat.delete("chatId"); // messages(chatId: string, page?: number, limit?: number): Promise await wa.chat.messages("chatId", 0, 0); // presenceSubscribe(jid: string): Promise await wa.chat.presenceSubscribe("jid"); // disappearing(jid: string, expiration: number): Promise await wa.chat.disappearing("jid", 0); // privacy(): Promise await wa.chat.privacy(); ## wa.call // call(to: string, isVideo?: boolean): Promise await wa.call.call("to", false); // reject(id: string, from: string): Promise await wa.call.reject("id", "from"); // accept(callId: string, callFrom: string): Promise await wa.call.accept("callId", "callFrom"); // end(callId: string, peerJid: string): Promise await wa.call.end("callId", "peerJid"); // sendAudio(callId: string, data: CallAudioData): Promise await wa.call.sendAudio("callId", { /* CallAudioData */ }); ## wa.label // list(): Promise<{ status: number; data: LabelInfo[] }> await wa.label.list(); // create(name: string, labelId?: string): Promise await wa.label.create("name", "labelId"); // getChats(labelId: string): Promise<{ status: number; data: ChatInfo[] }> await wa.label.getChats("labelId"); // addToChat(labelId: string, to: string): Promise await wa.label.addToChat("labelId", "to"); // delete(labelId: string): Promise await wa.label.delete("labelId"); // removeFromChat(labelId: string, to: string): Promise await wa.label.removeFromChat("labelId", "to"); ## wa.action // checkRegistered(number: string): Promise await wa.action.checkRegistered("number"); // downloadMedia(type: 'image' | 'video' | 'sticker' | 'audio' | 'document', message: DownloadableMessage): Promise await wa.action.downloadMedia("image", { /* DownloadableMessage */ }); // deleteStorage(): Promise await wa.action.deleteStorage(); ## wa.contact // list(): Promise await wa.contact.list(); // listByChannel(channel: Provider): Promise await wa.contact.listByChannel("whatsapp"); // profile(id: string): Promise<{ status: number; data: ContactInfo }> await wa.contact.profile("id"); // add(number: string, name: string): Promise await wa.contact.add("number", "name"); // remove(number: string): Promise await wa.contact.remove("number"); // block(number: string, action: 'block' | 'unblock'): Promise await wa.contact.block("number", "block"); // clearSession(number: string): Promise await wa.contact.clearSession("number"); // getStatus(number: string): Promise await wa.contact.getStatus("number"); // listBlocked(): Promise await wa.contact.listBlocked(); // resolveLids(lids: string[]): Promise await wa.contact.resolveLids([]); ## wa.group // list(): Promise<{ status: number; data: GroupInfo[] }> await wa.group.list(); // info(id: string): Promise<{ status: number; data: GroupInfo }> await wa.group.info("id"); // create(name: string, participants: string[]): Promise<{ status: number; data: GroupInfo }> await wa.group.create("name", []); // update(id: string, name: string, description: string): Promise await wa.group.update("id", "name", "description"); // changeSettings(id: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'): Promise await wa.group.changeSettings("id", "announcement"); // leave(id: string): Promise await wa.group.leave("id"); // getMembers(id: string): Promise<{ status: number; data: GroupParticipant[] }> await wa.group.getMembers("id"); // getInviteInfo(code: string): Promise await wa.group.getInviteInfo("code"); // getInviteCode(id: string): Promise await wa.group.getInviteCode("id"); // updatePicture(id: string, url: string): Promise await wa.group.updatePicture("id", "url"); // removePicture(id: string): Promise await wa.group.removePicture("id"); // addParticipants(id: string, participants: string[]): Promise await wa.group.addParticipants("id", []); // removeParticipants(id: string, participants: string[]): Promise await wa.group.removeParticipants("id", []); // updateParticipantRole(id: string, action: 'promote' | 'demote', participants: string[]): Promise await wa.group.updateParticipantRole("id", "promote", []); // getRequestParticipants(id: string): Promise<{ status: number; data: GroupParticipant[] }> await wa.group.getRequestParticipants("id"); // updateRequestParticipants(id: string, data: GroupParticipantsAction): Promise await wa.group.updateRequestParticipants("id", { /* GroupParticipantsAction */ }); // readiness(): Promise await wa.group.readiness(); ## wa.community // list(): Promise<{ status: number; data: CommunityInfo[] }> await wa.community.list(); // create(data: CommunityCreate): Promise<{ status: number; data: CommunityInfo }> await wa.community.create({ /* CommunityCreate */ }); // info(id: string): Promise<{ status: number; data: CommunityInfo }> await wa.community.info("id"); // update(id: string, data: CommunityUpdate): Promise await wa.community.update("id", { /* CommunityUpdate */ }); // leave(id: string): Promise await wa.community.leave("id"); // updatePicture(id: string, url: string): Promise await wa.community.updatePicture("id", "url"); // getInviteCode(id: string): Promise await wa.community.getInviteCode("id"); // removeParticipants(id: string, participants: string[]): Promise await wa.community.removeParticipants("id", []); // getRequestParticipants(id: string): Promise<{ status: number; data: GroupParticipant[] }> await wa.community.getRequestParticipants("id"); // updateRequestParticipants(id: string, data: GroupParticipantsAction): Promise await wa.community.updateRequestParticipants("id", { /* GroupParticipantsAction */ }); // acceptInvite(code: string): Promise await wa.community.acceptInvite("code"); // getInviteInfo(code: string): Promise await wa.community.getInviteInfo("code"); // createGroup(id: string, data: CommunityGroupCreate): Promise await wa.community.createGroup("id", { /* CommunityGroupCreate */ }); // ephemeral(id: string, expiration: number): Promise await wa.community.ephemeral("id", 0); // updateSettings(id: string, setting: string): Promise await wa.community.updateSettings("id", "setting"); // memberAddMode(id: string, mode: string): Promise await wa.community.memberAddMode("id", "mode"); // joinApproval(id: string, mode: string): Promise await wa.community.joinApproval("id", "mode"); ## wa.business // getCatalog(limit?: number, cursor?: string): Promise await wa.business.getCatalog(0, "cursor"); // createProduct(product: Product): Promise await wa.business.createProduct({ /* Product */ }); // updateProduct(productId: string, product: Product): Promise await wa.business.updateProduct("productId", { /* Product */ }); // deleteProduct(productId: string): Promise await wa.business.deleteProduct("productId"); // getCollections(limit?: number): Promise await wa.business.getCollections(0); // getOrder(orderId: string, token?: string): Promise await wa.business.getOrder("orderId", "token"); // getCommerceSettings(): Promise await wa.business.getCommerceSettings(); // updateCommerceSettings(settings: CommerceSettings): Promise await wa.business.updateCommerceSettings({ /* CommerceSettings */ }); ## wa.newsletter // create(name: string, description?: string): Promise await wa.newsletter.create("name", "description"); // getMetadata(type: string, id: string): Promise await wa.newsletter.getMetadata("type", "id"); // getSubscribers(id: string): Promise await wa.newsletter.getSubscribers("id"); // getAdmins(id: string): Promise await wa.newsletter.getAdmins("id"); // follow(id: string): Promise await wa.newsletter.follow("id"); // unfollow(id: string): Promise await wa.newsletter.unfollow("id"); // updateName(id: string, name: string): Promise await wa.newsletter.updateName("id", "name"); // updateDescription(id: string, description: string): Promise await wa.newsletter.updateDescription("id", "description"); // updatePicture(id: string, url: string): Promise await wa.newsletter.updatePicture("id", "url"); // removePicture(id: string): Promise await wa.newsletter.removePicture("id"); // transferOwnership(id: string, newOwnerJid: string): Promise await wa.newsletter.transferOwnership("id", "newOwnerJid"); // demoteAdmin(id: string, userJid: string): Promise await wa.newsletter.demoteAdmin("id", "userJid"); // getMessages(id: string, count?: number, since?: number, after?: number): Promise await wa.newsletter.getMessages("id", 0, 0, 0); // react(id: string, serverId: string, reaction: string): Promise await wa.newsletter.react("id", "serverId", "reaction"); // mute(id: string): Promise await wa.newsletter.mute("id"); // unmute(id: string): Promise await wa.newsletter.unmute("id"); // delete(id: string): Promise await wa.newsletter.delete("id"); ## wa.status // sendText(data: StatusTextData): Promise await wa.status.sendText({ /* StatusTextData */ }); // sendImage(data: StatusMediaData): Promise await wa.status.sendImage({ /* StatusMediaData */ }); // sendVideo(data: StatusMediaData): Promise await wa.status.sendVideo({ /* StatusMediaData */ }); // sendAudio(data: { url: string; statusJidList?: string[] }): Promise await wa.status.sendAudio({ /* data */ }); // mention(data: StatusMentionData): Promise await wa.status.mention({ /* StatusMentionData */ }); ## wa.templates // list(): Promise await wa.templates.list(); // create(data: CreateTemplateData): Promise await wa.templates.create({ /* CreateTemplateData */ }); // delete(name: string): Promise await wa.templates.delete("name"); // uploadHeaderMedia(url: string): Promise await wa.templates.uploadHeaderMedia("url"); // get(id: string): Promise await wa.templates.get("id"); // update(id: string, data: UpdateTemplateData): Promise await wa.templates.update("id", { /* UpdateTemplateData */ }); ## wa.analytics // usage(): Promise await wa.analytics.usage(); // conversations(query?: AnalyticsQuery): Promise await wa.analytics.conversations({ /* AnalyticsQuery */ }); // messages(query?: AnalyticsQuery): Promise await wa.analytics.messages({ /* AnalyticsQuery */ }); // templates(query?: AnalyticsQuery): Promise await wa.analytics.templates({ /* AnalyticsQuery */ }); // pricing(query?: AnalyticsQuery): Promise await wa.analytics.pricing({ /* AnalyticsQuery */ }); ## wa.calling // getSettings(): Promise await wa.calling.getSettings(); // updateSettings(calling: object): Promise await wa.calling.updateSettings({ /* object */ }); // controlCall(data: CallControlData): Promise await wa.calling.controlCall({ /* CallControlData */ }); ## wa.conversation // getComponents(): Promise await wa.conversation.getComponents(); // updateComponents(data: ConversationComponentsData): Promise await wa.conversation.updateComponents({ /* ConversationComponentsData */ }); ## Type Definitions ```typescript /** Provider channel a message is sent through / received from. */ export type Provider = 'whatsapp' | 'instagram' | 'messenger'; /** Outgoing webhook payload format: "native" (default), "meta" (Cloud API envelope), or "both". */ export type WebhookFormat = 'native' | 'meta' | 'both'; export interface Init { server: string; key: string; /** Default provider applied to every send unless overridden per-call. */ provider?: Provider; } export enum HttpMethod { GET = 'GET', POST = 'POST', PUT = 'PUT', DELETE = 'DELETE', PATCH = 'PATCH', } export enum Routes { INSTANCES = 'instance', MESSAGES = 'message', CONTACTS = 'contacts', GROUPS = 'groups', ACTIONS = 'actions', CALL = 'call', CHAT = 'chat', LABELS = 'labels', COMMUNITY = 'community', BUSINESS = 'business', NEWSLETTER = 'newsletter', STATUS = 'status', TEMPLATES = 'templates', ANALYTICS = 'analytics', CALLING = 'calling', CONVERSATION = 'conversation', } export enum TypeMessage { PRESENCE = 'presence', TEXT = 'text', AUDIO = 'audio', IMAGE = 'image', VIDEO = 'video', DOCUMENT = 'document', CONTACT = 'contact', LOCATION = 'location', REACTION = 'reaction', LINK = 'link', TITLE = 'title', BUTTON_REPLY = 'button_reply', BUTTON_ACTION = 'button_action', BUTTON_PIX = 'pix', POLL = 'survey', MENU = 'list', STICKER = 'sticker', VIDEO_NOTE = 'video-note', POLL_V2 = 'poll', EVENT = 'event', PIN = 'pin', CALL_LINK = 'call-link', } export enum StatusPresence { UNAVAILABLE = 'unavailable', AVAILABLE = 'available', COMPOSING = 'composing', RECORDING = 'recording', PAUSED = 'paused', } export interface ApiResponse { status: number; message: string; } export interface WebhookBody { allowWebhook: boolean; allowNumber?: string; webhookMessage: string; webhookGroup: string; webhookConnection: string; webhookQrCode: string; webhookMessageFromMe: string; webhookHistory: string; /** Set to "meta" (or "both") so incoming payloads use the envelope `parseWebhook` expects. */ webhookFormat?: WebhookFormat; } export interface Contact { fullName: string; phoneNumber: string; organization?: string; } export interface Location { latitude: number; longitude: number; address: string; } export interface Row { title: string; description: string; rowId: string; } export interface Section { title: string; rows: Row[]; } export interface InfoInstance { status: number; instance: Instance; } export interface IInstanceConfig { markMessages: boolean receiveStatusMessage: boolean receivePresence: boolean saveMedia: boolean permission: number proxy: string | null mongoDB: { uri: string | null dbName: string | null } } export interface Instance { mobile: boolean socketConnection: number user: User phoneConnected: boolean status: string webhook: Webhook config: IInstanceConfig businessProfile: BusinessProfile } export interface User { id: string name: string lid: string imageProfile: string } export interface Webhook { allowWebhook: boolean allowNumber: string webhookMessage: string webhookConnection: string webhookGroup: string webhookHistory: string webhookMessageFromMe: string webhookQrCode: string } export interface SendMessageRoot { status: number; message?: string; /** @deprecated use data instead */ data?: MessageData; } export interface MessageData { key: MessageKey; message: MessageContent; messageTimestamp: string; status: string; } export interface MessageKey { remoteJid: string; fromMe: boolean; id: string; } export interface MessageContent { extendedTextMessage?: ExtendedTextMessage; } export interface ExtendedTextMessage { text: string; } export interface Connect { status: number; phoneConnected: boolean; qrcode: string; image: string; user?: User; } export interface PairingCodeResponse { status: number; code: string; } export interface BusinessProfile { wid: string description: string address: string email: string website: any[] category: string } export interface Buttons { type: "quick_reply" | "cta_copy" | "cta_url" | "cta_call"; copy_code?: string; phone_number?: string; url?: string; id?: string; text: string; } export interface Items { id: string; name: string; price: number; quantity: number; } export interface HeaderMedia { title?: string; hasMediaAttachment?: boolean; imageMessage?: { url: string }; videoMessage?: { url: string }; documentMessage?: { url: string; mimetype?: string; fileName?: string }; } export interface DownloadableMessage { mediaKey: string; directPath: string; url: string; } export interface Product { name: string; description?: string; originCountryCode?: string; currency?: string; price?: number; images?: { url: string }[]; } export interface CommunityCreate { name: string; subject: string; } export interface CommunityUpdate { subject: string; description: string; } export interface GroupParticipantsAction { participants: string[]; action: 'reject' | 'approve'; } export interface MobileRegisterData { phoneNumberCountryCode: string; phoneNumberNationalNumber: string; phoneNumberMobileNetworkCode: string; } export interface EventData { to: string; name: string; description?: string; startTime?: string; locationName?: string; locationAddress?: string; } export interface RegisteredResponse { status: number; registered: boolean; } export interface ContactInfo { id: string; name?: string; notify?: string; imgUrl?: string; } /** * One entry of `GET /contacts` (`wa.contact.list()`). * * The address book is shared by every channel, so each entry carries the * `channel` it belongs to — WhatsApp phone numbers, Instagram IGSIDs and * Messenger PSIDs all live in `number` and look alike. Filter client-side by * `channel` when you need one channel only; the endpoint takes no query params. */ export interface ContactListItem { /** * Platform identifier: phone digits on WhatsApp, IGSID on Instagram, * PSID on Messenger. Never a JID — no `@s.whatsapp.net` suffix. */ number: string; /** Saved/display name. Empty string when the contact has no known name. */ name: string; /** Channel this contact belongs to. Legacy rows are reported as `whatsapp`. */ channel: Provider; /** Signed Meta profile-picture URL. Absent when unknown; expires over time. */ pictureUrl?: string; /** Instagram @handle. Only present on Instagram contacts. */ username?: string; } /** Response of `GET /contacts` (`wa.contact.list()`). */ export interface ListContactsResponse { status: number; /** Number of entries in `contacts`. */ total: number; contacts: ContactListItem[]; /** `Contacts fetched successfully` or `No contacts cached`. */ message?: string; } export interface GroupInfo { id: string; subject: string; owner: string; creation: number; desc?: string; participants: GroupParticipant[]; } export interface GroupParticipant { id: string; admin?: string; } export interface InviteCodeResponse { status: number; inviteCode: string; } export interface ChatInfo { id: string; name?: string; timestamp?: number; unreadCount?: number; } /** The contact behind a chat, as returned inside {@link ChatListItem}. */ export interface ChatContact { /** * Phone digits of the chat, or the address-book phone when the chat was * matched by LID. On Instagram/Messenger this holds the IGSID/PSID. */ phone: string; /** Address-book name. Empty string when the contact is not saved. */ name: string; } /** * One entry of `GET /chat` (`wa.chat.list()`) — an individual or group chat of * a single channel. */ export interface ChatListItem { /** * Storage key of the chat. A JID (`5511999999999@s.whatsapp.net`, * `...@g.us`) on the Baileys path; bare digits / IGSID / PSID on the * official Cloud API, Instagram and Messenger paths. */ chatId: string; /** Epoch milliseconds of the last message; `0` when unknown. Chats come sorted by this, newest first. */ lastMessageTimestamp: number; /** Stored message count for the chat. */ messageCount: number; /** Channel this chat belongs to. Legacy rows are reported as `whatsapp`. */ channel: Provider; /** Contact behind the chat. `name` is empty when not in the address book. */ contact: ChatContact; } /** * Response of `GET /chat` (`wa.chat.list()`). * * `chats` is normally a {@link ChatListItem} array. On the MongoDB fallback * path the server can only return the chat ids, so it may also come back as a * `string[]` — narrow with `typeof chat === 'string'` before reading fields. */ export interface ListChatsResponse { status: number; /** Channel the list was resolved for — the requested `provider`, or `whatsapp`. */ provider?: Provider; chats: ChatListItem[] | string[]; /** `Chats retrieved successfully`, `No chats found`, or the error text on 4xx/5xx. */ message?: string; } /** Pagination block returned by `GET /chat/messages`. */ export interface ChatMessagesPagination { page: number; limit: number; hasMore: boolean; } /** Response of `GET /chat/messages` (`wa.chat.messages()`). */ export interface ChatMessagesResponse { status: number; messages: MessageData[]; pagination?: ChatMessagesPagination; /** Present instead of `messages` when the request fails. */ message?: string; } export interface LabelInfo { id: string; name: string; color?: number; } export interface CommunityInfo { id: string; name: string; subject?: string; description?: string; participants?: GroupParticipant[]; } export interface CatalogResponse { status: number; data: Product[]; cursor?: string; } export interface WebhookStatistics { status: number; data: Record; } export interface ListMessagesResponse { status: number; data: MessageData[]; page?: number; limit?: number; total?: number; } export interface DownloadMediaResponse { status: number; data: string; } export interface CallResponse { status: number; data: Record; } export interface LiveLocationData { to: string; latitude: number; longitude: number; caption?: string; } export interface SendContactsData { to: string; displayName: string; contacts: Contact[]; } export interface ProductMessageData { to: string; businessOwnerJid: string; productId: string; catalogId: string; body?: string; footer?: string; } export interface GroupInviteMessageData { to: string; groupJid: string; groupName: string; inviteCode: string; inviteExpiration?: number; caption?: string; } export interface StatusTextData { text: string; statusJidList?: string[]; } export interface StatusMediaData { url: string; caption?: string; statusJidList?: string[]; } export interface StatusMentionData { jid: string; statusMsgId: string; } export interface NewsletterInfo { id: string; name?: string; description?: string; subscribers?: number; } export interface CommunityGroupCreate { subject: string; participants?: string[]; } /** Mark a message as read (POST /message/read). */ export interface MarkReadData { messageId: string; typing?: boolean; } /** Send an approved template message (POST /message/template — official only). */ export interface SendTemplateData { to: string; name: string; language?: string; components?: TemplateComponent[]; provider?: Provider; } /** A component of a WhatsApp message template (header/body/footer/buttons). */ export interface TemplateComponent { type: string; [key: string]: unknown; } /** Tax details for an order (Payments BR). */ export interface OrderTax { value?: number; description?: string; } /** A single line item of an order (Payments BR). */ export interface OrderItem { name: string; amount: number; quantity: number; saleAmount?: number; } /** Send an order with a payment link (POST /message/order-details — Payments BR). */ export interface OrderDetailsData { to: string; text: string; title: string; referenceId: string; paymentLinkUri: string; totalAmount: number; subtotal: number; tax?: OrderTax; items: OrderItem[]; } /** Update an order status (POST /message/order-status — official only, Payments BR). */ export interface OrderStatusData { to: string; referenceId: string; status: string; description?: string; } /** Request the recipient to share their location (POST /message/location-request). */ export interface LocationRequestData { to: string; text: string; } /** Send a message with ad context (POST /message/ad). */ export interface AdMessageData { to: string; text: string; url?: string; sourceId?: string; sourceUrl?: string; title?: string; body?: string; mentions?: string[]; } /** Send a product list (POST /message/product-list — official only). */ export interface ProductListData { to: string; header: string; body: string; sections: Section[]; footer?: string; catalogId: string; } /** Inject audio into an active call (POST /call/{callId}/audio). */ export interface CallAudioData { file?: string; url?: string; base64?: string; } /** Commerce settings (GET/POST /business/commerce-settings — official only). */ export interface CommerceSettings { isCartEnabled?: boolean; isCatalogVisible?: boolean; } /** Create a message template (POST /templates — official only). */ export interface CreateTemplateData { name: string; language: string; category: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION'; components: TemplateComponent[]; allow_category_change?: boolean; } /** Edit a message template (PUT /templates/{id} — official only). */ export interface UpdateTemplateData { category?: 'MARKETING' | 'UTILITY' | 'AUTHENTICATION'; components?: TemplateComponent[]; } /** Query range for analytics endpoints (official only). */ export interface AnalyticsQuery { start?: string; end?: string; granularity?: string; } /** Control a call (POST /calling/call — official only). */ export interface CallControlData { action: string; to?: string; callId?: string; sdp?: string; sdpType?: string; } /** Conversational components (POST /conversation — official only). */ export interface ConversationComponentsData { enableWelcomeMessage?: boolean; prompts?: unknown[]; commands?: unknown[]; } ``` ## Custom HTTP Client ```typescript import { Wame, IHttpClient, RequestOptions } from '@raphaelvserafim/client-api-whatsapp'; class MyHttpClient implements IHttpClient { async request(options: RequestOptions): Promise { // your custom implementation (fetch, got, etc.) } } const wa = new Wame( { server: "https://us.api-wa.me", key: "YOUR_KEY" }, new MyHttpClient() ); ``` ## Error Handling ```typescript import { WhatsAppError } from '@raphaelvserafim/client-api-whatsapp'; try { await wa.message.send(data); } catch (err) { if (err instanceof WhatsAppError) { console.error(err.message); } } ```