-
Notifications
You must be signed in to change notification settings - Fork 0
/
TinyTelegramBot.php
98 lines (98 loc) · 2.65 KB
/
TinyTelegramBot.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
<?php
// Max Base
// https://github.com/BaseMax/TinyTelegramBotPHP
include "NetPHP.php";
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
if(!function_exists("startsWith")) {
function startsWith($string, $startString) {
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
}
$token="****:***-*******";
$uri="https://api.telegram.org/bot".$token."/";
$fileuri="https://api.telegram.org/file/bot".$token."/";
$input=file_get_contents("php://input");
$json=json_decode($input, true);
// if($input == "") {
// exit("Error!\n");
// }
function sendMessage($chatID, $message, $replyID=null, $html=false, $preview=false, $keyboard=[]) {
global $token, $uri;
$param=[];
$param["text"]=$message;
$param["chat_id"]=$chatID;
if($replyID != null) {
$param["reply_to_message_id"]=$replyID;
}
if($html == true) {
$param["parse_mode"]="HTML";
}
if($keyboard != []) {
$keyboard=json_encode([
'keyboard'=>$keyboard,
'resize_keyboard'=>true,
'one_time_keyboard'=>true,
'selective'=>true,
]);
$param['reply_markup']=$keyboard;
// $param["reply_markup"]=$keyboard;
$param["resize_keyboard"]=true;
$param["one_time_keyboard"]=true;
}
$param["disable_web_page_preview"]=$preview;
return post($uri."sendMessage", $param)[0];
}
function getFile($fileID) {
global $token, $uri;
$param=[];
$param["file_id"]=$fileID;
return post($uri."getFile", $param)[0];
}
function sendPhoto($chatID, $photo, $caption="", $replyID=null, $keyboard=[]) {
global $token, $uri;
$param=[];
$param["chat_id"]=$chatID;
$param["photo"]=new CURLFile($photo);
$param["caption"]=$caption;
if($replyID != null) {
$param["reply_to_message_id"]=$replyID;
}
if($keyboard != []) {
$keyboard=json_encode([
'keyboard'=>$keyboard,
'resize_keyboard'=>true,
'one_time_keyboard'=>true,
'selective'=>true,
]);
$param['reply_markup']=$keyboard;
$param["resize_keyboard"]=true;
$param["one_time_keyboard"]=true;
}
return post($uri."sendPhoto", $param)[0];
}
function sendDocument($chatID, $document, $caption="", $replyID=null, $keyboard=[]) {
global $token, $uri;
$param=[];
$param["chat_id"]=$chatID;
$param["document"]=new CURLFile($document);
$param["caption"]=$caption;
if($replyID != null) {
$param["reply_to_message_id"]=$replyID;
}
if($keyboard != []) {
$keyboard=json_encode([
'keyboard'=>$keyboard,
'resize_keyboard'=>true,
'one_time_keyboard'=>true,
'selective'=>true,
]);
$param['reply_markup']=$keyboard;
$param["resize_keyboard"]=true;
$param["one_time_keyboard"]=true;
}
return post($uri."sendDocument", $param)[0];
}
/////////////////////////////////////////////////////