Viber API sending messages

Hello. There was an idea to send messages to the public account on Viber via the site. On the official site, it is not really clear how to implement this. The account itself has already started. For example, a simple form: a field and a button. I want to send it there when you click on it. How do I do this? (Google didn't help)

<form>
  <input type="text">
  <input type="submit" value="Send to Viber">
</form>
Author: Abmin, 2017-04-23

1 answers

Hello. Here is an example of my code:

class Viber
{
    private $url_api = "https://chatapi.viber.com/pa/";

    private $token = "";

    public function message_post
    (
        $from,          // ID администратора Public Account.
        array $sender,  // Данные отправителя.
        $text           // Текст.
    )
    {
        $data['from']   = $from;
        $data['sender'] = $sender;
        $data['type']   = 'text';
        $data['text']   = $text;
        return $this->call_api('post', $data);
    }

    private function call_api($method, $data)
    {
        $url = $this->url_api.$method;

        $options = array(
            'http' => array(
                'header'  => "Content-type: application/x-www-form-urlencoded\r\nX-Viber-Auth-Token: ".$this->token."\r\n",
                'method'  => 'POST',
                'content' => json_encode($data)
            )
        );
        $context  = stream_context_create($options);
        $response = file_get_contents($url, false, $context);
        return json_decode($response);
    }
}
$Viber = new Viber();
$Viber->message_post(
    '01234567890A=',
    [
        'name' => 'Admin', // Имя отправителя. Максимум символов 28.
        'avatar' => 'http://avatar.example.com' // Ссылка на аватарку. Максимальный размер 100кб.
    ],
    'Test'
);

This class can be continued by adding functions to each method.

 7
Author: Ruslan Melnychenko, 2017-07-20 15:20:13