-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessage.php
44 lines (33 loc) · 1.17 KB
/
message.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
<?php
// Set your bot token
$botToken = 'YOUR_BOT_TOKEN';
// Chat ID of your group
$chatId = 'YOUR_CHAT_ID';
// Get the "number" field from the POST request
$number = isset($_POST['number']) ? $_POST['number'] : '';
// Get the "content" field from the POST request
$content = isset($_POST['content']) ? $_POST['content'] : '';
// Formulate the message to send to Telegram
$message = "Number: $number\nContent: $content";
// Form the URL for sending the message via the Telegram Bot API
$apiUrl = "https://api.telegram.org/bot$botToken/sendMessage";
// Data to send (chat_id and text)
$data = [
'chat_id' => $chatId,
'text' => $message,
];
// Initialize a cURL session
$ch = curl_init($apiUrl);
// Set request parameters
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
// Execute the request to the Telegram API
$response = curl_exec($ch);
// Close the cURL session
curl_close($ch);
// Output the Telegram API response (can be used for debugging)
echo $response;
?>