Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Latest commit

 

History

History
202 lines (149 loc) · 11.2 KB

API.md

File metadata and controls

202 lines (149 loc) · 11.2 KB

API Reference

List

Details

createBot(fromPhoneNumberId, accessToken, version)

Param Type Default Description
fromPhoneNumberId String Whatsapp ID of business phone number.
accessToken String Temporary or Permanent access token.

sendText(to, text, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
text String The text of the text message.
[options] Object
[options.preview_url] Boolean By default, WhatsApp recognizes URLs and makes them clickable, but you can also include a preview box with more information about the link. Set this field to true if you want to include a URL preview box.

sendMessage(to, text, [options])

Same as sendText above.

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
text String The text of the text message.
[options] Object
[options.preview_url] Boolean By default, WhatsApp recognizes URLs and makes them clickable, but you can also include a preview box with more information about the link. Set this field to true if you want to include a URL preview box.

sendImage(to, urlOrObjectId, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
urlOrObjectId String Either one of the following:
- URL Link: use only with HTTP/HTTPS URLs
- Media Object ID. See Get Media ID for information on how to get the ID of your media object.
[options] Object
[options.caption] String Describes the image.

sendDocument(to, urlOrObjectId, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
urlOrObjectId String Either one of the following:
- URL Link: use only with HTTP/HTTPS URLs
- Media Object ID. See Get Media ID for information on how to get the ID of your media object.
[options] Object
[options.caption] String Describes the document.
[options.filename] String Describes the filename for the specific document.

sendAudio(to, urlOrObjectId)

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
urlOrObjectId String Either one of the following:
- URL Link: use only with HTTP/HTTPS URLs
- Media Object ID. See Get Media ID for information on how to get the ID of your media object.

sendVideo(to, urlOrObjectId, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
urlOrObjectId String Either one of the following:
- URL Link: use only with HTTP/HTTPS URLs
- Media Object ID. See Get Media ID for information on how to get the ID of your media object.
[options] Object
[options.caption] String Describes the video.

sendSticker(to, urlOrObjectId)

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
urlOrObjectId String Either one of the following:
- URL Link: use only with HTTP/HTTPS URLs
- Media Object ID. See Get Media ID for information on how to get the ID of your media object.

sendLocation(to, latitude, longitude, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
latitude Number Latitude of the location.
longitude Number Latitude of the location.
[options] Object
[options.name] Object Name of location.
[options.address] Object Address of the location. Only displayed if name is present.

sendTemplate(to, name, languageCode, [components])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
name String Name of the template.
languageCode String The code of the language or locale to use. Accepts both language and language_locale formats (e.g., en and en_US).
[components] Array of Objects See Official Documentation.

sendContacts(to, contacts)

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
[contacts] Array of Objects See Official Documentation.

sendReplyButtons(to, bodyText, buttons, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
bodyText String The content of the message. Emojis and markdown are supported. Maximum length: 1024 characters.
buttons Object Key-value pair denoting the id and title of the button, i.e.
- Key: Unique identifier for your button. This ID is returned in the webhook when the button is clicked by the user. Maximum length: 256 characters.
- Value: Button title. It cannot be an empty string and must be unique within the message. Emojis are supported, markdown is not. Maximum length: 20 characters.
[options] Object
[options.footerText] Object The footer content. Emojis, markdown, and links are supported. Maximum length: 60 characters.
[contacts.header] Array of Objects See Official Documentation.

sendList(to, buttonName, bodyText, sections, [options])

Param Type Default Description
to String WhatsApp ID or phone number for the person you want to send a message to.
buttonName String Button content. It cannot be an empty string and must be unique within the message. Emojis are supported, markdown is not. Maximum length: 20 characters.
bodyText String The content of the message. Emojis and markdown are supported. Maximum length: 1024 characters.
sections Object Key-value pair denoting the title of the section and the rows, i.e.
- Key: Title of the section. Maximum length: 24 characters.
- Value: Contains a list of rows. You can have a total of 10 rows across your sections. Each row must have a title (Maximum length: 24 characters) and an ID (Maximum length: 200 characters). You can add a description (Maximum length: 72 characters), but it is optional. e.g.

{
"id":"unique-row-identifier-here",
"title": "row-title-content-here",
"description": "row-description-content-here",
}
[options] Object
[options.footerText] Object The footer content. Emojis, markdown, and links are supported. Maximum length: 60 characters.
[contacts.header] Array of Objects See Official Documentation.

startExpressServer([options])

Param Type Default Description
[options] Object
[options.app] express.Application Your existing express application. Not required. See README for more info.
[options.useMiddleware] function A function that accepts middleware for your server. See README for more info.
[options.port] number Port number for the express server, e.g. 3000.
[options.webhookPath] string Endpoint for handling all whatsapp-related requests. See README for more info.
[options.webhookVerifyToken] string Verification token to use in Facebook Developer app settings.See README for more info.

on(event, cb: (message) => void)

Param Type Default Description
event string text | image | document | audio | video | sticker | location | contacts | button_reply | list_reply
message object See below.

message object:

Param Type Default Description
from string Whatsapp ID/phone number of Sender.
id string ID of created message.
timestamp string Unix epoch of created message.
type string text | image | document | audio | video | sticker | location | contacts | button_reply | list_reply
data object Varies depending on the event. e.g for text, it will be { text: string; }

Resources