forked from mahdiMGF2/botmirzapanel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
botapi.php
80 lines (78 loc) · 2.79 KB
/
botapi.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
<?php
function telegram($method, $datas = [])
{
global $APIKEY;
$url = "https://api.telegram.org/bot" . $APIKEY . "/" . $method;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
if (curl_error($ch)) {
var_dump(curl_error($ch));
} else {
return json_decode($res);
}
}
function sendmessage($chat_id,$text,$keyboard,$parse_mode){
telegram('sendmessage',[
'chat_id' => $chat_id,
'text' => $text,
'reply_markup' => $keyboard,
'parse_mode' => $parse_mode,
]);
}
function forwardMessage($chat_id,$message_id,$chat_id_user){
telegram('forwardMessage',[
'from_chat_id'=> $chat_id,
'message_id'=> $message_id,
'chat_id'=> $chat_id_user,
]);
}
function sendphoto($chat_id,$photoid,$caption,$parse_mode = "HTML"){
telegram('sendphoto',[
'chat_id' => $chat_id,
'photo'=> $photoid,
'caption'=> $caption,
'parse_mode' => $parse_mode,
]);
}
function sendvideo($chat_id,$videoid,$caption){
telegram('sendvideo',[
'chat_id' => $chat_id,
'video'=> $videoid,
'caption'=> $caption,
]);
}
function Editmessagetext($chat_id, $message_id, $text, $keyboard){
telegram('editmessagetext', [
'chat_id' => $chat_id,
'message_id' => $message_id,
'text' => $text,
'reply_markup' => $keyboard
]);
}
function deletemessage($chat_id, $message_id){
telegram('deletemessage', [
'chat_id' => $chat_id,
'message_id' => $message_id,
]);
}
#-----------------------------#
$update = json_decode(file_get_contents("php://input"), true);
$from_id = $update['message']['from']['id'] ?? $update['callback_query']['from']['id'] ?? 0;
$Chat_type = $update["message"]["chat"]["type"] ?? '';
$text = $update["message"]["text"] ?? $update["callback_query"]["message"]["text"] ?? '';
$message_id = $update["message"]["message_id"] ?? $update["callback_query"]["message"]["message_id"] ?? 0;
$photo = $update["message"]["photo"] ?? 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"] ?? '';
$username = $update['message']['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;
$first_name = $update['message']['from']['first_name'] ?? '';
$callback_query_id = $update["callback_query"]["id"] ?? 0;