Skip to main content

WhatsApp Message

Send WhatsApp messages with Messente's Omnichannel API.

tip

The easiest way to use Omnichannel API is with our official libraries. Libraries will take care of authentication, request validation and response handling.

WhatsApp Business Account Required

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.

# 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)

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"
}
]
}
titleError message
detailLonger description of the error message
sourceLocation in the request body for this error message
codeMachine-readable error code: 101 - Not found 102 - Forbidden 103 - Unauthorized 104 - Internal Server Error 105 - Invalid data 106 - Missing data 107 - Method not allowed