Is it possible to send a message to the bot channel, if something happens on the server, without listening for commands from the user? For example, I want to send notifications to user about events on server
Hey!
Easy peasy:
bot.telegram.sendMessage(chatId, ...)
Nice, but how I can get chatId then?)
When I'm inside event handler, I can use context, outside it is not possible.
Unfortunately, Telegram API doesn't contain any methods to get, like a list of users who uses the bot and bot developer must maintain that list if needed.
In other words, you can store all new users to any database/file when bot receive /start command:
bot.command('start', ctx => {
database.saveUserChat(ctx.from.id, ctx.chat.id)
return ctx.reply('Hey')
})
Now you can send messages to users without Telegraf context using mapping user_id <-> chat_id from your database/file 馃檭
Most helpful comment
Hey!
Easy peasy: