-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.php
More file actions
35 lines (30 loc) · 1.09 KB
/
bot.php
File metadata and controls
35 lines (30 loc) · 1.09 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
<?php
$update = json_decode(file_get_contents("php://input"));
if (isset($update->message)) {
$message = $update->message;
$text = $message->text;
$from_id = $message->from->id;
$chat_id = $message->chat->id;
}
const API_KEY = ''; # your bot token
function TelegramRequest(string $method, array $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . API_KEY . '/' . $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
return json_decode($response);
}
if ($text == '/start') {
TelegramRequest('sendMessage', [
'chat_id' => $from_id,
'text' => 'Hello, welcome to my bot! Send me a message to get started.'
]);
}