-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviber.php
74 lines (59 loc) · 1.53 KB
/
viber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once 'menu.php';
file_put_contents("viber.json",file_get_contents("php://input"));
$viber = file_get_contents("viber.json");
$viber = JSON_decode($viber);
function send($message){
$curl = curl_init();
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_2_0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => JSON_encode($message),
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/JSON",
"X-Viber-Auth-Token: VIBER-TOKEN"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
if ($viber->event == "conversation_started"){
$message['receiver'] = $viber->user->id;
$message['type'] = "text";
$message['text'] = "Welcome messages";
$message['keyboard'] = [
"Type" => "keyboard",
"Revision" => 1,
"DefaultHeight" => false,
"Buttons" => $main_menu
];
send($message);
exit;
}
if ($viber->event == "message"){
if ($viber->message->text == "action1"){
$message['receiver'] = $viber->sender->id;
$message['type'] = "text";
$message['text'] = "Button 1";
$message['keyboard'] = [
"Type" => "keyboard",
"Revision" => 1,
"DefaultHeight" => false,
"Buttons" => $main_menu
];
send($message);
exit;
}
}