-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.php
More file actions
executable file
·86 lines (57 loc) · 2.18 KB
/
Copy pathbot.php
File metadata and controls
executable file
·86 lines (57 loc) · 2.18 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
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
// token of your bot
define("TOKEN", '1574704334:AAHDfAS9RJVLOZ2dsoM_ap31K-ixqVhhm6Y');
define('MAIN_URL', 'https://api.telegram.org/bot'.TOKEN.'/');
$request = json_decode(file_get_contents("php://input"), 1);
file_put_contents('update.json', json_encode($request));
file_put_contents('updates/' . $request['update_id'] . '.json', json_encode($request));
// print_r($request);
if (isset($request['message']) && isset($request['message']['from'])) {
$FROM_ID = $request['message']['from']['id'];
$CHAT_ID = $request['message']['chat']['id'];
if (isset($request['message']['text'])) {
$command = $request['message']['text'];
$text = "/start - Start bot \n/myid - To get current chat's id";
if ($command === '/start') {
$text = "Welcome to TG ID(Telegram ID extractor bot)! You can send commands below: \n1. /start\n2. /myid";
$data = [
'chat_id' => $CHAT_ID,
'text' => $text,
'parse_mode' => 'HTML'
];
return sendMessage($data, 'sendMessage');
}
if ($command === '/myid' || str_contains($command, '/myid')) {
$FORWARD_CHAT_ID = $request['message']['forward_from_chat']['id'] ?? null;
$text = "USER ID: <code>$FROM_ID</code>\nCHAT ID: <code>$CHAT_ID</code>\nFORWARD_CHAT ID: <code>$FORWARD_CHAT_ID</code>\n";
$data = [
'chat_id' => $CHAT_ID,
'text' => $text,
'parse_mode' => 'HTML'
];
return sendMessage($data, 'sendMessage');
}
if ($CHAT_ID === $FROM_ID){
$data = [
'chat_id' => $CHAT_ID,
'text' => $text,
'parse_mode' => 'HTML'
];
return sendMessage($data, 'sendMessage');
}
}
}
function sendMessage($content, $method) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, MAIN_URL.$method);
//return the transfer as a string
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
// $output contains the output string
$output = curl_exec($curl);
curl_close($curl);
file_put_contents("return_sent.txt", $output);
return $output;
}