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

Latest commit

 

History

History
100 lines (88 loc) · 7.4 KB

send-a-template-whatsapp-message.md

File metadata and controls

100 lines (88 loc) · 7.4 KB

Send a WhatsApp Template Message

Send template messages via WhatsApp to targeted contacts directly from your workspace using this endpoint. It supports only WhatsApp Cloud App and WhatsApp Sandbox App.

{% hint style="info" %} In WhatsApp sandbox, there are only three pre-defined message templates available for use. It's not possible to create new templates or modify the existing ones. Refer to the the official documentation for more details. {% endhint %}

HTTP MethodURLRequires Auth
POSTNavigate to the Details tab of the App Info page to get the template message URL for the WhatsApp app in your workspace.
For example,
http://{rocketchat-workspace}/api/apps/private/{application-id}/templateMessage
no

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"
targetAgentUsername of the agent you want to transfer the chat to when the WhatsApp user replies."targetAgent": "murtaza98"
targetDepartmentDepartment 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 example in #sending-whatsapp-template-messages-from-your-workspace

{% hint style="info" %} 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. {% endhint %}

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

{% code overflow="wrap" %}

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

{% endcode %}

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