1
+ <?php
2
+
3
+ require_once 'menu.php ' ;
4
+
5
+ file_put_contents ("viber.json " ,file_get_contents ("php://input " ));
6
+ $ viber = file_get_contents ("viber.json " );
7
+ $ viber = JSON_decode ($ viber );
8
+
9
+ function send ($ message ){
10
+
11
+ $ curl = curl_init ();
12
+
13
+ curl_setopt_array ($ curl , array (
14
+ CURLOPT_URL => "https://chatapi.viber.com/pa/send_message " ,
15
+ CURLOPT_RETURNTRANSFER => true ,
16
+ CURLOPT_ENCODING => "" ,
17
+ CURLOPT_MAXREDIRS => 10 ,
18
+ CURLOPT_TIMEOUT => 30 ,
19
+ CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0 ,
20
+ CURLOPT_CUSTOMREQUEST => "POST " ,
21
+ CURLOPT_POSTFIELDS => JSON_encode ($ message ),
22
+ CURLOPT_HTTPHEADER => array (
23
+ "Cache-Control: no-cache " ,
24
+ "Content-Type: application/JSON " ,
25
+ "X-Viber-Auth-Token: VIBER-TOKEN "
26
+ ),
27
+ ));
28
+
29
+ $ response = curl_exec ($ curl );
30
+ $ err = curl_error ($ curl );
31
+
32
+
33
+ curl_close ($ curl );
34
+
35
+ if ($ err ) {
36
+ echo "cURL Error #: " . $ err ;
37
+ } else {
38
+ echo $ response ;
39
+ }
40
+
41
+ }
42
+
43
+ if ($ viber ->event == "conversation_started " ){
44
+ $ message ['receiver ' ] = $ viber ->user ->id ;
45
+ $ message ['type ' ] = "text " ;
46
+ $ message ['text ' ] = "Welcome messages " ;
47
+ $ message ['keyboard ' ] = [
48
+ "Type " => "keyboard " ,
49
+ "Revision " => 1 ,
50
+ "DefaultHeight " => false ,
51
+ "Buttons " => $ main_menu
52
+ ];
53
+ send ($ message );
54
+ exit ;
55
+ }
56
+
57
+ if ($ viber ->event == "message " ){
58
+
59
+ if ($ viber ->message ->text == "action1 " ){
60
+
61
+ $ message ['receiver ' ] = $ viber ->sender ->id ;
62
+ $ message ['type ' ] = "text " ;
63
+ $ message ['text ' ] = "Button 1 " ;
64
+ $ message ['keyboard ' ] = [
65
+ "Type " => "keyboard " ,
66
+ "Revision " => 1 ,
67
+ "DefaultHeight " => false ,
68
+ "Buttons " => $ main_menu
69
+
70
+ ];
71
+ send ($ message );
72
+ exit ;
73
+ }
74
+ }
0 commit comments