<?php
//$receiverID - это кому отправить клавиатуру ...
# Примеры:
https://viber.github.io/docs/tools/keyboard-examples/
function send_klava($receiverID){
$curl = curl_init();
$json_data = '{
"receiver":"'.$receiverID.'",
"type":"text",
"text":"Hello world",
"keyboard":{
"Type":"keyboard",
"DefaultHeight":false,
"Buttons":[
{
"ActionType":"reply",
"ActionBody":"reply to me",
"Text":"Key text",
"TextSize":"regular"
}
]
}
}
';
$data = json_decode($json_data); // Преобразовываем в json код
curl_setopt_array($curl, array(
CURLOPT_URL => "
https://chatapi.viber.com/pa/send_message",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($data) , // отправка кода
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/JSON",
"X-Viber-Auth-Token: 0000c419ece7d075-4c64680ae0e809a8-ab8000624a14e0000"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
//Отправка клавы пользователю с id
send_klava('yI8UmH+jb9ZAzyYtU/mYwg==');
?>