-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_webhook.php
45 lines (35 loc) · 1.23 KB
/
set_webhook.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
45
<?php
include "config.php";
function setWebhook($url) {
$api_url = 'https://api.telegram.org/bot' . BOT_TOKEN . '/setWebhook';
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['url' => $url]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
return [
'ok' => false,
'description' => 'Curl error: ' . curl_error($ch)
];
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($result === null) {
return [
'ok' => false,
'description' => 'Invalid JSON response. HTTP code: ' . $http_code . '. Response: ' . $response
];
}
return $result;
}
$result = setWebhook(WEBHOOK_URL);
if ($result['ok']) {
echo "Webhook impostato con successo a " . WEBHOOK_URL;
} else {
echo "Errore nell'impostazione del webhook: " . $result['description'] . "\n";
echo "API URL usato: https://api.telegram.org/bot" . substr(BOT_TOKEN, 0, 5) . "...{RESTO_DEL_TOKEN}/setWebhook\n";
echo "Webhook URL: " . WEBHOOK_URL . "\n";
}
?>