-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updates.ForEach is not a function #284
Comments
Are you able to reproduce the bug? |
Not in an easy way. I'm not sure why it happens. The only thing I know it happened to me twice, both of them at almost the same time on two conseqcutives days (around 9pm CET). I'm not sure, but I think is the same error that appears when you have more than one instance of the bot running. |
If you want to run multiple instances of the application, please use WebHooks. Using polling is not scalable. See more help information on scaling (Sorry! Help information is a bit incomplete! We really need help in that area.). Otherwise, it will be hard for us to fix the bug (comfortably) if we can not pinpoint why and how it occurs. We need to investigate more on this. |
Gocho, maybe I have explained myself wrong. The thing is that I don't want to run multiple instances of my bot, only one. But I think that the error that appears is the same as if I run more than one. I just said that to see if it could help to understand better the error. I'll try to give more information if I'm able to get a better understading of the error. I just wanted to see if someone could bring some light on the cause of the error. BTW, I'm going to try the webhook, just to see if the behaviour improves and errors are avoided. |
This simple script:
Result:
Month ago all works fine. |
|
Having the same issue after updating to 0.26. |
Stack trace upper:
data is
|
Seems to be working fine now. Didn't change anything 🤔 |
I've been using the polling option for a whole day whitout problems, it just started to fail suddenly, my app crashed, and after rebooting it, it worked again like a charm. That make me thing that it could be something related with Telegram servers, but I cannot assure it. Is just a intuition. |
I think something wrong with logic of enable polling. Polling wait array of polling results but get in result boolean. May be telegram servers automatically delete webHook and no need to call it manually |
Try to change polling and return if result data not array |
Change
And all works good. |
Thanks to this discussion that I have identified the bug. Yes, this is a bug in the library. This occurs when the bot, while polling, tries to delete the already-set webhook, so as to be able to get updates. I have been able to reproduce this bug (a test for this bug will be added) and am working to push a fix for this. |
Bug: During polling, deleting the already-set webhook, caused the `TelegramBotPolling#_getUpdates()` return an unexpected value. We expect the method to return an array (in the `.then()` clause). However, deleting the webhook returns its value, which is an object, from the method `_getUpdates()`. Fix: Simply retry the polling request and return the promise. Notes: Should we use recursion? I do not think so. Why? The chances of getting the error (having a webhook set) AGAIN is quite rare. And if it happens, there must be some problem with different instances invoking polling and webhook simultaneously. In that case, we wont struggle to recover from such a scenario. User is on their own! Isht! References: * Bug report: #284 * Reported by: @dcparga
Just pushed a fix for this in commit 130f6940ceb9972a7b0ac0636ac16e7e53984a46 (see how to reproduce the bug, and how we have fixed it!). Please try it out and let us know of the results. |
Console repeat this:
|
Do you have other instances of your bot running? |
Created new bot. All works fine. 10x |
Added: 1. Add constructor options: * (#243) `options.polling.params` (by @GochoMugo, requested-by @sidelux) 1. Add methods: * (#74) *TelegramBot#removeReplyListener()* (by @githugger) 1. (#283) Add proper error handling (by @GochoMugo) 1. (#272) Add health-check endpoint (by @mironov) * `options.webHook.healthEndpoint` 1. (#152) Add test for TelegramBot#sendDocument() using 'fileOpts' param (by @evolun) 1. Document `options.webHook.host` (by @GochoMugo) 1. (#264) Add Bot API version to README (by @kamikazechaser) 1. Add examples: - (#271) WebHook on Heroku (by @TheBeastOfCaerbannog) - (#274) WebHook on Zeit Now (by @ferrari) Changed: 1. (#147) Use *String#indexOf()*, instead of *RegExp#test()*, to find token in webhook request (by @AVVS) Fixed: * Fix bug: - (#275, #280) fix es6 syntax error on Node.js v4.x (by @CrazyAbdul) - (#276) promise.warning from `request-promise` (by @GochoMugo, reported-by @preco21) - (#281) fix handling error during polling (by @GochoMugo, reported-by @dimawebmaker) - (#284) fix error during deletion of already-set webhook, during polling (by @GochoMugo, reported-by @dcparga) 1. Fix links in documentation (by @Ni2c2k)
Fixed in v0.27.0. Thanks @dcparga, @lokhmakov and @mjanssen for your time and effort in fixing this bug. |
Bug: During polling, deleting the already-set webhook, caused the `TelegramBotPolling#_getUpdates()` return an unexpected value. We expect the method to return an array (in the `.then()` clause). However, deleting the webhook returns its value, which is an object, from the method `_getUpdates()`. Fix: Simply retry the polling request and return the promise. Notes: Should we use recursion? I do not think so. Why? The chances of getting the error (having a webhook set) AGAIN is quite rare. And if it happens, there must be some problem with different instances invoking polling and webhook simultaneously. In that case, we wont struggle to recover from such a scenario. User is on their own! Isht! References: * Bug report: yagop/node-telegram-bot-api#284 * Reported by: @dcparga
Bug: During polling, deleting the already-set webhook, caused the `TelegramBotPolling#_getUpdates()` return an unexpected value. We expect the method to return an array (in the `.then()` clause). However, deleting the webhook returns its value, which is an object, from the method `_getUpdates()`. Fix: Simply retry the polling request and return the promise. Notes: Should we use recursion? I do not think so. Why? The chances of getting the error (having a webhook set) AGAIN is quite rare. And if it happens, there must be some problem with different instances invoking polling and webhook simultaneously. In that case, we wont struggle to recover from such a scenario. User is on their own! Isht! References: * Bug report: yagop/node-telegram-bot-api#284 * Reported by: @dcparga
I have read:
I am using the latest version of the library.
Expected Behavior
The process should be able to run without problem and indefinitely without throwing an error.
Actual Behavior
After the whole day running without problems, around 9pm my process start to throw this message continuously:
Unhandled rejection TypeError: updates.forEach is not a function
at _lastRequest._getUpdates.then.updates (/app/node_modules/node-telegram-bot-api/src/telegramPolling.js:102:17)
at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:691:18)
at Async._drainQueue (/app/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/app/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)
The text was updated successfully, but these errors were encountered: