WhatsApp Template Message
Send WhatsApp template messages with Messente's Omnichannel API.
Introduction
WhatsApp template message use pre-approved message templates, that can be used to initiate conversations with users. The templates can be created through our template management API or using Meta's WhatsApp Business Account dashboard, and in both cases, they must be approved by Meta before they can be used.
The templates can include text, images, buttons, header/footer, and other interactive elements. They are designed to be re-usable and can be sent to users without prior interaction, as long as the template has been approved by Meta. Template messages are typically used for sending notifications, alerts, or other generic business-related messages. For more interactive flows, you can use service messages in order to be able to reply to users without pre-approved templates.
Template messages are the only way to initiate a conversation with a user. Once the recipient responds to your template message, a 24-hour window is started. Within this window, you can send any type of message to the user without needing to use a template. The type of messages, that don't require templates are called service messages. This can be especially useful for interactive flows, and back-and-forth conversation with your customers. After the 24-hour window expires, you are again required to use a template message to initiate a new conversation.
The 24-hour service window is extended by any user-initiated message. This means that if the user replies to your template message, the service window is extended for another 24 hours. You can continue sending service messages within this window without needing to use a template.
Template Categories
There are 3 categories of template messages you can send:
- marketing - these are used for sending promotional content, such as offers, discounts, or other marketing-related messages.
- utility - these are used for sending important information, such as account updates, transaction notifications, order status, or other business-related messages with the aim to improve your customers' experience.
- authentication - these are used for sending one-time passwords (OTPs), verification codes, or other authentication-related messages.
Different categories have different rules, restrictions and set of usable components, so it's important to choose the right category for your purpose. For example, only authentication messages can include OTPs, but can't include media content, while marketing and utility messages can include images, videos and documents.
Template Structure
Message templates consist of a name, category, language, and components. The name is a unique identifier for the template, and the category defines the type of message it is. The language must be specified and reflects the language, in which the template is written. The components are the actual content of the message, which can include text, images, buttons and more.
When creating a template, you can specify the components that you want to include in the message. Each component has its own set of properties, such as text, media URL, or button actions.
There are many types of components and they can contain parameters, which are placeholders for dynamic content. When sending a template message, you can use these parameters to replace the placeholders with actual values, allowing you to customize the message for each recipient. For example, you can use parameters to include the recipient's name, order number, or other relevant information. For more information about the components and their properties, you can refer to Meta's template component documentation. Our template messages are structured in a way, that allows you to include the components and parameters you need for a template.
Template Message Examples
The WhatsApp ecosystem is quite complex, and there are many different types of template messages you can send. To help you get started, we have provided some examples for the most common types, using our public libraries as well as raw HTTP requests (cURL). You can use these examples as a starting point for your own template messages, and customize them to fit your needs.
Hello world
After you've set up your WhatsApp Business Account and connected it to Messente, you can send a simple "Hello world" message to test the integration. It is a very basic template message, and it's already pre-approved by Meta, so you can use it right away. The template is called "hello_world".
- Python
- Node
- PHP
- Java
- Ruby
- .NET
- cURL
# pip install messente-api
from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
WhatsApp,
WhatsAppTemplate,
WhatsAppLanguage,
OmnimessageMessagesInner,
)
from messente_api.rest import ApiException
configuration = Configuration()
configuration.username = "YOUR_MESSENTE_API_USERNAME"
configuration.password = "YOUR_MESSENTE_API_PASSWORD"
api_instance = OmnimessageApi(ApiClient(configuration))
wa_template = WhatsAppTemplate(
name="hello_world",
language=WhatsAppLanguage(code="en_US"),
)
whatsapp = WhatsApp(sender="<sender name>", template=wa_template)
whatsapp_inner = OmnimessageMessagesInner(whatsapp)
omnimessage = Omnimessage(messages=[whatsapp_inner], to="<recipient_phone_number>")
try:
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception when sending an omnimessage: %s\n" % exception)
// npm i messente_api
const MessenteApi = require("messente_api");
const defaultClient = MessenteApi.ApiClient.instance;
const basicAuth = defaultClient.authentications["basicAuth"];
basicAuth.username = "YOUR_MESSENTE_API_USERNAME";
basicAuth.password = "YOUR_MESSENTE_API_PASSWORD";
const api = new MessenteApi.OmnimessageApi();
const whatsAppTemplate = MessenteApi.WhatsAppTemplate.constructFromObject({
name: "hello_world",
language: MessenteApi.WhatsAppLanguage.constructFromObject({
code: "en_US",
}),
});
const whatsapp = MessenteApi.WhatsApp.constructFromObject({
sender: "<sender name>",
template: whatsAppTemplate,
});
const omnimessage = MessenteApi.Omnimessage.constructFromObject({
messages: [whatsapp],
to: "<recipient_phone_number>",
});
api.sendOmnimessage(omnimessage, (error, data) => {
if (error) {
console.error(error);
} else {
console.log("API called successfully. Returned data: ", data);
}
});
// composer require messente/messente-api-php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Messente\Api\Api\OmnimessageApi;
use Messente\Api\Model\Omnimessage;
use Messente\Api\Configuration;
use Messente\Api\Model\WhatsApp;
use Messente\Api\Model\WhatsAppParameter;
use Messente\Api\Model\WhatsAppComponent;
use Messente\Api\Model\WhatsAppLanguage;
use Messente\Api\Model\WhatsAppTemplate;
$config = Configuration::getDefaultConfiguration()
->setUsername('YOUR_MESSENTE_API_USERNAME')
->setPassword('YOUR_MESSENTE_API_PASSWORD');
$apiInstance = new OmnimessageApi(
new GuzzleHttp\Client(),
$config
);
$omnimessage = new Omnimessage([
'to' => '<recipient_phone_number>',
]);
$whatsAppLanguage = new WhatsAppLanguage(['code' => 'en_US']);
$whatsAppTemplate = new WhatsAppTemplate(
[
'name' => 'hello_world',
'language' => $whatsAppLanguage,
]
);
$whatsapp = new WhatsApp(
[
'sender' => '<sender name>',
'template' => $whatsAppTemplate,
]
);
$omnimessage->setMessages([$whatsapp]);
try {
$result = $apiInstance->sendOmnimessage($omnimessage);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling sendOmnimessage: ', $e->getMessage(), PHP_EOL;
}
package org.example;
import com.messente.ApiClient;
import com.messente.ApiException;
import com.messente.api.*;
import com.messente.auth.HttpBasicAuth;
import java.util.List;
// repositories { mavenCentral() }
// dependencies { implementation 'com.messente.api:messente-api' }
public class HelloWorldTemplate {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient();
OmnimessageApi apiInstance = new OmnimessageApi(apiClient);
HttpBasicAuth basicAuth = (HttpBasicAuth) apiClient.getAuthentication("basicAuth");
basicAuth.setUsername("YOUR_MESSENTE_API_USERNAME");
basicAuth.setPassword("YOUR_MESSENTE_API_PASSWORD");
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate();
whatsAppTemplate.name("hello_world");
whatsAppTemplate.language(new WhatsAppLanguage().code("en_US"));
WhatsApp whatsApp = new WhatsApp();
whatsApp.sender("<sender name>");
whatsApp.template(whatsAppTemplate);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsApp);
whatsAppOmnimessageInner.setActualInstance(whatsApp);
Omnimessage omnimessage = new Omnimessage();
omnimessage.setMessages(List.of(whatsAppOmnimessageInner));
omnimessage.setTo("<recipient_phone_number>");
try {
OmniMessageCreateSuccessResponse result = apiInstance.sendOmnimessage(omnimessage);
System.out.println(result);
} catch (ApiException e) {
System.err.println(e.getResponseBody());
}
}
}
# gem install messente_api
require 'messente_api'
MessenteApi.configure do |config|
config.username = 'YOUR_MESSENTE_API_USERNAME'
config.password = 'YOUR_MESSENTE_API_PASSWORD'
end
api_instance = MessenteApi::OmnimessageApi.new
omnimessage = MessenteApi::Omnimessage.new
omnimessage.to = '<recipient_phone_number>'
wa_lang = MessenteApi::WhatsAppLanguage.new(code: 'en_US')
wa_template = MessenteApi::WhatsAppTemplate.new(name: 'hello_world', language: wa_lang)
omnimessage.messages = [
MessenteApi::WhatsApp.new(
sender: '<sender name>',
template: wa_template,
)
]
begin
result = api_instance.send_omnimessage(omnimessage)
puts result
rescue MessenteApi::ApiError => e
puts "Exception when calling send_omnimessage: #{e}"
puts e.response_body
end
// PM > Install-Package com.Messente.Api
using System;
using com.Messente.Api.Api;
using com.Messente.Api.Client;
using com.Messente.Api.Model;
namespace Example
{
public class HelloWorldTemplate
{
public static void Main()
{
Configuration conf = new Configuration
{
Username = "YOUR_MESSENTE_API_USERNAME",
Password = "YOUR_MESSENTE_API_PASSWORD"
};
var apiInstance = new OmnimessageApi(conf);
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate(
name: "hello_world",
language: new WhatsAppLanguage(code: "en_US")
);
var whatsapp = new WhatsApp(
sender: "<SENDER_NAME>",
template: whatsAppTemplate
);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsapp)
{
ActualInstance = whatsapp
};
var omnimessage = new Omnimessage(
to: "<RECIPIENT_PHONE_NUMBER>",
messages: new List<OmnimessageMessagesInner> { whatsAppOmnimessageInner }
);
try
{
var result = apiInstance.SendOmnimessage(omnimessage);
Console.WriteLine(result.ToJson());
}
catch (Exception e)
{
Console.WriteLine("Exception when calling SendOmnimessage: " + e.Message);
}
}
}
}
curl -X POST \
'https://api.messente.com/v1/omnimessage' \
-u MESSENTE_API_USERNAME:MESSENTE_API_PASSWORD \
-H 'Content-Type: application/json' \
-d '{
"to": "<RECIPIENT_PHONE_NUMBER>",
"messages": [
{
"channel": "whatsapp",
"sender": "<SENDER NAME>",
"template": {
"name": "hello_world",
"language": {
"code": "en_US"
}
}
}
]
}'
Media-based template with coupon code
This example shows how to send a template message with an image and a coupon code. The template consists of 5 components:
- a header with an image,
- a body with text and a parameter for the coupon code,
- a footer with text,
- 2 buttons that open a link and allow the user to copy the coupon code quickly.
The media is included in the header component and can be one of:
- image
- document
- video
- location
- Python
- Node
- PHP
- Java
- Ruby
- .NET
- cURL
# pip install messente-api
from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
OmnimessageMessagesInner,
WhatsApp,
WhatsAppTemplate,
WhatsAppLanguage,
WhatsAppParameter,
WhatsAppComponent,
)
from messente_api.rest import ApiException
configuration = Configuration()
configuration.username = "YOUR_MESSENTE_API_USERNAME"
configuration.password = "YOUR_MESSENTE_API_PASSWORD"
api_instance = OmnimessageApi(ApiClient(configuration))
header_component = WhatsAppComponent(
type="header",
parameters=[
WhatsAppParameter(
type="image",
image={"link": "<MEDIA_URL>"} # URL link to the header image or other media resource
)
]
)
body_component = WhatsAppComponent(
type="body",
parameters=[
WhatsAppParameter(
type="text",
text="<COUPON_CODE>" # The coupon code to be displayed
)
]
)
footer_component = WhatsAppComponent(
type="footer",
parameters=[
WhatsAppParameter(
type="text",
text="<FOOTER_TEXT>"
)
]
)
button_component = WhatsAppComponent(
type="button",
sub_type="copy_code",
index=1,
parameters=[
WhatsAppParameter(
type="coupon_code",
coupon_code="<COUPON_CODE>" # The coupon code to be copied when the button is clicked
)
]
)
whatsapp_template = WhatsAppTemplate(
name="<TEMPLATE_NAME>",
language=WhatsAppLanguage(code="<LANGUAGE_CODE>"),
components=[header_component, body_component, footer_component, button_component]
)
whatsapp_message = WhatsApp(
channel="whatsapp",
sender="<SENDER_NAME>",
template=whatsapp_template
)
whatsapp_inner = OmnimessageMessagesInner(whatsapp_message)
omnimessage = Omnimessage(
to="<RECIPIENT_PHONE_NUMBER>",
messages=[whatsapp_inner]
)
try:
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception when sending an omnimessage: %s\n" % exception)
// npm i messente_api
const MessenteApi = require("messente_api");
const defaultClient = MessenteApi.ApiClient.instance;
const basicAuth = defaultClient.authentications["basicAuth"];
basicAuth.username = "YOUR_MESSENTE_API_USERNAME";
basicAuth.password = "YOUR_MESSENTE_API_PASSWORD";
const api = new MessenteApi.OmnimessageApi();
const headerComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "header",
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "image",
image: {
link: "<HEADER_MEDIA_URL>", // URL of the header image or other media resource
},
}),
],
});
const bodyComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "body",
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "text",
text: "<COUPON_CODE>", // The coupon code to be displayed
}),
],
});
const footerComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "footer",
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "text",
text: "<FOOTER_TEXT>",
}),
],
});
const buttonComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "button",
sub_type: "copy_code",
index: 1,
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "coupon_code",
coupon_code: "<COUPON_CODE>", // The coupon code to be copied when the button is clicked
}),
],
});
const whatsAppTemplate = MessenteApi.WhatsAppTemplate.constructFromObject({
name: "test_default_marketing",
language: MessenteApi.WhatsAppLanguage.constructFromObject({
code: "<LANGUAGE_CODE>",
}),
components: [headerComponent, bodyComponent, footerComponent, buttonComponent],
});
const whatsapp = MessenteApi.WhatsApp.constructFromObject({
channel: "whatsapp",
sender: "<SENDER_NAME>",
template: whatsAppTemplate,
});
const omnimessage = MessenteApi.Omnimessage.constructFromObject({
messages: [whatsapp],
to: "<RECIPIENT_PHONE_NUMBER>",
});
api.sendOmnimessage(omnimessage, (error, data) => {
if (error) {
console.error(error);
} else {
console.log("API called successfully. Returned data: ", data);
}
});
// composer require messente/messente-api-php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Messente\Api\Api\OmnimessageApi;
use Messente\Api\Model\Omnimessage;
use Messente\Api\Configuration;
use Messente\Api\Model\WhatsApp;
use Messente\Api\Model\WhatsAppParameter;
use Messente\Api\Model\WhatsAppComponent;
use Messente\Api\Model\WhatsAppLanguage;
use Messente\Api\Model\WhatsAppTemplate;
$config = Configuration::getDefaultConfiguration()
->setUsername('YOUR_MESSENTE_API_USERNAME')
->setPassword('YOUR_MESSENTE_API_PASSWORD');
$apiInstance = new OmnimessageApi(
new GuzzleHttp\Client(),
$config
);
$headerComponent = new WhatsAppComponent([
'type' => 'header',
'parameters' => [
new WhatsAppParameter([
'type' => 'image',
'image' => ['link' => '<MEDIA_URL>'] // URL link to the header image or other media resource
])
]
]);
$bodyComponent = new WhatsAppComponent([
'type' => 'body',
'parameters' => [
new WhatsAppParameter([
'type' => 'text',
'text' => '<COUPON_CODE>' // The coupon code to be displayed
])
]
]);
$footerComponent = new WhatsAppComponent([
'type' => 'footer',
'parameters' => [
new WhatsAppParameter([
'type' => 'text',
'text' => '<FOOTER_TEXT>'
])
]
]);
$buttonComponent = new WhatsAppComponent([
'type' => 'button',
'subType' => 'copy_code',
'index' => 1,
'parameters' => [
new WhatsAppParameter([
'type' => 'coupon_code',
'couponCode' => '<COUPON_CODE>' // The coupon code to be copied when the button is clicked
])
]
]);
$whatsAppTemplate = new WhatsAppTemplate([
'name' => '<TEMPLATE_NAME>',
'language' => new WhatsAppLanguage(['code' => '<LANGUAGE_CODE>']),
'components' => [$headerComponent, $bodyComponent, $footerComponent, $buttonComponent]
]);
$whatsappMessage = new WhatsApp([
'channel' => 'whatsapp',
'sender' => '<SENDER_NAME>',
'template' => $whatsAppTemplate
]);
$omnimessage = new Omnimessage([
'to' => '<RECIPIENT_PHONE_NUMBER>',
'messages' => [$whatsappMessage]
]);
try {
$result = $apiInstance->sendOmnimessage($omnimessage);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling sendOmnimessage: ', $e->getMessage(), PHP_EOL;
}
package org.example;
import com.messente.ApiClient;
import com.messente.ApiException;
import com.messente.api.*;
import com.messente.auth.HttpBasicAuth;
import java.util.List;
// repositories { mavenCentral() }
// dependencies { implementation 'com.messente.api:messente-api' }
public class MediaAndCouponCodeExample {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient();
OmnimessageApi apiInstance = new OmnimessageApi(apiClient);
HttpBasicAuth basicAuth = (HttpBasicAuth) apiClient.getAuthentication("basicAuth");
basicAuth.setUsername("YOUR_MESSENTE_API_USERNAME");
basicAuth.setPassword("YOUR_MESSENTE_API_PASSWORD");
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate();
whatsAppTemplate.name("<YOUR_TEMPLATE_NAME>");
whatsAppTemplate.language(new WhatsAppLanguage().code("<LANGUAGE_CODE>"));
WhatsAppMedia headerImage = new WhatsAppMedia().link("<HEADER_MEDIA_URL>"); // URL link to the header image or other media resource
WhatsAppComponent headerComponent = new WhatsAppComponent();
headerComponent.type("header");
headerComponent.setParameters(
List.of(new WhatsAppParameter().type("image").image(headerImage))
);
String couponCode = "<PROMO_CODE>"; // The coupon code to be displayed/copied
WhatsAppComponent bodyComponent = new WhatsAppComponent();
bodyComponent.type("body");
bodyComponent.setParameters(
List.of(new WhatsAppParameter().type("text").text(couponCode))
);
WhatsAppComponent footerComponent = new WhatsAppComponent();
footerComponent.type("footer");
footerComponent.setParameters(
List.of(new WhatsAppParameter().type("text").text("Visit our website for more information!"))
);
// 0th button doesn't require any parameters, so you MUST skip it entirely
WhatsAppComponent buttonComponent = new WhatsAppComponent();
buttonComponent.type("button").subType("copy_code").index(1); // index is used to determine, which button you're referring to
buttonComponent.setParameters(
List.of(new WhatsAppParameter().type("coupon_code").couponCode(couponCode))
);
whatsAppTemplate.setComponents(
List.of(
headerComponent,
bodyComponent,
footerComponent,
buttonComponent
)
);
WhatsApp whatsApp = new WhatsApp();
whatsApp.sender("<SENDER_NAME>");
whatsApp.template(whatsAppTemplate);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsApp);
whatsAppOmnimessageInner.setActualInstance(whatsApp);
Omnimessage omnimessage = new Omnimessage();
omnimessage.setMessages(List.of(whatsAppOmnimessageInner));
omnimessage.setTo("<RECIPIENT_PHONE_NUMBER>");
try {
OmniMessageCreateSuccessResponse result = apiInstance.sendOmnimessage(omnimessage);
System.out.println(result);
} catch (ApiException e) {
System.err.println(e.getResponseBody());
}
}
}
# gem install messente_api
require 'messente_api'
MessenteApi.configure do |config|
config.username = 'YOUR_MESSENTE_API_USERNAME'
config.password = 'YOUR_MESSENTE_API_PASSWORD'
end
api_instance = MessenteApi::OmnimessageApi.new
header_component = MessenteApi::WhatsAppComponent.new(
type: 'header',
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'image',
image: { link: '<HEADER_MEDIA_URL>' } # URL of the header image or other media resource
)
]
)
body_component = MessenteApi::WhatsAppComponent.new(
type: 'body',
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'text',
text: '<COUPON_CODE>' # The coupon code to be displayed
)
]
)
footer_component = MessenteApi::WhatsAppComponent.new(
type: 'footer',
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'text',
text: '<FOOTER_TEXT>'
)
]
)
button_component = MessenteApi::WhatsAppComponent.new(
type: 'button',
sub_type: 'copy_code',
index: 1,
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'coupon_code',
coupon_code: '<COUPON_CODE>' # The coupon code to be copied when the button is clicked
)
]
)
whatsapp_template = MessenteApi::WhatsAppTemplate.new(
name: '<TEMPLATE_NAME>',
language: MessenteApi::WhatsAppLanguage.new(code: '<LANGUAGE_CODE>'),
components: [header_component, body_component, footer_component, button_component]
)
whatsapp_message = MessenteApi::WhatsApp.new(
channel: 'whatsapp',
sender: '<SENDER_NAME>',
template: whatsapp_template
)
omnimessage = MessenteApi::Omnimessage.new(
to: '<RECIPIENT_PHONE_NUMBER>',
messages: [whatsapp_message]
)
begin
result = api_instance.send_omnimessage(omnimessage)
puts result
rescue MessenteApi::ApiError => e
puts "Exception when calling send_omnimessage: #{e}"
puts e.response_body
end
// PM > Install-Package com.Messente.Api
using System;
using com.Messente.Api.Api;
using com.Messente.Api.Client;
using com.Messente.Api.Model;
namespace WhatsAppMediaAndCouponCodeExample
{
public class WhatsAppMediaAndCouponCodeExample
{
public static void Main()
{
Configuration conf = new Configuration
{
Username = "YOUR_MESSENTE_API_USERNAME",
Password = "YOUR_MESSENTE_API_PASSWORD",
};
var apiInstance = new OmnimessageApi(conf);
WhatsAppParameter headerParameter = new WhatsAppParameter(
type: "image",
image: new WhatsAppMedia(link: "<HEADER_MEDIA_URL>") // URL of the header image or other media resource
);
WhatsAppComponent headerComponent = new WhatsAppComponent(
type: "header",
parameters: new List<WhatsAppParameter> { headerParameter }
);
string couponCode = "<COUPON_CODE>"; // The coupon code to be displayed/copied
WhatsAppParameter bodyParameter = new WhatsAppParameter(
type: "text",
text: couponCode
);
WhatsAppComponent bodyComponent = new WhatsAppComponent(
type: "body",
parameters: new List<WhatsAppParameter> { bodyParameter }
);
WhatsAppComponent footerComponent = new WhatsAppComponent(
type: "footer",
parameters: new List<WhatsAppParameter> { new WhatsAppParameter(type: "text", text: "<FOOTER_TEXT>") }
);
WhatsAppComponent couponButtonComponent = new WhatsAppComponent(
type: "button",
subType: "copy_code",
index: 1,
parameters: new List<WhatsAppParameter> { new WhatsAppParameter(type: "coupon_code", couponCode: couponCode) }
);
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate(
name: "<YOUR_TEMPLATE>",
language: new WhatsAppLanguage(code: "<LANGUAGE_CODE>"),
components: new List<WhatsAppComponent> { headerComponent, bodyComponent, footerComponent, couponButtonComponent }
);
var whatsapp = new WhatsApp(
sender: "<SENDER_NAME>",
template: whatsAppTemplate
);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsapp)
{
ActualInstance = whatsapp
};
var omnimessage = new Omnimessage(
to: "<RECIPIENT_PHONE_NUMBER>",
messages: new List<OmnimessageMessagesInner> { whatsAppOmnimessageInner }
);
try
{
var result = apiInstance.SendOmnimessage(omnimessage);
Console.WriteLine(result.ToJson());
}
catch (Exception e)
{
Console.WriteLine("Exception when calling SendOmnimessage: " + e.Message);
}
}
}
}
curl -X POST \
'https://api.messente.com/v1/omnimessage' \
-u MESSENTE_API_USERNAME:MESSENTE_API_PASSWORD \
-H 'Content-Type: application/json' \
-d '{
"to": "<RECIPIENT_PHONE_NUMBER>",
"messages": [
{
"channel": "whatsapp",
"sender": "<SENDER_NAME>",
"template": {
"name": "<TEMPLATE_NAME>",
"language": {
"code": "<LANGUAGE_CODE>"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "image",
"image": {
"link": "<HEADER_MEDIA_URL>"
}
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "<COUPON_CODE>"
}
]
},
{
"type": "footer",
"parameters": [
{
"type": "text",
"text": "visit our website for more discounts!"
}
]
},
{
"type": "button",
"sub_type": "copy_code",
"index": 1,
"parameters": [
{
"type": "coupon_code",
"coupon_code": "<COUPON_CODE>"
}
]
}
]
}
}
]
}'
Resulting Message
Text-based template with Quick Reply buttons
This example shows how to send a template message with a text-based header and 2 quick reply buttons for user responses. The template consists of 4 components:
- a header with text (this can be skipped in the request, since there are no parameters),
- a body with text and a parameter for the user's name,
- 2 buttons that allow the user to quickly respond to the message using pre-defined replies. The buttons in this case are yes and no replies. You can specify a PAYLOAD for each button, which is additional data that will be sent back to you when the user clicks the button. This can be useful for tracking user responses or triggering specific actions in your application. If you don't need the payload, you can skip adding the button components altogether, as long as they are present in the template approved by Meta.
- Python
- Node
- PHP
- Java
- Ruby
- .NET
- cURL
# pip install messente-api
from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
OmnimessageMessagesInner,
WhatsApp,
WhatsAppTemplate,
WhatsAppLanguage,
WhatsAppParameter,
WhatsAppComponent,
)
from messente_api.rest import ApiException
configuration = Configuration()
configuration.username = "YOUR_MESSENTE_API_USERNAME"
configuration.password = "YOUR_MESSENTE_API_PASSWORD"
api_instance = OmnimessageApi(ApiClient(configuration))
body_component = WhatsAppComponent(
type="body",
parameters=[
WhatsAppParameter(
type="text",
text="<PARAMETER_TEXT (e.g. a name or ID)>"
)
]
)
yes_button_component = WhatsAppComponent(
type="button",
sub_type="quick_reply",
index=0,
parameters=[
WhatsAppParameter(
type="payload",
payload="<PAYLOAD>"
)
]
)
no_button_component = WhatsAppComponent(
type="button",
sub_type="quick_reply",
index=1,
parameters=[
WhatsAppParameter(
type="payload",
payload="<PAYLOAD>"
)
]
)
whatsapp_template = WhatsAppTemplate(
name="<YOUR_TEMPLATE_NAME>",
language=WhatsAppLanguage(code="<LANGUAGE_CODE>"),
components=[body_component, yes_button_component, no_button_component]
)
whatsapp_message = WhatsApp(
channel="whatsapp",
sender="<SENDER_NAME>",
template=whatsapp_template
)
whatsapp_inner = OmnimessageMessagesInner(whatsapp_message)
omnimessage = Omnimessage(
to="<RECIPIENT_PHONE_NUMBER>",
messages=[whatsapp_inner]
)
try:
response = api_instance.send_omnimessage(omnimessage)
print(
"Successfully sent Omnimessage with id: %s that consists of the following messages:"
% response.omnimessage_id
)
for message in response.messages:
pprint(message)
except ApiException as exception:
print("Exception when sending an omnimessage: %s\n" % exception)
// npm i messente_api
const MessenteApi = require("messente_api");
const defaultClient = MessenteApi.ApiClient.instance;
const basicAuth = defaultClient.authentications["basicAuth"];
basicAuth.username = "YOUR_MESSENTE_API_USERNAME";
basicAuth.password = "YOUR_MESSENTE_API_PASSWORD";
const api = new MessenteApi.OmnimessageApi();
const bodyComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "body",
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "text",
text: "<PARAMETER_TEXT (e.g. a name or ID)>",
}),
],
});
const yesButtonComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "button",
sub_type: "quick_reply",
index: 0,
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "payload",
payload: "<PAYLOAD>",
}),
],
});
const noButtonComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "button",
sub_type: "quick_reply",
index: 1,
parameters: [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "payload",
payload: "<PAYLOAD>",
}),
],
});
const whatsAppTemplate = MessenteApi.WhatsAppTemplate.constructFromObject({
name: "<TEMPLATE_NAME>",
language: MessenteApi.WhatsAppLanguage.constructFromObject({
code: "<LANGUAGE_CODE>",
}),
components: [bodyComponent, yesButtonComponent, noButtonComponent],
});
const whatsapp = MessenteApi.WhatsApp.constructFromObject({
channel: "whatsapp",
sender: "<SENDER_NAME>",
template: whatsAppTemplate,
});
const omnimessage = MessenteApi.Omnimessage.constructFromObject({
messages: [whatsapp],
to: "<RECIPIENT_PHONE_NUMBER>",
});
api.sendOmnimessage(omnimessage, (error, data) => {
if (error) {
console.error(error);
} else {
console.log("API called successfully. Returned data: ", data);
}
});
// composer require messente/messente-api-php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Messente\Api\Api\OmnimessageApi;
use Messente\Api\Model\Omnimessage;
use Messente\Api\Configuration;
use Messente\Api\Model\WhatsApp;
use Messente\Api\Model\WhatsAppParameter;
use Messente\Api\Model\WhatsAppComponent;
use Messente\Api\Model\WhatsAppLanguage;
use Messente\Api\Model\WhatsAppTemplate;
$config = Configuration::getDefaultConfiguration()
->setUsername('YOUR_MESSENTE_API_USERNAME')
->setPassword('YOUR_MESSENTE_API_PASSWORD');
$apiInstance = new OmnimessageApi(
new GuzzleHttp\Client(),
$config
);
$bodyComponent = new WhatsAppComponent([
'type' => 'body',
'parameters' => [
new WhatsAppParameter([
'type' => 'text',
'text' => '<PARAMETER_TEXT (e.g. a name or ID)>'
])
]
]);
$yesButtonComponent = new WhatsAppComponent([
'type' => 'button',
'subType' => 'quick_reply',
'index' => 0,
'parameters' => [
new WhatsAppParameter([
'type' => 'payload',
'payload' => '<PAYLOAD>'
])
]
]);
$noButtonComponent = new WhatsAppComponent([
'type' => 'button',
'subType' => 'quick_reply',
'index' => 1,
'parameters' => [
new WhatsAppParameter([
'type' => 'payload',
'payload' => '<PAYLOAD>'
])
]
]);
$whatsAppTemplate = new WhatsAppTemplate([
'name' => '<TEMPLATE_NAME>',
'language' => new WhatsAppLanguage(['code' => '<LANGUAGE_CODE>']),
'components' => [$bodyComponent, $yesButtonComponent, $noButtonComponent]
]);
$whatsappMessage = new WhatsApp([
'channel' => 'whatsapp',
'sender' => '<SENDER_NAME>',
'template' => $whatsAppTemplate
]);
$omnimessage = new Omnimessage([
'to' => '<RECIPIENT_PHONE_NUMBER>',
'messages' => [$whatsappMessage]
]);
try {
$result = $apiInstance->sendOmnimessage($omnimessage);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling sendOmnimessage: ', $e->getMessage(), PHP_EOL;
}
package org.example;
import com.messente.ApiClient;
import com.messente.ApiException;
import com.messente.api.*;
import com.messente.auth.HttpBasicAuth;
import java.util.List;
// repositories { mavenCentral() }
// dependencies { implementation 'com.messente.api:messente-api' }
public class TextWithQuickReplyExample {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient();
OmnimessageApi apiInstance = new OmnimessageApi(apiClient);
HttpBasicAuth basicAuth = (HttpBasicAuth) apiClient.getAuthentication("basicAuth");
basicAuth.setUsername("YOUR_MESSENTE_API_USERNAME");
basicAuth.setPassword("YOUR_MESSENTE_API_PASSWORD");
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate();
whatsAppTemplate.name("<TEMPLATE_NAME>");
whatsAppTemplate.language(new WhatsAppLanguage().code("<LANGUAGE_CODE>"));
WhatsAppComponent bodyComponent = new WhatsAppComponent();
bodyComponent.type("body");
bodyComponent.setParameters(
List.of(new WhatsAppParameter().type("text").text("<PARAMETER_TEXT (e.g. a name or ID)>"))
);
WhatsAppComponent yesButtonComponent = new WhatsAppComponent();
yesButtonComponent.type("button").subType("quick_reply").index(0);
yesButtonComponent.setParameters(
List.of(new WhatsAppParameter().type("payload").payload("<YOUR_PAYLOAD>"))
);
WhatsAppComponent noButtonComponent = new WhatsAppComponent();
noButtonComponent.type("button").subType("quick_reply").index(1);
noButtonComponent.setParameters(
List.of(new WhatsAppParameter().type("payload").payload("<YOUR_PAYLOAD>"))
);
whatsAppTemplate.setComponents(
List.of(bodyComponent, yesButtonComponent, noButtonComponent)
);
WhatsApp whatsApp = new WhatsApp();
whatsApp.sender("<SENDER_NAME>");
whatsApp.template(whatsAppTemplate);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsApp);
whatsAppOmnimessageInner.setActualInstance(whatsApp);
Omnimessage omnimessage = new Omnimessage();
omnimessage.setMessages(List.of(whatsAppOmnimessageInner));
omnimessage.setTo("<RECIPIENT_PHONE_NUMBER>");
try {
OmniMessageCreateSuccessResponse result = apiInstance.sendOmnimessage(omnimessage);
System.out.println(result);
} catch (ApiException e) {
System.err.println(e.getResponseBody());
}
}
}
# gem install messente_api
require 'messente_api'
MessenteApi.configure do |config|
config.username = 'YOUR_MESSENTE_API_USERNAME'
config.password = 'YOUR_MESSENTE_API_PASSWORD'
end
api_instance = MessenteApi::OmnimessageApi.new
body_component = MessenteApi::WhatsAppComponent.new(
type: 'body',
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'text',
text: '<PARAMETER_TEXT (e.g. a name or ID)>'
)
]
)
yes_button_component = MessenteApi::WhatsAppComponent.new(
type: 'button',
sub_type: 'quick_reply',
index: 0,
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'payload',
payload: '<PAYLOAD>'
)
]
)
no_button_component = MessenteApi::WhatsAppComponent.new(
type: 'button',
sub_type: 'quick_reply',
index: 1,
parameters: [
MessenteApi::WhatsAppParameter.new(
type: 'payload',
payload: '<PAYLOAD>'
)
]
)
whatsapp_template = MessenteApi::WhatsAppTemplate.new(
name: '<TEMPLATE_NAME>',
language: MessenteApi::WhatsAppLanguage.new(code: '<LANGUAGE_CODE>'),
components: [body_component, yes_button_component, no_button_component]
)
whatsapp_message = MessenteApi::WhatsApp.new(
channel: 'whatsapp',
sender: '<SENDER_NAME>',
template: whatsapp_template
)
omnimessage = MessenteApi::Omnimessage.new(
to: '<RECIPIENT_PHONE_NUMBER>',
messages: [whatsapp_message]
)
begin
result = api_instance.send_omnimessage(omnimessage)
puts result
rescue MessenteApi::ApiError => e
puts "Exception when calling send_omnimessage: #{e}"
puts e.response_body
end
// PM > Install-Package com.Messente.Api
using System;
using com.Messente.Api.Api;
using com.Messente.Api.Client;
using com.Messente.Api.Model;
namespace WhatsAppTextWithQuickReplyExample
{
public class WhatsAppTextWithQuickReplyExample
{
public static void Main()
{
Configuration conf = new Configuration
{
Username = "YOUR_MESSENTE_API_USERNAME",
Password = "YOUR_MESSENTE_API_PASSWORD",
};
var apiInstance = new OmnimessageApi(conf);
WhatsAppParameter bodyParameter = new WhatsAppParameter(
type: "text",
text: "<PARAMETER_TEXT (e.g. a name or ID)>"
);
WhatsAppComponent bodyComponent = new WhatsAppComponent(
type: "body",
parameters: new List<WhatsAppParameter> { bodyParameter }
);
WhatsAppComponent yesButtonComponent = new WhatsAppComponent(
type: "button",
subType: "quick_reply",
index: 0,
parameters: new List<WhatsAppParameter> { new WhatsAppParameter(type: "payload", payload: "<YOUR_PAYLOAD>") }
);
WhatsAppComponent noButtonComponent = new WhatsAppComponent(
type: "button",
subType: "quick_reply",
index: 1,
parameters: new List<WhatsAppParameter> { new WhatsAppParameter(type: "payload", payload: "<YOUR_PAYLOAD>") }
);
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate(
name: "<TEMPLATE_NAME>",
language: new WhatsAppLanguage(code: "<LANGUAGE_CODE>"),
components: new List<WhatsAppComponent> { bodyComponent, yesButtonComponent, noButtonComponent }
);
var whatsapp = new WhatsApp(
sender: "<SENDER_NAME>",
template: whatsAppTemplate
);
OmnimessageMessagesInner whatsAppOmnimessageInner = new OmnimessageMessagesInner(whatsapp)
{
ActualInstance = whatsapp
};
var omnimessage = new Omnimessage(
to: "<RECIPIENT_PHONE_NUMBER>",
messages: new List<OmnimessageMessagesInner> { whatsAppOmnimessageInner }
);
try
{
var result = apiInstance.SendOmnimessage(omnimessage);
Console.WriteLine(result.ToJson());
}
catch (Exception e)
{
Console.WriteLine("Exception when calling SendOmnimessage: " + e.Message);
}
}
}
}
curl -X POST \
'https://api.messente.com/v1/omnimessage' \
-u MESSENTE_API_USERNAME:MESSENTE_API_PASSWORD \
-H 'Content-Type: application/json' \
-d '{
"to": "<RECIPIENT_PHONE_NUMBER>",
"messages": [
{
"channel": "whatsapp",
"sender": "<SENDER_NAME>",
"template": {
"name": "test_quick_reply",
"language": {
"code": "<LANGUAGE_CODE>"
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "<PARAMETER_TEXT (e.g. a name or ID)>"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [
{
"type": "payload",
"payload": "<PAYLOAD>"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 1,
"parameters": [
{
"type": "payload",
"payload": "<PAYLOAD>"
}
]
}
]
}
}
]
}'