Telegram bot keeps spamming
I decided to use botman.io to start making my amazing, fantastic, never-before-seen Telegram bot. I chose it instead of the more popular telegram-bot-sdk by @irazasyed was because it was able to publish to different platforms if I ever choose to do so. Plus, using Laravel’s amazing middleware feature, I was able to hook up with wit.ai‘s API.
After getting all the SSL shenanigans settled, my bot was finally working, sort of. It kept spamming the same reply over and over. I had to do some digging.
https://api.telegram.org/bot/getWebhookInfo
returned the following-ish:
{
"ok": true,
"result": {
"url": "YOUR WEBHOOK CALLBACK URL",
"has_custom_certificate": false,
"pending_update_count": 10,
"last_error_date": 1498041234,
"last_error_message": "Wrong response from the webhook: 500 Internal Server Error",
"max_connections": 40
}
}
Ok, so pending_update_count
was stuck at 10. I was sure this was part of the reason it was spamming. By right it was supposed to go back to 0 as my backend cleared everything by replying or just ignoring. The other concerning thing was the "last_error_message": "Wrong response from the webhook: 500 Internal Server Error"
Long story short, the default handle() method in the botman controller was not returning a 200. So I just added a return response()->json(['message' =>'success']);
at the end and it worked.
public function handle(){
//the rest of the code
$bot->listen();
return response()->json(['message' =>'success']);
}