node-telegram-bot-api: how to know if bot is blocked by user (catch 403 forbbidden)?
Sometimes users deletes/block the bots and this error shows up:
W20170201-07:16:56.291(0)? (STDERR) Unhandled rejection Error: 403 {"ok":false,"error_code":403,"description":"Forbidden: Bot was blocked by the user"}
W20170201-07:16:56.293(0)? (STDERR) at /home/x/telegram/app/node_modules/node-telegram-bot-api/lib/telegram.js:219:17
W20170201-07:16:56.293(0)? (STDERR) at tryCatcher (/home/x/telegram/app/node_modules/request-promise/node_modules/bluebird/js/main/util.js:26:23)
W20170201-07:16:56.293(0)? (STDERR) at Promise._settlePromiseFromHandler (/home/x/telegram/app/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:510:31)
W20170201-07:16:56.293(0)? (STDERR) at Promise._settlePromiseAt (/home/x/telegram/app/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:584:18)
W20170201-07:16:56.294(0)? (STDERR) at Promise._settlePromises (/home/x/telegram/app/node_modules/request-promise/node_modules/bluebird/js/main/promise.js:700:14)
W20170201-07:16:56.294(0)? (STDERR) at Async._drainQueue (/home/x/telegram/app/node_modules/request-promise/node_modules/bluebird/js/main/async.js:123:16)
i tried doing .catch
on sendMessage
but it doesn’t seem to work, even “old school” try/catch
around bot.sendMessage
curiously didn’t seem to work.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 15
Commits related to this issue
- doc: Update help information References: * Issue #219: https://github.com/yagop/node-telegram-bot-api/issues/219 * Issue #273: https://github.com/yagop/node-telegram-bot-api/issues/273 * Issue... — committed to yagop/node-telegram-bot-api by GochoMugo 7 years ago
- doc: Update help information References: * Issue #219: https://github.com/yagop/node-telegram-bot-api/issues/219 * Issue #273: https://github.com/yagop/node-telegram-bot-api/issues/273 * Issue... — committed to fullstackbusiness1128/node-telegram-bot-api by fullstackbusiness1128 7 years ago
@GochoMugo > What semantically-correct way do you recommend, in place of exceptions?
Well, in golang the syntax is:
The problem with this approach IMO is that exceptions are expensive. It would be better to avoid throwing exception
For example,
exceptions aren’t expensive on js, anyway, if you want to avoid try/catch you use “reject” from Promises, which seem like it’s already the case?
That’s a non-issue, even if it was a performance issue nobody is running sendMessage on an infinite loop that’s supposed to perform.
I’m surprised Telegram doesn’t have any API to listen on when user exits or delete bot.
@GochoMugo Just a regular promise.error ( or promise.catch ) ?