WhatsApp Message
Send WhatsApp messages with Messente's Omnichannel API.
The easiest way to use Omnichannel API is with our official libraries. Libraries will take care of authentication, request validation and response handling.
Sending WhatsApp messages requires having set up billing and having your message templates approved by Meta. Meta only allows sending business-initiated messages that match a pre-approved template. Messente matches your message to an existing approved template.
Follow our support guides for more details on setting up your WhatsApp account and connecting it to Messente.
Send WhatsApp Message
Use the following example to send a WhatsApp Message using Omnichannel API.
- Python
- Node
- PHP
- Java
- Ruby
- .NET
- cURL
# pip install messente-api
from pprint import pprint
from messente_api import (
OmnimessageApi,
Omnimessage,
Configuration,
ApiClient,
WhatsApp,
WhatsAppParameter,
WhatsAppComponent,
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_parameters = [WhatsAppParameter(type='text', text='hello whatsapp')]
wa_component = WhatsAppComponent(type='body', parameters=wa_parameters)
wa_template = WhatsAppTemplate(
name='<template name>',
language=WhatsAppLanguage(code='<language_code>'),
components=[wa_component],
)
whatsapp = WhatsApp(sender='<sender name (optional)>', 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 whatsAppParameters = [
MessenteApi.WhatsAppParameter.constructFromObject({
type: "text",
text: "hello whatsapp",
}),
];
const whatsAppComponent = MessenteApi.WhatsAppComponent.constructFromObject({
type: "body",
parameters: whatsAppParameters,
});
const whatsAppTemplate = MessenteApi.WhatsAppTemplate.constructFromObject({
name: "<template_name>",
language: MessenteApi.WhatsAppLanguage.constructFromObject({
code: "<language_code>",
}),
components: [whatsAppComponent],
});
const whatsapp = MessenteApi.WhatsApp.constructFromObject({
sender: "<sender name (optional)>",
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
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>',
]);
$whatsAppParameters = [new WhatsAppParameter(['type' => 'text', 'text' => 'hello whatsapp'])];
$whatsAppComponent = new WhatsAppComponent(['type' => 'body', 'parameters' => $whatsAppParameters]);
$whatsAppLanguage = new WhatsAppLanguage(['code' => '<language_code>']);
$whatsAppTemplate = new WhatsAppTemplate(
[
'name'=> '<template_name>',
'language'=> $whatsAppLanguage,
'components' => [$whatsAppComponent]
]
);
$whatsapp = new WhatsApp(
[
'sender' => '<sender name (optional)>',
'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;
}
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 Main {
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");
WhatsAppParameter whatsAppParameter = new WhatsAppParameter();
whatsAppParameter.type("text");
whatsAppParameter.text("hello whatsapp");
WhatsAppComponent whatsAppComponent = new WhatsAppComponent();
whatsAppComponent.type("body");
whatsAppComponent.setParameters(List.of(whatsAppParameter));
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate();
whatsAppTemplate.name("<template_name>");
whatsAppTemplate.language(new WhatsAppLanguage().code("<language_code>"));
whatsAppTemplate.setComponents(List.of(whatsAppComponent));
WhatsApp whatsApp = new WhatsApp();
whatsApp.sender("<sender name (optional)>");
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_parameters = [
MessenteApi::WhatsAppParameter.new(type: 'text', text: 'hello whatsapp'),
]
wa_component = MessenteApi::WhatsAppComponent.new(type: 'body', parameters: wa_parameters)
wa_lang = MessenteApi::WhatsAppLanguage.new(code: '<language_code>')
wa_template = MessenteApi::WhatsAppTemplate.new(name: '<template_name>', language: wa_lang, components: [wa_component])
omnimessage.messages = [
MessenteApi::WhatsApp.new(
sender: '<sender name (optional)>',
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 SendOmniMessageExample
{
public static void Main()
{
Configuration conf = new Configuration
{
Username = "YOUR_MESSENTE_API_USERNAME",
Password = "YOUR_MESSENTE_API_PASSWORD"
};
var apiInstance = new OmnimessageApi(conf);
WhatsAppParameter whatsAppParameter = new WhatsAppParameter(
type: "text",
text: "hello whatsapp"
);
WhatsAppComponent whatsAppComponent = new WhatsAppComponent(
type: "body",
parameters: new List<WhatsAppParameter> { whatsAppParameter }
);
WhatsAppTemplate whatsAppTemplate = new WhatsAppTemplate(
name: "<template_name>",
language: new WhatsAppLanguage(code: "<language_code>"),
components: new List<WhatsAppComponent> { whatsAppComponent }
);
var whatsapp = new WhatsApp(
sender: "<sender name (optional)>",
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 (optional)>",
"template": {
"name": "<template_name>",
"language": {
"code": "<language_code>"
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "hello whatsapp"
}
]
}
]
}
}
]
}'
Response
The API will return a response with an omnimessage_id, as well as a message_id for each "sub-message" (fallback channel). You can use these IDs to track the delivery status of the message.
{
"messages": [
{
"channel": "whatsapp",
"message_id": "fr593ce7-68de-5e44-bc50-044a3ad0a7fa",
"sender": "SENDER_ID"
}
],
"omnimessage_id": "632c6f3d-49d0-4a8f-5k2n-74023d31e51d",
"to": "RECIPIENT_PHONE_NUMBER"
}
Error example
{
"errors": [
{
"code": "105",
"detail": "Invalid or disallowed sender Messente",
"source": "payload[whatsapp][sender]",
"title": "Invalid data"
}
]
}
title | Error message |
---|---|
detail | Longer description of the error message |
source | Location in the request body for this error message |
code | Machine-readable error code: 101 - Not found 102 - Forbidden 103 - Unauthorized 104 - Internal Server Error 105 - Invalid data 106 - Missing data 107 - Method not allowed |