Perché il mio webhook non funziona? Non ottengo alcun dato dall'API del bot del telegramma. Ecco la spiegazione dettagliata del mio problema:Hai problemi con il webhook per l'API Bot di Telegram
ho ottenuto CERT dello SSL da StartSSL, funziona benissimo sul mio sito (secondo GeoCerts SSL checker), ma sembra ancora come il mio webhook al telegramma Bot API non funziona (nonostante dice che il webhook è stato impostato, non ho ricevuto alcun dato).
Sto facendo un webhook per il mio script sul mio sito in questa forma:
https://api.telegram.org/bot<token>/setWebhook?url=https://mywebsite.com/path/to/giveawaysbot.php
ottengo questo testo in risposta:
{"ok":true,"result":true,"description":"Webhook was set"}
Così deve essere di lavoro, ma in realtà doesn 't.
Ecco il mio codice script:
<?php
ini_set('error_reporting', E_ALL);
$botToken = "<token>";
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input');
$update = json_decode($update);
print_r($update); // this is made to check if i get any data or not
$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];
switch ($message) {
case "/test":
sendMessage($chatId,"test complete");
break;
case "/hi":
sendMessage($chatId,"hey there");
break;
default:
sendMessage($chatId,"nono i dont understand you");
}
function sendMessage ($chatId, $message) {
$url = $GLOBALS[website]."/sendMessage?chat_id=".$chatId."&text=".urlencode($message);
file_get_contents($url);
}
?>
Io in realtà non ricevono alcun dato a $ aggiornamento. Quindi il webhook non funziona. Perché?
Forse correlato a non ottenere alcun dato, dovresti fare 'json_decode ($ update, true)' per ottenere i dati come array, piuttosto che come 'stdClass'. – ixchi
ixchi, 'json_decode ($ update, true)' non ha modificato nulla, ancora non funziona: \ – markelov
Sei sicuro di ricevere effettivamente il webhook? Funziona correttamente per me. – ixchi