Viber Message

Sending Viber 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 Viber, WhatsApp or Telegram messages, please contact our support team. These providers require some extra verification before approving sender ID.

Send Viber Message

Use the following example to send a Viber 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 viber = new Viber(text: "Hello viber!");

            messages.Add(viber);

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

            try
            {
                OmniMessageCreateSuccessResponse result = apiInstance.SendOmnimessage(omnimessage);
                Debug.Print("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": "viber", "sender": "YOUR_PHONE_NUMBER", "text": "Hello Viber!" }] }'
    
// 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();

        Viber viber = new Viber();
        viber.text("Viber text");
        viber.sender("YOUR_PHONE_NUMBER");

        omnimessage.setMessages(Arrays.asList(viber,));
        omnimessage.setTo("RECIPIENT_PHONE_NUMBER");

        try {
            OmniMessageCreateSuccessResponse result = apiInstance.sendOmnimessage(omnimessage);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when sending a 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 viber = OmnichannelApi.Viber.constructFromObject({
	text: "Hello Viber!",
	sender: "YOUR_PHONE_NUMBER"
});

const omnimessage = OmnichannelApi.Omnimessage.constructFromObject({
    messages: [viber],
    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\Viber;

// 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"]);

$viber = new Viber( ["text" => "Hello Viber!", "sender" => "YOUR_PHONE_NUMBER"]);
$omnimessage->setMessages([$viber]);

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

from omnichannel import OmnimessageApi, Viber, Omnimessage, Configuration, ApiClient
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))

viber = Viber(sender="YOUR_PHONE_NUMBER", text="Hello Viber")

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

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::Viber.new(
        {
            :sender => "YOUR_PHONE_NUMBER",
            :text => "Hello from Viber!"
        }
    )
]

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

Response

{
  "messages": [
    {
      "channel": "viber",
      "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

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

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

Possible combinations of text, image and button elements:

Text Button Image
Only text
Text with button
Text, image and button
Only image    

Keep in mind that because of Viber API restrictions you can only send text content with image if you add a button to the same message.

Use the following parameters to compose the message with different elements:

text: Message (max 1000 characters)
image_url: Emebedded image URL (jpg, jpeg, png, gif files are supported)
button_text: The text of the button
button_url: The URL of the buton

Receiving Messages

Receiving messages is currently not supported for Viber 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