Closed vhdmsm closed 6 years ago
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" notifications@github.com 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.
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!
@yagop :100:
@yagop can you please release a new version with this fix? I think the issue here: https://github.com/yagop/node-telegram-bot-api/issues/15#issuecomment-214911783 is related to this, but I noticed 0.20.1 doesn't have this fix yet and there hasn't been a release since then.
@yagop can you please release a new version with this fix? I think the issue here: #15 (comment) is related to this, but I noticed 0.20.1 doesn't have this fix yet and there hasn't been a release since then.
@omnidan Upgrading to 0.20.1 did fix the issue for me, I believe.
@phillipadsmith the fix isn't part of 0.20.1 (it's from Feb 1 and the fix was made on Mar 13) - I also contacted @yagop a while ago and he told me he meant to release a new version but forgot. Still no new release now 😞
@omnidan Bah, you're totally right.
And, having managed to get into this infinite loop again, I'm wondering if @yagop's commit https://github.com/yagop/node-telegram-bot-api/commit/178f9cd9051b63377fcbb3a13f564b175b1cd3e7 actually fixed it?
I've just tried using that version of telegramPolling.js and -- if there's a failure -- the incrementing doesn't appear to happen, and the loop begins as far as I can tell.
Have others resolved this with a patch? cc @idchlife @lucaslg26
I'm having the same issue right now @phillipadsmith
This is what I have gathered so far:
The bug occurs when an error is thrown during processing of an update.
During this processing of an update (at src/telegramPolling.js#L46), an error could be thrown while:
EventListener
calls all listeners synchronously"Such an error would bubble up and be handled by the enveloping promise (see src/telegramPolling.js#L40). The promise would simply re-throw the error (at src/telegramPolling.js#L51). This results in the "Unhandled rejection Error" as seen above. So far, such unhandled errors do NOT terminate the Node.js process. The unterminated process will continue polling (see src/telegramPolling.js#L58)!
However, @yagop's fix, updates the offset before processing an update. Since an update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id, all the updates received, including the update that caused the chain of errors to occur, would be confirmed, as soon as we enter the next poll interval (see src/telegramPolling.js#L94). Thus, the fix (kinda) works!
Before the fix, the offset would not have been updated (see old code at src/telegramPolling.js#L34), causing the next poll interval to retrieve already-processed updates, including the update that originally caused the error! Thus LOOP!
Note that if the process terminated and we restarted it again, this bug would re-surface since we would not have marked the already-processed updates as confirmed! This is important considering that in the future, unhandled promise rejections will terminate the process. Thus, the fix will stop working some time in the future!
In some cases, the bug would disappear, as the offending update would have been discarded by Telegram after their 24hr limit!
It is currently fixed!!!
The current fix works, as long as unhandled promise rejections do not terminate the process. Once Node.js behaves by terminating, this loop will re-surface! To prevent this Loop completely, we need a way to consider this:
To achieve the above, in our .catch()
(at src/telegramPolling.js#L49), we may do the following, in order:
getUpdates
request with the updated offset + 1
, therefore marking all processed updates as confirmed!Reproducing this bug is important. If you believe that this bug has not been fixed, please provide an elaborate way to reproduce it. (@yagop had a hard time doing so)
The current fix works, as long as unhandled promise rejections do not terminate the process. Once Node.js behaves by terminating, this loop will re-surface! To prevent this Loop completely...
PR #265 handles (future) cases where unhandled promise rejections will terminate the process. Please proceed to the PR to leave comments on the implementation!
👍For fixing this!
@mvalipour link is down
@luckydonald Fixed it. damn trailing slash :/
Fixed in v0.30.0.
Hi My bot has been stuck in infinite loop and it's not responding anymore, what's problem? here is the stack trace: