Warning: Undefined array key 0 in /var/www/tgoop/function.php on line 65

Warning: Trying to access array offset on value of type null in /var/www/tgoop/function.php on line 65
57 - Telegram Web
Telegram Web
Channel created
Come testare un bot Telegram
Guida originale: https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates
1) Scaricate postman da https://www.getpostman.com/
2) Inserite lo stesso link che avete messo per settare il webhook, se non lo sapete usate questo link e cambiate <token> con il vostro https://api.telegram.org/bot<token>/getWebhookInfo e copiate quello che sta in url
3) Fate una nuova richiesta con POST invece di GET, cliccate su body e andate su raw
4) Ora dovete copiare questo e metterlo come body della richiesta
{
"update_id":10000,
"message":{
"date":1441645532,
"chat":{
"last_name":"Test Lastname",
"id":1111111,
"first_name":"Test",
"username":"Test"
},
"message_id":1365,
"from":{
"last_name":"Test Lastname",
"id":1111111,
"first_name":"Test",
"username":"Test"
},
"text":"/start"
}
}

5) Sostituite le varie info con le vostre per esempio chat id e text
6) Se siete su PHP potete per esempio mettere dei var_dump($nomevariabile); per verificare il funzionamento del bot facendovi stampare in pagina (che poi vedrete da postman) i valori che assumono le variaibli durante una richiesta fatta da telegram

Extra: Se volete fare il test di come si comporta il bot con messaggi modificati o altro trovate gli esempi qua https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates , altrimente potete mandare voi stessi un messaggio al vostro bot e salvarvi la richiesta in un file per poi copiarla e mandarla con postman
Per chi non fossero chiari alcuni passaggi questa foto offere un esempio di come andrebbe usato postman
Per più info: https://core.telegram.org/bots/webhooks#testing-your-bot-with-updates
Nuova versione di TuriBot https://github.com/davtur19/TuriBot
È stato aggiunto il file bot_debug.php per semplificare il debug e per capire quali sono le variabili utilizzate


Il bot genera automaticamente le variabili ricevute dal update, è consigliato leggere attentamente la documentazione e usare bot_debug.php per capire come funziona (è da sostituire in commands.php, da require_once(bot.php); a require_once(bot_debug.php); )

La generazione delle variabili per ogni update ricevuto neccessita di attenzione durante la scrittura del codice, siccome un eventuale variabile mancante genererà errori se non gestita correttamente siccome essa sarà NULL
2025/06/28 10:33:58
Back to Top
HTML Embed Code: