How to send templates and messages to WhatsApp from Botmaker API?

In this article, you will learn how to send messages and templates to WhatsApp from the Botmaker API.

Estimated reading time: 10 minutes


The Botmaker API (https://go.botmaker.com/apidocs/), which you access through Menu>Botmaker API, has 2 ways to send messages to the user:

  • Triggering intents using the /intent/v2 endpoint. This endpoint allows firing intents and sending WhatsApp templates.

  • Writing messages built by the API user, through the /message/v3 endpoint.

In the API documentation, you can find the description of these endpoints and you can also call them:

01

  1. Intents API and WhatsApp templates

With the Botmaker API, you can trigger intents to your users upon the occurrence of a specific event in your business or system.

In WhatsApp, there is a window to send messages to the user, which closes 24 hours after the user’s last message. Once this window is closed, you need to use templates to contact your users. The intent endpoint is also used to send WhatsApp templates.

#### Endpoint

``**POST** https://go.botmaker.com/api/v1.0/intent/v2.

#### Example request body:

```

{

“chatPlatform”: “whatsapp”,

“chatChannelNumber”: “<bot line phone number, for example, 12185206423>”,

“platformContactId”: “<user phone number, for example, 5491151653774>”,

“ruleNameOrId”: “<Name of bot Intent>”,

“clientPayload”: “<data to be sent by webhook notification>”,

“params”: { “nameOfVariable”: “<value of the variable to be set before executing intent or template>” }

}

```

You can try it out in the API documentation: https://go.botmaker.com/apidocs/, by deploying intent>/intent/v2 and filling in the body field. Once you have entered the data, you must click on try it out.

02

The parameter 'chatChannelNumber` is the WhatsApp phone line of your bot. You can get it by going to Menu>Channels and Integrations>WhatsApp:

03

  1. Message API

This endpoint is used to send messages that are not in any intent flow; they are messages built from outside the platform, elaborated by the Botmaker API user.

You can send messages, text, images, audio, and buttons.

You can only use this endpoint if the user has the message window open, that is, within 24 hours of a user message.

#### Endpoint

**POST** https://go.botmaker.com/api/v1.0/**message/v3.**

#### Example request body:

```

{

“chatPlatform”: “whatsapp”,

“chatChannelNumber”: “12185208001”,

“platformContactId”: “5491155643774”,

“messageText”: “a message written by the customer that must be API”,

“buttons”: [

{ “label”: “continue”, “payload”: “idBusinessContinue” },

{ “label”: “help”, “payload”: “idBusinessHelp” }

]

}

```

04

###### Messages with buttons

To send messages with buttons, you have to pass an array in the buttons field **buttons**:

```

[

{ “label”: “continue”, “payload”: “id for your system 1”},

{ “label”: “help”, “payload”: “id for your system 2”}

]

```

Whatever you send in the payload field, will be sent to you in the user’s message when selecting the button through a webhook.

It is also possible to trigger intents with buttons, using the intentIdOrLabel field. Remember that you cannot pass payload and intentIdOrLabel fields at the same time.

```

[

{ “label”: “continuar”, “intentIdOrLabel”: “Name Intent 1”},

{ “label”: “ayuda”, “intentIdOrLabel”: “Name Intent 2”}

]

```

For the buttons to work, you must have the whatsAppReplyButtons and whatsAppListMessages options enabled, under settings>private.

###### Messages with audio

To send an audio message, use the audioURL field with a public audio URL.

```

{

“chatPlatform”: “whatsapp”,

“chatChannelNumber”: “12185208001”,

“platformContactId”: “5491155643774”,

“audioURL”: “http://cld3097web.audiovideoweb.com/va90web25003/companions/Foundations of Rock/13.01.mp3"

}

```

To obtain more information on this topic, you can refer to the following articles:

Remember to visit our Help Center for further information.

Written by: Botmaker Team

Updated: 03/21/2022