Viber
Viber Business Messages
Viber over API

Viber over API

Make sure that you are familiar with compliance and guidelines and details of message types before sending Viber messages.

Business Messages API

Use the Viber Business Messages API (opens in a new tab) to send conversational, promotional, and transactional messages to end users.

Follow the  Authentication guide (opens in a new tab) to secure your connection with Infobip.

Outbound messages

You can send the following types of messages over API (opens in a new tab):

  • Template
  • Text
  • Image
  • Video
  • File
  • Text + call-to-action button
  • Text + image
  • Text + video
  • Text + image + call-to-action button
  • Text + video + call-to-action button

Message template

Info

This message type is available only in Russia, Belarus, and Ukraine.

In Russia, Belarus, and Ukraine, any transactional (informative) messages that you send to end users must use registered templates that are approved by Viber. These templates must follow a predefined message structure and follow Viber guidelines.

If you send a transactional message that does not use a registered message template, you will be charged at the standard promotional message rate.

To send message templates, contact your dedicated Infobip Account Manager or contact our Sales team by using the Infobip Contact form (opens in a new tab).

If your business is based in any of the countries listed in this section, and you want to send transactional messages to customers who are outside these countries, you must use two accounts - one to communicate with customers within the above countries and the other for customers in all other countries.

Primary device

This section is applicable only for Text and Message templates.

An end user can have Viber installed on more than one device. Example: smartphone, tablet, and desktop. Either the smartphone or tablet is their primary device, and the others are secondary devices.

Any Viber message that you send to the end user will be delivered to all the devices. If you want to force the message to be delivered only to the end user’s primary device, set the toPrimaryDeviceOnly parameter to true in your API request.

Recommendations

  • To send formatted messages, add markdowns to the text string. Refer to the Outbound messages > Text > Text Formatting section. You cannot use text formatting in message templates.
  • To make sure that media URLs sent over the API are parsed and the content is displayed correctly, follow these guidelines:
    • Use only secured HTTPS links in the request.
    • Make sure that image URLs are not protected by captcha.
  • Use the following file formats for images: .jpg, .jpeg, .png, .bmp, .svg, .webp. For detailed specifications, refer to the Outbound messages > Image section.
  • Use the following file formats for video: .3gp, .m4v, .mov, .mp4. For detailed specifications, refer to the Outbound messages > Video section.
  • Use the following file formats for files: .csv, .doc, .docx, .dot, .dotx, .eps, .fods, .fodt, .info, .odf, .ods, .odt, .pdax, .pdf, .rtf, .txt, .xls, .xlsx, .xltx, .xps, xlsm. For detailed specifications, refer to the Outbound messages > File section.

Remember to add supplementary options to your send request in case you would like to benefit from our additional features.

Message options

Additional message options can be applied to your API request.

Bulk messages

You can send multiple text messages or message templates in a single API request.

Scheduling messages

Every communication can be scheduled. You can set a start date, time and time zone. This feature comes in handy when you don’t want to disturb your customers during the night, or you want to send messages only during a specific period for optimal conversion.

json
 
    "SendAt": 2015-07-07T17:00:00.000+01:00
 

An additional scheduling option is to set sending speed limit. For example, you can limit the sending speed when sending messages in bulk to deliver messages over a longer period of time. This feature can be beneficial when you expect recipients to react to your call-to-action embedded within the dispatched message. In that way you could avoid overwhelming your system or agents with an influx of responses from end customers and avoid operational strain. You can set the number (amount) of messages that will be sent periodically. Available time units are: minutes, hours, days.

json
 
    "sendingSpeedLimit":  {
        "amount": 30,
        "timeUnit": "HOUR"
        }
 

You can also set a specific message delivery window outside of which messages won’t be delivered. You can set start time (hour/minute), end time (hour/minute) and days of the week. Time is expressed in the UTC time zone.

json
 
    "deliveryTimeWindow": {
        "days": [
            "MONDAY",
            "TUESDAY",
            "WEDNESDAY",
            "THURSDAY",
            "FRIDAY",
            "SATURDAY",
            "SUNDAY"
            ],
        "from": {
            "hour": 6,
            "minute": 0
            },
        "to": {
            "hour": 15,
            "minute": 30
            }
        }
 
Validity period

There is a specific time period for messages during which the system will try to deliver them. For example, when you want to send a message to your audience and some users have their cell phones turned off, the system will retry delivery to these users until the validity period passes. The default and also the maximum validity period is 48 hours. It does not need to be set for each request. If you want to set a shorter period, you should define it under Validity period. Available time units are: seconds, minutes, hours. Default value is minutes.

json
 
    "validityPeriod":  {
        "amount": 30,
        "timeUnit": "MINUTES"
        }
 
SMS failover

Add a failover to SMS option in case your Viber message does not reach the end user within the defined period. You can also set a validity period for the SMS message.

json
 
    "smsFailover":  {
        "sender": "41793026726",
        "text": "Failover message text",
        "validityPeriod":  {
            "amount": 2,
            "timeUnit": "HOURS"
            }
        }
 
Platform

Viber APIs work seamlessly with CPaaS X. This gives you greater flexibility in managing your configurations and resources in whatever manner that suits your needs. For more information about CPaaS X, refer to our CPaaS X documentation.

json
 
    "platform": {
        "entityId": "priorityCustomer",
        "applicationId": "clientTestEnvironment"
        }
 
Webhooks

Use the webhooks > delivery > url parameter option if you want users to be able to set the URL where they want to receive API responses. Define the URL under the webhooks parameter of the API request.

json
 
    "webhooks": {
        "delivery": {
            "url": "https://www.example.com/viberbm"
            },
        }
 
URL shortening and tracking

You can shorten URLs and track the number of clicks for these URLs. You can enable URL shortening without enabling URL tracking. However, to enable URL tracking, you must enable URL shortening.

URL shortening and tracking is supported for the following message combinations:

  • Text only: URL in the text
  • Text + image: URL in the text
  • Text + video: URL in the text
  • Text + CTA button: URLs in the text and the CTA button
  • Image + text + CTA button: URLs in the text and the CTA button
  • Video + text + CTA button: URLs in the text and the CTA button
  • File: Media URL
URL shortening

Use URL shortening to reduce the length of the URLs that you share with end users. The URL is shortened when you add it to the message body.

You can use the following types of URL shortening:

TypeDescriptionExample
Default shortened URLShortens the entire URL.Message with original URL:
  • To find out more about business messages, go to
    https://www.infobip.com/docs/viber/business-messages
    .


Message with default shortened URL:
  • To find out more about business messages, go to
    https://rrj.nu/x5T3jd2Y
    .
Custom domain shortened URLShortens the URL in such a way that it retains the custom domain.

You can use custom domain URL shortening only for URLs that contain a custom domain (subdomain), for example:
www.dev.infobip.com
.

You cannot use custom domain URL shortening for URLs that contain a primary domain, for example
www.infobip.com
.
Message with original URL:
  • To find out more about business messages, go to
    https://www.dev.infobip.com/docs/api/channels/viber
    .


Message with default shortened URL:
  • To find out more about business messages, go to
    https://www.dev.infobip.com/x5T3jd2Y
    .
Protocol removalURLs that contain a primary domainRemoves the 'http' or 'https' prefix from the URL and shortens the URL.

If a URL contains a primary domain, the entire URL gets shortened.
Message with original URL:
  • To find out more about business messages, go to
    https://www.infobip.com/docs/viber/business-messages
    .


Message with protocol removed and URL shortened:
  • To find out more about business messages, go to
    rrj.nu/x5T3jd2Y
    .
URLs that contain a custom domain (subdomain)Removes the 'http' or 'https' prefix from the URL and shortens the URL.

If an URL contains a custom domain (subdomain), the URL is shortened in such a way that it retains the custom domain.
Message with original URL:
  • To find out more about business messages, go to
    https://www.dev.infobip.com/docs/api/channels/viber
    .


Message with protocol removed and URL shortened:
  • To find out more about business messages, go to
    www.dev.infobip.com/x5T3jd2Y
    .
URL tracking

You can track the number of clicks for a URL.

Specify the trackingUrl and set trackClicks to true.

json
 
    {
        ...
        "tracking": {
            "shortenUrl": true,
            "trackClicks": true,
            "trackingUrl": "https://webhook.site/077a5470-42f9-471f-a7f2-c67d5b *",
            "removeProtocol": true,
            "customDomain": "m.infobip.com"
        }
    }
 

When an end user clicks the URL in the message body, an event is returned to Infobip. This event is recorded in reports and notifications, and you will receive a click notification.

The structure of the data that is passed in the click notification is shown below.

json
 
    {
      "notificationType": "CLICKED",
      "recipient": "38591 ***",
      "url": "https://www.infobip.com",
      "sendDateTime": 1603440470723,
      "messageId": "303440456940035 *",
      "recipientInfo": {
        "deviceType": "Phone",
        "os": "Android 10",
        "deviceName": "Unknown"
      }
    }
 

Inbound messages

Incoming messages are forwarded to you in real-time when you use the API for two-way communication. The messages are forwarded to the endpoint that you provided when you set up your Viber account on Infobip solutions.

To enable messages from the Infobip web interface to be forwarded to an API endpoint, you must grant the relevant permission to the API endpoint. Use additional authorization headers to secure connections.

You can receive (opens in a new tab) the following types of messages from end users:

  • Text
  • Image
  • Video
  • File

Reports

After you successfully send a message, you can check the status of the sent message. The following reports are forwarded to a defined endpoint:

You can have delivery and seen reports forwarded to your URL in real time. To set this feature, provide the URL to your Infobip Account Manager.

(Optional) You can define the endpoint in the webhooks > delivery > url parameter of the API request of a message. If you do not define this endpoint, the reports are forwarded to the endpoint that is defined in the platform.

OMNI API

To send Viber messages over API, you need to set up your scenario. Refer to our API reference (opens in a new tab) to help you out.

Create scenario

The first step is to create an OMNI scenario (opens in a new tab). In the OMNI scenario configuration, define the OMNI steps which will be executed separately.

As the Viber sender ("channel": "VIBER" flow) use the one provided during the activation process—the phone number in the international format that was activated for you (for example, 385981234567). You need to have a secure connection. Either use Base64 hash combination of Infobip credentials, API keys (recommended), or tokens. Refer to API Authentication for instructions.

Request example

json
 
    {
      "from": "InfoSMS",
      "channel": "SMS"
    },
    {
      "from": "3045",
      "channel": "VIBER"
    }
 

Create the scenario during the initial phase only. You are not required to repeat this step every time you want to send a message. You create a scenario when adding new channels in a failover scenario or when you want to change the sender.

To use this as a default scenario, set the default value to true. From this point on, scenarioKey is not a mandatory parameter when sending the message.

json
 
    {
      "from": "InfoSMS",
      "channel": "SMS"
    },
    {
      "from": "3045",
      "channel": "VIBER"
    }
 

Store the key parameter because it will be used when sending the message.

Default scenario

The first scenario you create for the account will be used as the default scenario. It will be used until you set another scenario to be the default one. To change this, set the default value to true.

Response format

If successful, the response header HTTP status code will be 201 Created and the scenario will be created.

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

If you use this method too often in a short period of time, you will get the status code 429 Too Many Requests. This prevents misusing the method to create a lot of unnecessary scenarios.

Once you create your scenario, you can always reference it via the scenario key and reuse it as many times as you like for sending OMNI messages. There is no need to create a new scenario for each OMNI message.

Send OMNI messages

Once you have created your OMNI scenario (identified by the key parameter) as described in the Create scenario section, you are ready to send your OMNI messages through defined Viber and SMS communication channels.

  1. Send a Viber message to the defined phoneNumber.
  2. 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 is sent via SMS.

For sending OMNI messages, you can use the advanced API method. Refer to our API documentation (opens in a new tab).

The parameters that should be set are the scenarioKey, phoneNumber and specific text for each communication channel.

The default validity period in OMNI is 48 h for both Viber and SMS messages.

Response example

json
 
    {
          "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"
    }
 

Send rich messages over Viber

Here’s how to send Viber messages containing text, images, and CTA buttons. You can configure the custom validity period for each communication channel.

Any combination of text, image or buttons is allowed. The buttonUrl and buttonText are mandatory.

json
 
    {
           "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
     }
 

Supported image formats: .jpeg, .jpg, .png. Emojis can be sent over the Viber channel via API as well and enhance the end-user experience.

Failover to SMS

Add a failover to SMS option in case your Viber message does not reach the end user within the defined period. The failover option is applicable for all message types.

Primary device

This section is applicable only for text and message templates.

An end user can have Viber installed on more than one device. Example: smartphone, tablet, and desktop. Either the smartphone or tablet is their primary device, and the others are secondary devices.

Any Viber message that you send to the end user will be delivered to all the devices. If you want to force the message to be delivered only to the end user’s primary device, set the toPrimaryDeviceOnly parameter to true in your API request.

Recommendations

  • To send formatted messages, add markdowns to the text string. Refer to the Outbound messages > Text > Text formatting section. You cannot use text formatting in message templates.
  • To make sure that media URLs sent over the API are parsed and the content is displayed correctly, follow these guidelines:
    • Use only secured HTTPS links in the request.
    • Make sure that image URLs are not protected by captcha.
  • Use the following file formats for images: .jpg, .jpeg, .png, .bmp, .svg, .webp. For detailed specifications, refer to the Outbound messages > Image section.
  • Use the following file formats for video: .3gp, .m4v, .mov, .mp4. For detailed specifications, refer to the Outbound messages > Video section.
  • Use the following file formats for files: .csv, .doc, .docx, .dot, .dotx, .eps, .fods, .fodt, .info, .odf, .ods, .odt, .pdax, .pdf, .rtf, .txt, .xls, .xlsx, .xltx, .xps, .xlsm. For detailed specifications, refer to the Outbound messages > File section.

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.

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

Response

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"
          }
       ]
    }
 

For a complete list of all API statuses and error codes, refer to the Response status and error codes article.

Note

You can also have delivery reports forwarded to your URL in real time. In that case, provide the URL to your dedicated Account Manager and they will set it up for you.

Real-time delivery reports

Delivery reports that are forwarded to your URL in real-time have a different format than the one that is retrieved using the OMNI reports method.

json
 
    {
        "results": [{
            "bulkId": "",
            "price": {
                "pricePerMessage": 0,
                "currency": "EUR"
            },
            "status": {
                "id": 5,
                "groupId": 3,
                "groupName": "DELIVERED",
                "name": "DELIVERED_TO_HANDSET",
                "description": "Message delivered to handset"
            },
            "error": {
                "id": 0,
                "name": "NO_ERROR",
                "description": "No Error",
                "groupId": 0,
                "groupName": "OK",
                "permanent": false
            },
            "messageId": "fb469d73-d362-463f-b30f-1e959b53badc",
            "doneAt": "2019-04-09T16:01:56.494-0300",
            "messageCount": 1,
            "sentAt": "2019-04-09T16:00:58.647-0300",
            "to": "41793026731",
            "channel": "VIBER"
        }]
    }
 

Need assistance

Explore Infobip Tutorials

Encountering issues

Contact our support

What's new? Check out

Release Notes

Unsure about a term? See

Glossary

Research panel

Help shape the future of our products
Service Terms & ConditionsPrivacy policyTerms of use