Closed elhadjx closed 1 year ago
You need to setup a local DB or similar that you store the userID of the users + the status (block or not).
Actually you can do:
bot.sendMessage(userID, 'hi').catch(err => {
// If the Telegram bot api return an error, you can handle it and put the user your db the list of blocked
})
Recomended for future, listen this event for know in real time when a user block, not block, change persions of your bot...:
bot.on("my_chat_member", (msg) => {
// You can know if a user block or unblock your bot (When the user perform this action). Is a telegram update event
})
Note: For get this update you need to put in the list of "allowed_updates". Reference: https://github.com/yagop/node-telegram-bot-api/issues/923#issuecomment-996038501
that's so helpful. thank you, alot!
I have:
Introduction
I needed to message all Bot users but I get sometimes an error of Bot blocked by user! so it'd be helpful to have a isBotBlockedBy(userID) function.
Example
if ( !isBotBlockedBy(userID) ) { bot.sendMessage(userID, ' hi '); }