-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTelegramBot.php
81 lines (68 loc) · 2.04 KB
/
TelegramBot.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
<?php
class TelegramBot{
#You can use this token to access HTTP API:
private $TokenAPI;
function __construct($TokenAPI){
$this->TokenApi=$TokenAPI;
}
#Send the request
private function SendApiBot($Url,$Data = null)
{
$resource = curl_init($Url);
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_TIMEOUT => 0,
CURLOPT_CONNECTTIMEOUT => 600,
CURLOPT_SSL_VERIFYPEER => false );
//SendApiBot ....
if (!is_null($Data)) {
$options[CURLOPT_POSTFIELDS] = http_build_query($Data);
}
curl_setopt_array($resource, $options);
$GetBody = curl_exec($resource);
curl_close($resource);
$ResultJson = json_decode($GetBody);
return $ResultJson;
}
#Task demand
private function SendQueries($TheTask, $data=NULL){
$TokenAPI = $this->TokenApi;
$Consent = $this->SendApiBot("https://api.telegram.org/bot$TokenAPI/".$TheTask, $data);
return $Consent;
}
//Now Status bots
public function Status(){
$Consent = $this->SendQueries("getme");
return($Consent);
}
public function GetUpdates(){
$Consent = $this->SendQueries("getUpdates");
return($Consent);
}
public function SendMessage($ChatId, $TextMsg, $ReplyIDm = null, $ReplyMarkup = null){
$data = array();
$data["chat_id"]= $ChatId;
$data["text"]= $TextMsg;
$data["disable_web_page_preview"] = "true";
if(isset($ReplyIDm))
$data["reply_to_message_id"] = $ReplyIDm;
if(isset($ReplyMarkup))
$data["reply_markup"] = $ReplyMarkup;
$Consent = $this->SendQueries("sendMessage", $data);
return $Consent;
}
public function GetUserProfilePhoto($UserID, $OffSet = null, $Limit = null){
$data = array();
$data["user_id"] = $UserID;
if(isset($OffSet)){
$data["offset"] = $OffSet;
}
if(isset($Limit)){
$data["limit"] = $Limit;
}
$Consent = $this->SendQueries("getUserProfilePhotos", $data);
return $Consent;
}
}
?>