Send a Template WhatsApp Message

HTTP MethodURLRequires Auth

POST

Navigate to the Details tab of the App Info page to get the URL for your workspace. For example, http://localhost:3000/api/apps/public/30bf52a3-d65b-4ab1-9b11-7cfdddf1ef29/templateMessage

Body Parameters

KeyDescriptionExample Value

phoneNumbers*

Recipient WhatsApp IDs where you want to send the template message. Note that you can validate a WhatsApp id from here.

"phoneNumbers": [ "+917785887264", "+551452001478" ]

connectedWhatsAppNo*

The WhatsApp Number from which you want to send this template message.

"connectedWhatsAppNo": "+565412001234"

targetAgent

Username of the agent you want to transfer the chat to when the WhatsApp user replies.

"targetAgent": "murtaza98"

targetDepartment

Department name or ID where you want to transfer the chat to when the WhatsApp user replies.

"targetDepartment": "SalesDepartment"

template*

Provide information about the template message you wish to send. It is the same as WhatsApp-template-object.

Refer to the template property in above example.

We strongly recommend including the + prefix for all phone numbers in the payload. While you can submit numbers without the leading + sign, we have encountered cases where WhatsApp will return an invalid response despite the number being in use.

Example Body

{
    "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"
                    }
                ]
            },
        ]
    }
}

Sample Call

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"
        }
    }
}'

Responses

Success ResponseError 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 updated

Rocket.Chat versions receive support for six months after release.