/
api.php
109 lines (90 loc) · 2.66 KB
/
api.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
103
104
105
106
107
108
109
<?php
// API
function sendMsg($m, $is_reply = true){
sendChatAction("sendMsg");
$cid = $GLOBALS['chatID'];
$mid = $GLOBALS['messageID'];
$m = urlencode($m);
$url = "https://api.telegram.org/bot" . TOKEN . "/sendMessage?chat_id=" . $cid;
$url .= "&disable_web_page_preview=true";
if($is_reply){
$url .= "&reply_to_message_id=" . $mid;
}
$url .= "&text=" . $m;
$ch = curl_init($url);
curl_exec($ch);
$time = date('Y-m-d H:i:s', time());
$log = curl_getinfo($ch);
logging("request", "<" . $time . ">" . PHP_EOL);
logging("request", $log);
curl_close($ch);
}
function sendSticker($f, $is_reply = true){
sendChatAction("sendSticker");
$cid = $GLOBALS['chatID'];
$mid = $GLOBALS['messageID'];
$url = "https://api.telegram.org/bot" . TOKEN . "/sendSticker?chat_id=" . $cid;
if($is_reply){
$url .= "&reply_to_message_id=" . $mid;
}
$url .= "&sticker=" . $f;
$ch = curl_init($url);
curl_exec($ch);
$time = date('Y-m-d H:i:s', time());
$log = curl_getinfo($ch);
logging("request", "<" . $time . ">" . PHP_EOL);
logging("request", $log);
curl_close($ch);
}
function sendVoice($v, $is_reply = true){
sendChatAction("sendVoice");
$cid = $GLOBALS['chatID'];
$mid = $GLOBALS['messageID'];
$url = "https://api.telegram.org/bot" . TOKEN . "/sendVoice?chat_id=" . $cid;
if($is_reply){
$url .= "&reply_to_message_id=" . $mid;
}
$url .= "&voice=" . $v;
$ch = curl_init($url);
curl_exec($ch);
$time = date('Y-m-d H:i:s', time());
$log = curl_getinfo($ch);
logging("request", "<" . $time . ">" . PHP_EOL);
logging("request", $log);
curl_close($ch);
}
function sendChatAction($a){
$cid = $GLOBALS['chatID'];
$action = "";
switch ($a) {
case "sendMsg":
case "sendSticker":
$action = "typing";
break;
case "sendPhoto":
$action = "upload_photo";
break;
case "sendVideo":
$action = "upload_video";
break;
case "sendAudio":
case "sendVoice":
$action = "upload_audio";
break;
case "sendDoc":
$action = "upload_document";
break;
default:
$action = "typing";
break;
}
$url = "https://api.telegram.org/bot" . TOKEN . "/sendChatAction?chat_id=" . $cid;
$url .= "&action=" . $action;
$ch = curl_init($url);
curl_exec($ch);
$time = date('Y-m-d H:i:s', time());
$log = curl_getinfo($ch);
logging("request", "<" . $time . ">" . PHP_EOL);
logging("request", $log);
curl_close($ch);
}