Messente logo

WhatsApp Message

Send WhatsApp messages with 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.

Before sending WhatsApp, Viber or Telegram messages, please contact our support team. These providers require some extra verification before approving sender ID.

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,
    WhatsAppText,
)
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))

whatsapp = WhatsApp(
    sender="<sender name (optional)>", text=WhatsAppText(body="hello whatsapp")
)

omnimessage = Omnimessage(
    messages=tuple([whatsapp]), 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 whatsAppText = MessenteApi.WhatsAppText.constructFromObject({
  body: 'hello whatsapp',
});

const whatsapp = MessenteApi.WhatsApp.constructFromObject({
  text: whatsAppText,
});

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);
  }
});
<?php

// 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\WhatsAppText;
use Messente\Api\Model\WhatsApp;

$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>',
]);

$whatsAppText = new WhatsAppText(
    [
        'body' => 'hello whatsapp',
    ]
);

$whatsapp = new WhatsApp(
    [
        'text' => $whatsAppText,
        'sender' => '<sender name (optional)>',
    ]
);

$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.OmniMessageCreateSuccessResponse;
import com.messente.api.Omnimessage;
import com.messente.api.OmnimessageApi;
import com.messente.api.WhatsApp;
import com.messente.api.WhatsAppText;
import com.messente.auth.HttpBasicAuth;

import java.util.Arrays;

// repositories { jcenter() }
// dependencies { implementation 'com.messente.api:messente-api' }

public class Main {
    public static void main(String[] args) {
        ApiClient apiClient = new ApiClient();

        HttpBasicAuth basicAuth = (HttpBasicAuth) apiClient.getAuthentication("basicAuth");
        basicAuth.setUsername("YOUR_MESSENTE_API_USERNAME");
        basicAuth.setPassword("YOUR_MESSENTE_API_PASSWORD");

        WhatsApp whatsApp = new WhatsApp();
        WhatsAppText whatsAppText = new WhatsAppText();
        whatsAppText.body("hello whatsapp");
        whatsApp.text(whatsAppText);
        whatsApp.sender("<sender name (optional)>");

        OmnimessageApi apiInstance = new OmnimessageApi(apiClient);
        Omnimessage omnimessage = new Omnimessage();
        omnimessage.setMessages(Arrays.asList(whatsApp));
        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>'
omnimessage.messages = [
  MessenteApi::WhatsApp.new(
    sender: '<sender name (optional)>',
    text: MessenteApi::WhatsAppText.new(
      body: 'hello whatsapp!'
    )
  )
]

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 System.Diagnostics;
using System.Collections.Generic;
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();
            conf.Username = "YOUR_MESSENTE_API_USERNAME";
            conf.Password = "YOUR_MESSENTE_API_PASSWORD";
            var apiInstance = new OmnimessageApi(conf);

            var whatsapp = new WhatsApp(
                sender: "<sender name (optional)>",
                text: new WhatsAppText(body: "hello whatsapp")
            );

            List<object> messages = new List<object>
            {
                whatsapp
            };

            var omnimessage = new Omnimessage(
                to: "<recipient_phone_number>",
                messages: messages
            );

            try
            {
                var result = apiInstance.SendOmnimessage(omnimessage);
                Debug.WriteLine(result.ToJson());
            }
            catch (Exception e)
            {
                Debug.Print("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)>",
        "text": {
          "body": "hello whatsapp"
        }
      }
    ]
  }'

Response

{
  "messages": [
    {
      "channel": "whatsapp",
      "message_id": "fr593ce7-68de-5e44-bc50-044a3ad0a7fa",
      "sender": "SENDER_ID"
    }
  ],
  "omnimessage_id": "632c6f3d-49d0-4a8f-5k2n-74023d31e51d",
  "to": "RECIPIENT_PHONE_NUMBER"
}

Use the message_id to keep track of the message delivery status.


Features

WhatsApp messages are not limited to SMS restrictions. You can use text, images, documents, or audio in your messages for the same price.

These features are mutually exclusive. Only a single element can be sent at once.

WhatsApp has different price and content requirements for transactional and marketing messages. Contact us to learn more.

# Only 1 element can be sent in a single message
whatsapp_text = WhatsApp(
  sender="<sender name (optional)>",
  text=WhatsAppText(body="Hello WhatsApp", preview_url=true)
)
whatsapp_image = WhatsApp(
  sender="<sender name (optional)>",
  image=WhatsAppImage(caption="Company Logo!", content="image in base64")
)
whatsapp_document = WhatsApp(
  sender="<sender name (optional)>",
  document=WhatsAppDocument(caption="Document Title", content="document in base64")
)
whatsapp_audio = WhatsApp(
  sender="<sender name (optional)>",
  audio=WhatsAppAudio(content="audio in base64")
)
const whatsAppText = MessenteApi.WhatsAppText.constructFromObject({
  body: 'Hello WhatsApp!',
  preview_url: false,
});
const whatsAppImage = MessenteApi.WhatsAppImage.constructFromObject({
  caption: 'Company Logo!',
  content: 'image in base64',
});
const whatsAppDocument = MessenteApi.WhatsAppDocument.constructFromObject({
  caption: 'Document Title!',
  content: 'document in base64',
});
const whatsAppAudio = MessenteApi.WhatsAppAudio.constructFromObject({
  content: 'audio in base64',
});

// Only 1 element can be sent in a single message
const whatsapp = MessenteApi.WhatsApp.constructFromObject({
  // text: whatsAppText,
  // image: whatsAppImage,
  // document: whatsAppDocument,
  // audio: whatsAppAudio,
  sender: '<sender name (optional)>',
});
<?php

$whatsAppText = new WhatsAppText([
  'body' => 'Hello WhatsApp!',
  'previewUrl' => true,
]);

$whatsAppImage = new WhatsAppImage([
  'caption' => 'Company Logo',
  'content' => 'image in base64',
]);
$whatsAppDocument = new WhatsAppDocument([
  'caption' => 'Document Title',
  'content' => 'document in base64',
]);
$whatsAppAudio = new WhatsAppAudio([
  'content' => 'audio in base64',
]);

// Only 1 element can be sent in a single message
$whatsapp = new WhatsApp([
//  "text" => $whatsAppText,
//  "image" => $whatsAppImage,
//  "document" => $whatsAppDocument,
//  "audio" => $whatsAppAudio,
  'sender' => '<sender name (optional)>',
]);
// Only 1 element can be sent in a single message

WhatsApp whatsAppText = new WhatsApp();
WhatsAppText whatsAppText = new WhatsAppText();
whatsAppText.body("WhatsApp text");
whatsAppText.previewUrl(true);
whatsApp.text(whatsAppText);

WhatsApp whatsAppImage = new WhatsApp();
WhatsAppImage whatsAppImage = new WhatsAppImage();
whatsAppImage.caption("Company Logo");
whatsAppImage.content("image in base64");
whatsApp.image(whatsAppImage);

WhatsApp whatsAppDocument = new WhatsApp();
WhatsAppDocument whatsAppDocument = new WhatsAppDocument();
whatsAppDocument.caption("Document Title");
whatsAppDocument.content("document in base64");
whatsApp.document(whatsAppDocument);

WhatsApp whatsAppAudio = new WhatsApp();
WhatsAppAudio whatsAppAudio = new WhatsAppAudio();
whatsAppAudio.content("audio in base64");
whatsApp.audio(whatsAppAudio);
# Only 1 element can be sent in a single message

omnimessage.messages = [
  Omnichannel::WhatsApp.new(
    sender: '<sender name (optional)>',
    text: Omnichannel::WhatsAppText.new(
      body: 'Hello from WhatsApp!',
      preview_url: false
    )
  ),
  Omnichannel::WhatsApp.new(
    sender: '<sender name (optional)>',
    image: Omnichannel::WhatsAppImage.new(
      caption: 'Company Logo!',
      content: 'image in base64'
    )
  ),
  Omnichannel::WhatsApp.new(
    sender: '<sender name (optional)>',
    document: Omnichannel::WhatsAppDocument.new(
      caption: 'Document Title!',
      content: 'document in base64'
    )
  ),
  Omnichannel::WhatsApp.new(
    sender: '<sender name (optional)>',
    audio: Omnichannel::WhatsAppAudio.new(
      content: 'audio in base64'
    )
  )
]
// Only 1 element can be sent in a single message
var whatsAppText = new WhatsApp(
    text: new WhatsAppText(
        body: "Hello WhatsApp!",
        previewUrl: true
    )
);
var whatsAppImage = new WhatsApp(
    image: new WhatsAppImage(
        caption: "Company Logo",
        content: "image in base64"
    )
);
var whatsAppDocument = new WhatsApp(
    document: new WhatsAppDocument(
        caption: "Document Title",
        content: "document in base64"
    )
);
var whatsAppAudio = new WhatsApp(
    audio: new WhatsAppAudio(
        content: "audio in base64"
    )
);
# Only 1 element can be sent in a single 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)>",
      "text": {
        "body": "Happy Messaging!",
        "preview_link": true
      },
      "image": {
        "caption": "Company Logo",
        "content": "image in base64"
      },
      "document": {
        "caption": "read this!",
        "content": "document in base64"
      },
      "audio": {
        "content": "audio in base64"
      }
    }]
  }'

Error example

{
  "errors": [
    {
      "code": "105",
      "detail": "Invalid or disallowed sender Messente",
      "source": "payload[whatsapp][sender]",
      "title": "Invalid data"
    }
  ]
}
Key Value
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