forked from mahdiMGF2/mirzabot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotapi.php
More file actions
152 lines (148 loc) · 5.76 KB
/
botapi.php
File metadata and controls
152 lines (148 loc) · 5.76 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require_once 'config.php';
function telegram($method, $datas = [],$token = null)
{
global $APIKEY;
$token = $token == null ? $APIKEY : $token;
$url = "https://api.telegram.org/bot" . $token . "/" . $method;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
$res = json_decode($res,true);
if(!$res['ok']){
if(json_encode($res) != null)error_log(json_encode($res));
}
if (curl_error($ch)) {
return curl_error($ch);
} else {
return $res;
}
}
error_log(json_encode(telegram('verifyUser',[
'user_id' => 1789174391,
'custom_description' => "تایید شده توسط fbi"
])));
function sendmessage($chat_id,$text,$keyboard,$parse_mode,$bot_token = null){
if(intval($chat_id) == 0)return ['ok' => false];
return telegram('sendmessage',[
'chat_id' => $chat_id,
'text' => $text,
'reply_markup' => $keyboard,
'parse_mode' => $parse_mode,
],$bot_token);
}
function sendDocument($chat_id, $documentPath, $caption) {
return telegram('sendDocument',[
'chat_id' => $chat_id,
'document' => new CURLFile($documentPath),
'caption' => $caption,
]);
}
function forwardMessage($chat_id,$message_id,$chat_id_user){
return telegram('forwardMessage',[
'from_chat_id'=> $chat_id,
'message_id'=> $message_id,
'chat_id'=> $chat_id_user,
]);
}
function sendphoto($chat_id,$photoid,$caption){
telegram('sendphoto',[
'chat_id' => $chat_id,
'photo'=> $photoid,
'caption'=> $caption,
]);
}
function sendvideo($chat_id,$videoid,$caption){
telegram('sendvideo',[
'chat_id' => $chat_id,
'video'=> $videoid,
'caption'=> $caption,
]);
}
function senddocumentsid($chat_id,$documentid,$caption){
telegram('sendDocument',[
'chat_id' => $chat_id,
'document'=> $documentid,
'caption'=> $caption,
]);
}
function Editmessagetext($chat_id, $message_id, $text, $keyboard,$parse_mode = 'HTML'){
return telegram('editmessagetext', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'text' => $text,
'reply_markup' => $keyboard,
'parse_mode' => $parse_mode,
]);
}
function deletemessage($chat_id, $message_id){
telegram('deletemessage', [
'chat_id' => $chat_id,
'message_id' => $message_id,
]);
}
function getFileddire($photoid){
return telegram('getFile', [
'file_id' => $photoid,
]);
}
function pinmessage($from_id,$message_id){
return telegram('pinChatMessage', [
'chat_id' => $from_id,
'message_id' => $message_id,
]);
}
function unpinmessage($from_id){
return telegram('unpinAllChatMessages', [
'chat_id' => $from_id,
]);
}
function answerInlineQuery($inline_query_id,$results){
return telegram('answerInlineQuery', [
"inline_query_id" => $inline_query_id,
"results" => json_encode($results)
]);
}
function convertPersianNumbersToEnglish($string) {
$persian_numbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$english_numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
return str_replace($persian_numbers, $english_numbers, $string);
}
// #-----------------------------#
$update = json_decode(file_get_contents("php://input"), true);
$from_id = $update['message']['from']['id'] ?? $update['callback_query']['from']['id'] ?? $update["inline_query"]['from']['id'] ?? 0;
$time_message = $update['message']['date'] ?? $update['callback_query']['date'] ?? $update["inline_query"]['date'] ?? 0;
$is_bot = $update['message']['from']['is_bot'] ?? false;
$chat_member = $update['chat_member'] ?? null;
$language_code = strtolower($update['message']['from']['language_code'] ?? $update['callback_query']['from']['language_code'] ?? "fa");
$Chat_type = $update["message"]["chat"]["type"] ?? $update['callback_query']['message']['chat']['type'] ?? '';
$text = $update["message"]["text"] ?? '';
if(isset($update['pre_checkout_query'])){
$Chat_type = "private";
$from_id = $update['pre_checkout_query']['from']['id'];
}
$text =convertPersianNumbersToEnglish($text);
$text_inline = $update["callback_query"]["message"]['text'] ?? '';
$message_id = $update["message"]["message_id"] ?? $update["callback_query"]["message"]["message_id"] ?? 0;
$time_message = $update["message"]["date"] ?? $update["callback_query"]["date"] ?? 0;
$photo = $update["message"]["photo"] ?? 0;
$document = $update["message"]["document"] ?? 0;
$fileid = $update["message"]["document"]["file_id"] ?? 0;
$photoid = $photo ? end($photo)["file_id"] : '';
$caption = $update["message"]["caption"] ?? '';
$video = $update["message"]["video"] ?? 0;
$videoid = $video ? $video["file_id"] : 0;
$forward_from_id = $update["message"]["reply_to_message"]["forward_from"]["id"] ?? 0;
$datain = $update["callback_query"]["data"] ?? '';
$last_name = $update['message']['from']['last_name'] ?? $update["callback_query"]["from"]["last_name"] ?? $update["inline_query"]['from']['last_name'] ?? '';
$first_name = $update['message']['from']['first_name'] ?? $update["callback_query"]["from"]["first_name"] ?? $update["inline_query"]['from']['first_name'] ?? '';
$username = $update['message']['from']['username'] ?? $update['callback_query']['from']['username'] ?? $update["callback_query"]["from"]["username"] ?? 'NOT_USERNAME';
$user_phone =$update["message"]["contact"]["phone_number"] ?? 0;
$contact_id = $update["message"]["contact"]["user_id"] ?? 0;
$callback_query_id = $update["callback_query"]["id"] ?? 0;
$inline_query_id = $update["inline_query"]["id"] ?? 0;
$query = $update["inline_query"]["query"] ?? 0;