-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_webhook.php
More file actions
81 lines (72 loc) · 2.15 KB
/
Copy pathsetup_webhook.php
File metadata and controls
81 lines (72 loc) · 2.15 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
<?php
require_once __DIR__ . '/config.php';
function mentorq_set_webhook()
{
$url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/setWebhook';
$data = array(
'url' => WEBHOOK_URL,
'max_connections' => 40,
'allowed_updates' => json_encode(array('message', 'callback_query')),
);
$opts = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
'timeout' => 30,
),
);
$ctx = stream_context_create($opts);
$raw = @file_get_contents($url, false, $ctx);
if ($raw === false) {
echo "Error calling Telegram API\n";
return;
}
$res = json_decode($raw, true);
if (!empty($res['ok'])) {
echo "Webhook set\n";
echo "URL: " . WEBHOOK_URL . "\n";
} else {
echo "Failed to set webhook\n";
if (isset($res['description'])) {
echo $res['description'] . "\n";
}
}
}
function mentorq_delete_webhook()
{
$url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/deleteWebhook';
$raw = @file_get_contents($url);
$res = json_decode($raw, true);
if (!empty($res['ok'])) {
echo "Webhook deleted\n";
} else {
echo "Failed to delete webhook\n";
}
}
function mentorq_check_webhook()
{
$url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/getWebhookInfo';
$raw = @file_get_contents($url);
$res = json_decode($raw, true);
if (!empty($res['ok'])) {
$info = $res['result'];
echo "Current webhook:\n";
echo 'URL: ' . ($info['url'] ?? '') . "\n";
echo 'Pending updates: ' . ($info['pending_update_count'] ?? 0) . "\n";
echo 'Last error message: ' . ($info['last_error_message'] ?? 'none') . "\n";
} else {
echo "Failed to get webhook info\n";
}
}
echo "MentorQ webhook setup\n";
echo "======================\n\n";
echo "1) Current webhook info:\n";
mentorq_check_webhook();
echo "\n";
echo "2) Setting webhook:\n";
mentorq_set_webhook();
echo "\n";
echo "3) Final webhook info:\n";
mentorq_check_webhook();
echo "\n";