Methods
get(params, verify_token) → {String}
- Source:
GET helper, must be called inside the get function of your code.
Used once at the first webhook setup.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | The GET request parameters in object format |
verify_token |
String | The verification token |
Throws:
-
-
500 if verify_token is not specified
- Type
- Number
-
-
-
400 if the request is missing data
- Type
- Number
-
-
-
403 if the verification tokens don't match
- Type
- Number
-
Returns:
The challenge string, it must be the http response body
- Type
- String
post(data, onMessage, onStatusopt) → {Number}
- Source:
POST helper, must be called inside the post function of your code.
When setting up the webhook, only subscribe to messages. Other subscritions support might be added later.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Object | The post data sent by Whatsapp, already parsed to object | |
onMessage |
onMessage | The function to be called if the post request is a valid message | |
onStatus |
onStatus |
<optional> |
The function to be called if the post request is a valid status update |
Throws:
-
400 if the POST request isn't valid
- Type
- Number
Returns:
200, it's the expected http/s response code
- Type
- Number
Type Definitions
Logger(phoneID, to, object, raw)
Callback function after a sendMessage request is sent
Parameters:
Name | Type | Description |
---|---|---|
phoneID |
String | The bot's phoneID from where the message was sent |
to |
String | The user's phone number |
object |
Text | Audio | Document | Image | Sticker | Video | Location | Contacts | Interactive | Template | The message object |
raw |
Request | The raw body sent to the server |
onMessage(phoneID, phone, message, name, raw)
- Source:
POST helper callback for messages
Parameters:
Name | Type | Description |
---|---|---|
phoneID |
String | The bot's phoneID |
phone |
String | The user's phone number |
message |
Object | The messages object |
name |
String | The username |
raw |
Object | The raw data from the API |
onStatus(phoneID, phone, status, messageID, conversation, pricing, raw)
- Source:
POST helper callback for statuses
Parameters:
Name | Type | Description |
---|---|---|
phoneID |
String | The bot's phoneID |
phone |
String | The user's phone number |
status |
String | The message status |
messageID |
String | The message ID |
conversation |
Object | The conversation object |
pricing |
Object | The pricing object |
raw |
Object | The raw data from the API |