OMNI channel: Viber example

Find out about the simple methods which will allow you to send messages and retrieve message reports using the Viber and SMS communication channels.

In the following examples, we’ll show you how to configure the Viber-SMS failover scenario, send your first messages and retrieve message reports.

The messages will firstly be sent over the Viber communication channel. If the messages are rejected on Viber (for example, the user doesn’t have Viber installed), the messages will be sent using the SMS communication channel. For each communication channel, a specific validity period can be set.

There are three easy steps to follow:

1. Create OMNI scenario

The first step is to create an OMNI scenario. In the OMNI scenario configuration, you need to define the OMNI steps which will be sequentially executed. The key parameters are channel and from, respectively identifying the communication channels and senders for each communication channel.

Prerequisites

To be able to send Viber messages using the Infobip platform you need to configure the Viber service. Please contact us for service activation and configuration.

For Viber sender (“channel”: “VIBER” flow) you should use the Viber sender provided during the activation process.

POST /omni/1/scenarios HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{
  "name":"My VIBER-SMS scenario",
  "flow": [
    {
      "from": "ViberSender",
      "channel": "VIBER"
    },
    {
      "from": "InfoSMS",
      "channel": "SMS"
    }    
  ],
  "default": true
}	
  

Response format

If successful, the response header HTTP status code will be 200 OK and the scenario will be created, as shown in the example bellow.

If you try to create the scenario without authorization, you will receive a 401 Unauthorized error.

{
  "key": "CC9F01A5DC7BEE2C2B829D203482A654",
  "name":"My VIBER-SMS scenario",
  "flow": [
    {
      "from": "ViberSender",
      "channel": "VIBER"
    },
    {
      "from": "InfoSMS",
      "channel": "SMS"
    }    
  ],
  "default": true
}	
  

The key parameter needs to be stored as it will be used when sending the message.

Info

More information about creating an OMNI scenario can be found at the following page: Scenario:// Create.

2. Send OMNI message

Once you’ve created an OMNI scenario (identified by the key parameter) as described in the previous chapter, you are ready to send your OMNI messages through defined VIBER and SMS communication channels. First, the VIBER message will be sent to the defined phoneNumber. If, for some reason, the message is rejected on the VIBER application or the end user doesn’t have the Viber application installed, the message will be sent using the SMS communication channel.

For sending OMNI messages, you can use the advanced API method. Detailed descriptions about the advanced API method can be found here: OMNI:// Send an advanced message.

The parameters that should be set are the scenario key, phoneNumber and specific text for each communication channels, as shown below.

POST /omni/1/advanced HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{ 
	"scenarioKey":"CC9F01A5DC7BEE2C2B829D203482A654",  
  "destinations":[ 
  	{ 
    	"to":{
        "phoneNumber": "41793026727"
      }
    }
  ],
  "viber": {
  	"text": "This Viber message will be delivered to Viber application on the user device."
  },
  "sms": {
  	"text": "This is the SMS failover message"
  }
}	
  

Response format

If successful, the response header HTTP status code will be 200 OK and the message will be sent.

If you try to send the message without authorization, you will receive a 401 Unauthorized error.

HTTP/1.1 200 OK
Content-Type: application/json

{   
    "messages":[   
       {   
            "to":{
              "phoneNumber": "41793026731"
            },
            "status": {
                "groupId": 1,
                "groupName": "PENDING",
                "id": 7,
                "name": "PENDING_ENROUTE",
                "description": "Message sent to next instance"
            },
            "messageId": "50c24400-124f-4678-9f4b-309e994a4deb"
        }
    ]
}	
  

3. Get Delivery Reports

Once you’ve successfully sent your message using the advanced API method you can check the status of sent messages using the OMNI reports method.

The simplest way is to use the method without any query parameters. In that case, the response will contain all messages sent to a specific account.

GET /omni/1/reports HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Accept: application/json	
  

The response will contain all messages, rejected and delivered, as shown in the example below.

HTTP/1.1 200 OK
Content-Type: application/json

{  
   "results":[  
      {  
         "messageId":"1215f543ab19-345f-adbd-12ad31451ed25f35",
         "to":"41793026731",
         "messageCount": 1,
         "sentAt":"2016-02-23T17:41:11.833+0100",
         "doneAt":"2016-02-23T17:41:11.843+0100",
         "mccMnc":"22801",
         "price":{  
            "pricePerMessage":0.0104,
            "currency":"EUR"
         },
         "status":{  
            "groupId":2,
            "groupName":"UNDELIVERABLE",
            "id":9,
            "name":"UNDELIVERABLE_NOT_DELIVERED",
            "description":"Message sent not delivered"
         },
         "error":{  
            "groupId":1,
            "groupName":"HANDSET_ERRORS",
            "id":6,
            "name":"EC_ABSENT_SUBSCRIBER_SM",
            "description":"Absent Subscriber",
            "permanent":false
         },
        "channel": "VIBER"
      },
      {  
         "messageId":"2315d543441c-335f-1d3d-142d31451ed25f35",
         "to":"41793026731",
         "sentAt":"2016-06-23T17:40:31.773+0100",
         "doneAt":"2016-06-23T17:40:31.787+0100",
         "messageCount":1,
         "mccMnc":"22801",
         "price":{  
            "pricePerMessage":0.01,
            "currency":"EUR"
         },
         "status":{  
            "groupId":3,
            "groupName":"DELIVERED",
            "id":5,
            "name":"DELIVERED_TO_HANDSET",
            "description":"Message delivered to handset"
         },
         "error":{  
            "groupId":0,
            "groupName":"OK",
            "id":0,
            "name":"NO_ERROR",
            "description":"No Error",
            "permanent":false
         },
        "channel": "SMS"
      }
   ]
}	
  

4. Receive incoming Viber message

Provided that your Viber service account is two-way, you can receive messages that users send to you. In order to start receiving messages, you should set up an MO configuration and an HTTP forward action, as described in Number configuration.

All messages will be forwarded in the following format:

{
    "results": [{
        "from": "385919998888",
        "to": "1234",
        "text": "Message text",
        "receivedAt": "2017-10-03T12:28:18.857+0000",
        "messageId": "5095978370419896438",
        "pairedMessageId": "1234567890123456",
        "callbackData": "calbackDataOnResourceAction",
        "price": {
            "pricePerMessage": 0.000000,
            "currency": "EUR"
        }
    }],
    "messageCount": 1,
    "pendingMessageCount": 0
}	
  

Additional Examples

Send Rich Viber message

If you would like to send Viber messages containing text, images and CTA buttons please check the example provided below. The example also shows how to configure the custom validity period for each communication channel.

Parameter Type Description
text string Text of the message that will be sent. Max 1000 characters.
imageURL string URL of the image sent in the Viber message.
buttonText string Viber button label. Max 20 characters.
buttonURL string Viber Button Call To Action. Should point to your landing page.
isPromotional boolean Indicates if content is of promotional character.
validityPeriod string The message validity period in minutes. When the period expires, the message will be automatically sent using the next OMNI step.

Rich Viber message

When sending a rich Viber message, imageURL, buttonText and buttonURL are all mandatory!

Info

Default validity period in OMNI for Viber messages is 24h and 48h for SMS messages.

Rich Viber message request example:

POST /omni/1/advanced HTTP/1.1
Host: api.infobip.com
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json

{ 
	"scenarioKey":"CC9F01A5DC7BEE2C2B829D203482A654",  
  "destinations":[ 
  	{ 
    	"to":{
        "phoneNumber": "41793026727"
      }
    }
  ],
 "viber": {
    "text": "This is the message which will be displayed in Viber Application. It can contain up to 1000 characters. ",
    "imageURL": "http://www.infobip.com/infobip-logo.png",
    "buttonText": "More information",
    "buttonURL": "http://www.infobip.com/",
    "isPromotional": true,
    "validityPeriod":1
  },
  "sms": {
    "text": "This text will be received via SMS if Viber message is not delivered.",
    "validityPeriod":1
  }
}	
  

The message received in the Viber application is shown below: