The Offset Infinite Loop
Hi My bot has been stuck in infinite loop and it's not responding anymore, what's problem? here is the stack trace:
Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"Error: Bot was kicked from a chat"}
at /Users/vahid/Desktop/node_modules/node-telegram-bot-api/src/telegram.js:72:15
at tryCatcher (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:367:17)
Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"Error: Bot was kicked from a chat"}
at /Users/vahid/Desktop/node_modules/node-telegram-bot-api/src/telegram.js:72:15
at tryCatcher (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:503:31)
at Promise._settlePromiseAt (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:577:18)
at Promise._settlePromises (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:693:14)
at Async._drainQueue (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/vahid/Desktop/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:15:14)
at processImmediate [as _immediateCallback] (timers.js:367:17)
Any luck fixing this?
I have the same problem
Actually i've changed my method from polling to telegram webhooks, and my problems are gone now.
I have the same issue as well:
Using version 0.19.0
Its just a test a bot and the person who the message only sent the message once.
My bot is constantly just getting the same message over and over
{ message_id: 506, from: { id: someId, first_name: 'name' }, chat: { id: -GroupId, title: 'Group Name', type: 'group' }, date: 1452347899, text: '/next' }
Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"[Error]: Forbidden: bot was kicked from the group chat"} at /Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:121:15 at tryCatcher (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23) at Promise._settlePromiseFromHandler (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:507:31) at Promise._settlePromiseAt (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:581:18) at Promise._settlePromises (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:697:14) at Async._drainQueue (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16) at Async._drainQueues (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues as _onImmediate at processImmediate as _immediateCallback Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"[Error]: Forbidden: bot was kicked from the group chat"} at /Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:121:15 at tryCatcher (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23) at Promise._settlePromiseFromHandler (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:507:31) at Promise._settlePromiseAt (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:581:18) at Promise._settlePromises (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:697:14) at Async._drainQueue (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16) at Async._drainQueues (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues as _onImmediate at processImmediate as _immediateCallback
Seems you are trying to send a message to non exists peer or haven't talk to you before El 9/1/2016 18:20, "Brian Lough" [email protected] escribió:
I have the same issue as well:
My bot is constantly just getting the same message back:
Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"[Error]: Forbidden: bot was kicked from the group chat"} at /Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:121:15 at tryCatcher (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23) at Promise._settlePromiseFromHandler (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:507:31) at Promise._settlePromiseAt (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:581:18) at Promise._settlePromises (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:697:14) at Async._drainQueue (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16) at Async._drainQueues (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues as _onImmediate http:///Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:15:14 at processImmediate as _immediateCallback Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"[Error]: Forbidden: bot was kicked from the group chat"} at /Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/src/telegram.js:121:15 at tryCatcher (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/util.js:26:23) at Promise._settlePromiseFromHandler (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:507:31) at Promise._settlePromiseAt (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:581:18) at Promise._settlePromises (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/promise.js:697:14) at Async._drainQueue (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:123:16) at Async._drainQueues (/Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues as _onImmediate http:///Users/brian/my-reaction-when-telegram-bot/node_modules/node-telegram-bot-api/node_modules/bluebird/js/main/async.js:15:14 at processImmediate as _immediateCallback
— Reply to this email directly or view it on GitHub https://github.com/yagop/node-telegram-bot-api/issues/36#issuecomment-170261100 .
Sorry your right the stack is due to that, but the reason the issue is appearing is that the bot is constantly receiving the same message over and over again, even thought this user only sent "/next" once, when I start up my bot all I receive is that message, same message_id everytime as well
{ message_id: 506, from: { id: someId, first_name: 'name' }, chat: { id: -GroupId, title: 'Group Name', type: 'group' }, date: 1452347899, text: '/next' }
Does that make more sense?
The error causes it won't be marked as read
@witnessmenow IMPOV, using polling is very unreliable and not worth it. You can very easily switch to webhooks. -- see my blog post: http://mvalipour.github.io/node.js/2015/12/06/telegram-bot-webhook-existing-express
@yagop Is there anyway to move past this error when it occurs?
Apologies if there is something straight forward I'm missing, I'm pretty new to node and even newer to bot development.
@mvalipour thanks for the link, looks very straight forward. I had planned on giving the bot a web interface at some stage anyways so would have needed to add an express part down the line as it was. The bot is still in development though, so it wont solve my current problem
My specific issue has to be a telegram one, Even if I request a higher offset message directly to the Telegram API its not clearing the messages.
I tweeted telegram hopefully they get back to me.
https://twitter.com/witnessmenow/status/686341804799733760
Same error guys. Bot receives same message with same message_id and does not change this.offset here
https://github.com/yagop/node-telegram-bot-api/blob/master/src/telegramPolling.js#L32
Loop is starting over and over again, I was testing it with breakpoints in WebStorm and it behaves strangely. Always index = 0 and loop restarts again.
I think we should try to find the problem and fix it guys.
@yagop in which case message wont be marked as read?
I think its a telegram error, as I was even trying to clear the message using the telegram api directly and couldn't.
It will clear its self in a couple of days
@witnessmenow I just used telegram api url, manually entered offset like this:
/getUpdates?offset=415204539
+1-ing every time I got update_id in json. So after some iterations I got rid of old messages.
Problem is not with telegram I think. Something wrong with incrementing update_id in code. If I encounter this problem again I will try to find a solution and create PR.
If you look at my tweet from earlier I tried that and it didn't work. Messages for bots clear after 24 hours, did you just happen to wait that long maybe?
@witnessmenow which update_id did you use? I got one from their json and just incremented it and entered and repeated until no old messages left. Maybe they are clearing them automatically but you can erase them manually if you have stuck messages?
Also you may be right. I have this problem since yesterday (don't really remember time). I'll try to create another one.
Yep. I did create another 'situation'.
Recipe is: turn off bot. Send several same messages for which you created callback onText, turn bot on and you get this:
Got message. Id: 1476 and time: 1454681507065
Got message. Id: 1476 and time: 1454681507540
Got message. Id: 1476 and time: 1454681508017
Got message. Id: 1476 and time: 1454681508480
Got message. Id: 1476 and time: 1454681508938
Got message. Id: 1476 and time: 1454681509399
After this I manually entered url which is used inside this bot
https://api.telegram.org/botNUMBER:TOKEN/getUpdates?offset=415204539
(offset is kinda random)
I got update_id like this:
{"ok":true,"result":[{"update_id":415204547,
After it I incremented this update_id and sent it via offset parameter
One by one (with each increment) stacked messages started to disappear. Until I got empty array and bot resumed to work properly. Exactly what this bot is supposed to do when reading updates. This is kinda major bug I think, because you can that easily create it.
We need to go deeper and investigate the code :smiley:
+1 Same problem here, I need flush my bot manually incrementing +1 on offset manually.
This should be fixed by commit 178f9cd9051b63377fcbb3a13f564b175b1cd3e7. The matter was it wasn't updating the offset if there was an error and can't reach the last message. Now every message processed updates the offset.
Thank you @yagop!
Working perfectly now! Thanks @yagop!