Repository navigation
Expand file tree
/
Copy pathbot.php
More file actions
65 lines (51 loc) · 1.69 KB
/
Copy pathbot.php
File metadata and controls
65 lines (51 loc) · 1.69 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
<?php
// Basic error handling
error_reporting(E_ALL);
ini_set("log_errors", 1);
ini_set("error_log", __DIR__ . "/logs/php_error.log");
// Simple logging function
function logDebug($message) {
$log = date("Y-m-d H:i:s") . " " . $message . "\n";
file_put_contents(__DIR__ . "/logs/bot.log", $log, FILE_APPEND);
}
try {
// Log request start
logDebug("=== New Request ===");
// Log request method
logDebug("Method: " . $_SERVER["REQUEST_METHOD"]);
// Get raw input
$input = file_get_contents("php://input");
logDebug("Raw input: " . $input);
// Send 200 OK response
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
if (!empty($input)) {
$update = json_decode($input, true);
if ($update === null) {
logDebug("JSON decode error: " . json_last_error_msg());
throw new Exception("Invalid JSON");
}
logDebug("Decoded update: " . print_r($update, true));
if (isset($update["message"]["text"])) {
$text = $update["message"]["text"];
logDebug("Received message: " . $text);
if ($text === "/run") {
logDebug("Run command received");
}
}
}
// Send success response
echo json_encode([
"ok" => true,
"message" => "Webhook received"
]);
} catch (Exception $e) {
logDebug("Error: " . $e->getMessage());
// Even on error, send 200 OK to Telegram
header("HTTP/1.1 200 OK");
header("Content-Type: application/json");
echo json_encode([
"ok" => false,
"error" => $e->getMessage()
]);
}