-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
102 lines (84 loc) · 1.75 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require_once('lib/telegram.php');
define('PATH', realpath('./'));
$config = json_decode(file_get_contents(PATH."/config.json"), true);
// telegram instance
$telegram = new telegram($config['TELEGRAM_API_KEY']);
// get Uri
$uri = $_SERVER['REQUEST_URI'];
switch($uri)
{
case '/webHookUpdates':
{
$result = getRequest();
$telegram->parse($result);
break;
}
case '/getUpdates':
{
$offset = null;
$method = 'getUpdates';
$params = array
(
'offset' => $offset,
'limit' => null,
'timeout' => null
);
do
{
$result = $telegram->request($method, $params);
echo "<pre>";
print_r($result);
echo "</pre>";
// parse each comment
foreach($result['result'] as $r)
{
$params['offset'] = $r['update_id'];
$telegram->parse($r);
}
// to remove notifications, else always get the last
$params['offset']++;
}
while($result['ok']===true && count($result['result'])>0);
break;
}
case '/setWebhook':
{
$method = 'setWebhook';
$url = "https://".$config['APP_ID'].".herokuapp.com/webHookUpdates";
$params = array
(
'url' => $url
);
$result = $telegram->request($method, $params);
echo "<pre>";
print_r($result);
echo "</pre>";
break;
}
case '/unsetWebhook':
{
$method = 'setWebhook';
$params = array
(
'url' => null
);
$result = $telegram->request($method, $params);
echo "<pre>";
print_r($result);
echo "</pre>";
break;
}
default:
{
include('view/default.tpl');
}
}
function getRequest()
{
$postdata = file_get_contents("php://input");
$json = json_decode($postdata, true);
if($json)
return $json;
return $postdata;
}