Links

Template Whatsapp message

Send a template message
URL
Method
Input Data Format
REST API URL can be found on Apps Page Sample Url for eg: http://localhost:3000/api/apps/public/30bf52a3-d65b-4ab1-9b11-7cfdddf1ef29/templateMessage
POST
JSON

Request structure

{
"phoneNumbers": [
"+917785887264", "+551452001478"
],
"connectedWhatsAppNo": "+565412001234",
"targetAgent": "murtaza98",
"targetDepartment": "SalesDepartment",
"template": {
"namespace": "your-namespace",
"name": "your-template-name",
"language": {
"code": "your-language-and-locale-code",
"policy": "deterministic"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "your-text-string"
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "your-text-string"
},
{
"type": "text",
"text": "your-text-string"
}
]
},
{
"type": "footer",
"parameters": [
{
"type": "text",
"text": "your-text-string"
}
]
},
]
}
}

Parameters

Param Name
Param Type
Description
Dependency
Example
phoneNumbers
Array of String
Recipient WhatsApp Id(s) where you want to send the template message. Note you can validate a WhatsApp id from here
Required
"phoneNumbers": [ "+917785887264", "+551452001478" ]
connectedWhatsAppNo
String
The WhatsApp Number from which you want to send this template message
Required
"connectedWhatsAppNo": "+565412001234"
targetAgent
String
Username of the targetAgent you wish to transfer the chat to when the WhatsApp user replies back
Optional
"targetAgent": "murtaza98"
targetDepartment
String
Department Name or Id where you wish to transfer the chat to when the WhatsApp user replies back
Optional
"targetDepartment": "SalesDepartment"
template
Provide information about the template message you wish to send
Required
Please refer to the template property in above examp
We strongly recommend including the '+' prefix for the all PhoneNumbers in the payload. While you can submit numbers without the leading '+' we have encountered cases where WhatsApp will return 'invalid' despite the number being in use.

Sample Call

Curl
curl --location --request POST 'http://localhost:3000/api/apps/public/085b7345-53e7-498c-adcb-d909e11f8100/templateMessage' \
--header 'Content-Type: application/json' \
--data-raw '{
"phoneNumbers": [
"+917738772967"
],
"connectedWhatsAppNo": "+565412001234",
"targetAgent": "murtaza98",
"targetDepartment": "SalesDepartment",
"template": {
"namespace": "aa498c38_6c0c_448d_a652_38f5d33b8c7f",
"name": "sales_welcome_template",
"language": {
"code": "en",
"policy": "deterministic"
}
}
}'
HTTP
POST /api/apps/public/085b7345-53e7-498c-adcb-d909e11f8100/templateMessage HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Content-Length: 312
{
"phoneNumbers": [
"+917738772967"
],
"connectedWhatsAppNo": "+565412001234",
"targetAgent": "murtaza98",
"targetDepartment": "SalesDepartment",
"template": {
"namespace": "aa498c38_6c0c_448d_a652_38f5d33b8c7f",
"name": "sales_welcome_template",
"language": {
"code": "en",
"policy": "deterministic"
}
}
}

Response

Success Response
Error Response
Code: 200 Content: { success: true }
Code: 400 BAD REQUEST Content: { "success": false, error: "Too many phone numbers! Please make sure that phoneNumbers are <= 250" }
Code: 200 Content: { "success": true, "invalidContacts": [ "917738772967" ] }
Code: 400 BAD REQUEST Content: { "success": false, error: "No Agent found with username abc98" }
Code: 400 BAD REQUEST Content: { "success": false, error: "No Department found with id/Name SalesDepartment" }
Code: 400 BAD REQUEST Content: { "success": false, error: "Error! Missing "connectedWhatsAppNo" field within the request" }
Code: 400 BAD REQUEST Content: { "success": false, error: "Connected WhatsApp Number (connectedWhatsAppNo) i.e. 565412001234 is not a valid WhatsApp contact. Contact Status is invalid" }
Code: 400 BAD REQUEST Content: { "success": false, error: "Error! Connected WhatsApp Number (connectedWhatsAppNo) i.e. 565412001234 has not been registered yet on Rocket.Chat. Please goto #omnichannel-whatsapp-setup channel and connect this WhatsApp number first there before sending this request again." }
Code: 500 Internal Server Error Content: { "success": false, error : "Error occurred while processing request. Details: [Error Details]" }

****

Last modified 3mo ago
Deprecation for cloud services and apps is now extended to November 20, 2023. Rocket.Chat versions receive support for six months after release.