Skip to content

Post guide

General syntax

The webhook address of 🤖 pRobot is ***.

🤖 pRobot only accepts POST request method.

Required POST data

  • Header:

Content-Type: application/json

  • Body/Post parameters (JSON):
{

  "probottoken": "string",
  "command": "string",
  "viberuserlist": ["array"],
  "mixmessage": "string" or {"keys":"values"}  

}

Return data

string: OK or other error text.

Descriptions

By default, a Viber bot can send messages to its subscribed Viber users only. So the bot can not send messages to an arbitrary Viber user ID that hasn't subscribed to it yet.

  • probottoken: your given 🤖pRobot password.

  • command : The command here can be:

    1. sendtoall: Broadcast messages to all subscribed Viber users. It will ignore viberuserlist list.

    2. sendtouserlist: Send messages to a selected Viber user list or one Viber user. It requires subscribed Viber user ID list in the viberuserlist parameter below.

  • viberuserlist: this is an array (or list in Python) of Viber user IDs. When the command is sendtouserlist, viberuserlist must have a valid list of Viber user IDs, like ["viberID1", "viberID1"]. A user can get his or her Viber ID via this command showmyid.

Note: For both of the above commands, the maximum list length is 300 receivers in a single request. There is a rate limit of 500 requests in a 10 seconds window. -- Ref

So one needs to divide the user list into smaller chunks for each request if there are more than 300 subscribers.

  • mixmessage: it can be a string or a complicated dictionary object (or dict in Python).

    1. string: like "hello world", if you just want to send a simple text message.

    2. object: like {"text": "Hello world", "type":"picture", "etc": "etc" }. Use this if you want to send rich media messages or carousel content messages etc. Parameter values in this object will overwrite the simple JSON post data of pRobot, except the receiver. Note: For available parameters, check this API.

pRobot uses broadcast_message API to send messages, even to one user. So it will auto-handle the receiver parameter, you do not need to provide this value in the object. broadcast_message uses similar parameters with send_message.

Example code snippets

Python

import requests

viberBotURL = '*** edit this'


# Example with sendtouserlist command, sendtoall command is also the same

my_probot_token = "** edit this*"
my_viberid_list = ["userID1", "userID2"]

addvancedText = {
    "probottoken": my_probot_token,
    "command": "sendtouserlist",
    "viberuserlist": my_viberid_list,

    "mixmessage": {
        # Adapted from https://developers.viber.com/docs/api/rest-bot-api/#send-message

        "min_api_version": 1,
        "sender": {
            "name": "From Webpost",
            "avatar": "https://probot.pages.dev/assets"
        },
        "tracking_data": "tracking data",
        "type": "picture",
        "text": "Text message here",
        "media": "https://probot.pages.dev/assets/viberbot_subscribe.png",
        # "thumbnail": "http://www.images.com/thumb.jpg"
    }
}


res = requests.post(viberBotURL, json=addvancedText)

print(res.text)

PHP

<?php
$pRobotUrl = '***';

$sendAll = [
    "probottoken" => "***",
    "command" => "sendtoall",
    "viberuserlist" => [],

    "mixmessage" => "Test: text to send all from php"
];

$sendToSomeSpecialUsers = [
    "probottoken" => "***",
    "command" => "sendtouserlist",
    "viberuserlist" =>["userID1", "UserID2"],

    "mixmessage" => [
        // Adapted from https://developers.viber.com/docs/api/rest-bot-api/#send-message

        "min_api_version" => 1,
        "sender" => [
            "name" => "John McClane",
            "avatar" => "http://avatar.example.com"
        ],
        "tracking_data" => "tracking data",
        "type" => "picture",
        "text" => "Text message here",
        "media" => "http://www.images.com/img.jpg",
        "thumbnail" => "http://www.images.com/thumb.jpg"
    ]
];


// $postData = json_encode($sendAll);
$postData = json_encode($sendToSomeSpecialUsers);


// https://stackoverflow.com/a/16920588
// Setup cURL
$ch = curl_init($pRobotUrl);
curl_setopt_array($ch, array(
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => $postData
));

// Send the request
$response = curl_exec($ch);

// Check for errors
if($response === FALSE){
    die(curl_error($ch));
}

// Decode the response
//$responseData = json_decode($response, TRUE);

// Close the cURL handler
curl_close($ch);

// Print the date from the response
// echo $responseData;
echo $response;