WhatsApp Message

Sending 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 or Viber 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.

// PM > Install-Package com.Messente.Omnichannel

using System;
using System.Diagnostics;
using System.Collections.Generic;
using com.Messente.Omnichannel.Api;
using com.Messente.Omnichannel.Client;
using com.Messente.Omnichannel.Model;

namespace Example
{
    public class SendOmniMessageExample
    {
        public static void Main()
        {
            // Configure HTTP basic authorization: basicAuth
            Configuration.Default.Username = "MESSENTE_API_USERNAME";
            Configuration.Default.Password = "MESSENTE_API_PASSWORD";

            List messages = new List();
            var whatsapp = new WhatsApp(text: new WhatsAppText(body: "Hello WhatsApp!"));

            messages.Add(whatsapp);

            var apiInstance = new OmnimessageApi();
            var omnimessage = new Omnimessage(to: "RECIPIENT_PHONE_NUMBER", messages: messages);

            try
            {
                OmniMessageCreateSuccessResponse result = apiInstance.SendOmnimessage(omnimessage);
                Debug.Print("WhatsApp message successfully sent!");
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("There was a problem sending message: " + e.Message);
            }

        }
    }
}
    
curl https://api.messente.com/v1/omnimessage \
    -u MESSENTE_API_USERNAME:MESSENTE_API_PASSWORD \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{ "to": "RECIPIENT_PHONE_NUMBER", "messages": [{ "channel": "whatsapp", "sender": "YOUR_PHONE_NUMBER", "text": "Hello WhatsApp!" }] }'
    
// compile "com.messente.omnichannel:omnichannel-java"

public class Main {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();

        // Configure HTTP basic authorization: basicAuth
        HttpBasicAuth basicAuth = (HttpBasicAuth) defaultClient.getAuthentication("basicAuth");
        basicAuth.setUsername("MESSENTE_API_USERNAME");
        basicAuth.setPassword("MESSENTE_API_PASSWORD");

        OmnimessageApi apiInstance = new OmnimessageApi();
        Omnimessage omnimessage = new Omnimessage();

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

        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("Exception when sending message");
            e.printStackTrace();
        }
    }
}
    
// npm install omnichannel_api --save

const OmnichannelApi = require('omnichannel_api');

const defaultClient = OmnichannelApi.ApiClient.instance;

// Configure HTTP basic authorization: basicAuth
const basicAuth = defaultClient.authentications['basicAuth'];
basicAuth.username = 'MESSENTE_API_USERNAME';
basicAuth.password = 'MESSENTE_API_PASSWORD';

const api = new OmnichannelApi.OmnimessageApi();

const whatsAppText = OmnichannelApi.WhatsAppText.constructFromObject({
	body: "Hello WhatsApp!",
	preview_url: false
});

const whatsapp = OmnichannelApi.WhatsApp.constructFromObject({
	text: whatsAppText,
    sender: "YOUR_PHONE_NUMBER"
});

const omnimessage = OmnichannelApi.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-omnichannel-php

require_once(__DIR__ . '/../vendor/autoload.php');

use \Messente\Omnichannel\Api\OmnimessageApi;
use \Messente\Omnichannel\Configuration;
use \Messente\Omnichannel\Model\Omnimessage;
use \Messente\Omnichannel\Model\WhatsApp;
use \Messente\Omnichannel\Model\WhatsAppText;

// Configure HTTP basic authorization: basicAuth
$config = Configuration::getDefaultConfiguration()
    ->setUsername('MESSENTE_API_USERNAME')
    ->setPassword('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" => "YOUR_PHONE_NUMBER"]);
$omnimessage->setMessages([$whatsapp]);

try {
    $result = $apiInstance->sendOmnimessage($omnimessage);
    print_r($result);
} catch (Exception $e) {
    echo 'Sending message failed: ', $e->getMessage(), PHP_EOL;
}
    
# pip install omnichannel-api

from omnichannel import OmnimessageApi, Omnimessage, Configuration, ApiClient, WhatsApp, WhatsAppText
from omnichannel.rest import ApiException

# API information from https://dashboard.messente.com/api-settings
configuration = Configuration()
configuration.username = "MESSENTE_API_USERNAME"
configuration.password = "MESSENTE_API_PASSWORD"

# create an instance of the API class
api_instance = OmnimessageApi(ApiClient(configuration))

whatsapp = WhatsApp(sender="YOUR_PHONE_NUMBER", text=WhatsAppText(body="Hello WhatsApp"))

omnimessage = Omnimessage(to="RECIPIENT_PHONE_NUMBER", messages=( whatsapp,))

try:
    response = api_instance.send_omnimessage(omnimessage)
    print("Message successfully sent with id %s:" % response.omnimessage_id)
except ApiException as e:
    print("There was a problem sending message: %s\n" % e)
    
# gem 'omnichannel', '~> 1.0.0'

require 'omnichannel'

# setup authorization
Omnichannel.configure do |config|
    # Configure HTTP basic authorization: basicAuth
    config.username = 'MESSENTE_API_USERNAME'
    config.password = 'MESSENTE_API_PASSWORD'
end

api_instance = Omnichannel::OmnimessageApi.new

omnimessage = Omnichannel::Omnimessage.new
omnimessage.to = 'RECIPIENT_PHONE_NUMBER'
omnimessage.messages = [
    Omnichannel::WhatsApp.new(
        {
            :sender => "YOUR_PHONE_NUMBER",
            :text => Omnichannel::WhatsAppText.new(
                {
                    :body => "Hello from WhatsApp!",
                    :preview_url => false
                }
            )
        }
    )
]

begin
    result = api_instance.send_omnimessage(omnimessage)
    puts "SMS successfully sent!"
rescue Omnichannel::ApiError => e
    puts "There was a problem with sending message: #{e}"
    puts e.response_body
end
    

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 = WhatsApp(
  sender="YOUR_PHONE_NUMBER",
  text=WhatsAppText(body="Hello WhatsApp", preview_url=true)
)
whatsapp = WhatsApp(
  sender="YOUR_PHONE_NUMBER",
  image=WhatsAppImage(caption="Company Logo!", content="image in base64")
)
whatsapp = WhatsApp(
  sender="YOUR_PHONE_NUMBER",
  document=WhatsAppDocument(caption="Document Title", content="document in base64")
)
whatsapp = WhatsApp(
  sender="YOUR_PHONE_NUMBER",
  audio=WhatsAppAudio(content="audio in base64")
)
const whatsAppText = OmnichannelApi.WhatsAppText.constructFromObject({
  body: "Hello WhatsApp!",
  preview_url: false
});
const whatsAppImage = OmnichannelApi.WhatsAppImage.constructFromObject({
  caption: "Company Logo!",
  content: "image in base64"
});
const whatsAppDocument = OmnichannelApi.WhatsAppDocument.constructFromObject({
  caption: "Document Title!",
  content: "document in base64"
});
const whatsAppAudio = OmnichannelApi.WhatsAppAudio.constructFromObject({
  content: "audio in base64"
});

// Only 1 element can be sent in a single message
const whatsapp = OmnichannelApi.WhatsApp.constructFromObject({
  // text: whatsAppText,
  // image: whatsAppImage,
  // document: whatsAppDocument,
  // audio: whatsAppAudio,
  sender: "YOUR_PHONE_NUMBER"
});
$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" => "YOUR_PHONE_NUMBER"
]);
// Only 1 element can be sent in a single message

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

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

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

WhatsApp whatsApp = 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 => "YOUR_PHONE_NUMBER",
      :text => Omnichannel::WhatsAppText.new(
        {
          :body => "Hello from WhatsApp!",
          :preview_url => false
        }
      )
    }
  )
]
omnimessage.messages = [
  Omnichannel::WhatsApp.new(
    {
      :sender => "YOUR_PHONE_NUMBER",
      :image => Omnichannel::WhatsAppImage.new(
        {
          :caption => "Company Logo!",
          :content => "image in base64"
        }
      )
    }
  )
]
omnimessage.messages = [
  Omnichannel::WhatsApp.new(
    {
      :sender => "YOUR_PHONE_NUMBER",
      :document => Omnichannel::WhatsAppDocument.new(
        {
          :caption => "Document Title!",
          :content => "document in base64"
        }
      )
    }
  )
]
omnimessage.messages = [
  Omnichannel::WhatsApp.new(
    {
      :sender => "YOUR_PHONE_NUMBER",
      :audio => Omnichannel::WhatsAppAudio.new(
        {
          :content => "audio in base64"
        }
      )
    }
  )
]
// Only 1 element can be sent in a single message
var whatsapp = new WhatsApp(
    text: new WhatsAppText(
        body: "Hello WhatsApp!",
        previewUrl: true
    )
);
var whatsapp = new WhatsApp(
    image: new WhatsAppImage(
        caption: "Company Logo",
        content: "image in base64"
    ),
);
var whatsapp = new WhatsApp(
    document: new WhatsAppDocument(
        caption: "Document Title",
        content: "document in base64"
    ),
);
var whatsapp = new WhatsApp(
    audio: new WhatsAppAudio(
        content: "audio in base64"
    ),
);
# Only 1 element can be sent in a single message
curl https://api.messente.com/v1/omnimessage \
  -u MESSENTE_API_USERNAME:MESSENTE_API_PASSWORD \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "to": "RECIPIENT_PHONE_NUMBER",
    "messages": [{
      "channel": "whatsapp",
      "sender": "YOUR_PHONE_NUMBER",
      "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"
      }
    }]
  }'

Receiving Messages

Receiving messages is currently not supported for WhatsApp messages.

Adding two-way message capabilities to Omnichannel API is a high priority to us. Write to us to get early access.

Error example

{
  "errors": [
    {
      "code": "105",
      "detail": "Invalid or disallowed sender Messente",
      "source": "payload[viber][sender]",
      "title": "Invalid data"
    }
  ]
}
Key Value
title Error message
detail Longer description of the error message
code Machine-readable error code

101 Not found
102 Forbidden
103 Unauthorized
104 Invalid data
105 Internal Server Error
106 Missing data
107 Method not allowed
source Location in the request body for this error message