Telegraf: Send message after external event happens

Created on 31 Oct 2017  路  3Comments  路  Source: telegraf/telegraf

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

question

Most helpful comment

Hey!

Easy peasy:

bot.telegram.sendMessage(chatId, ...)

All 3 comments

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 馃檭

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bostrot picture bostrot  路  3Comments

supermomme picture supermomme  路  3Comments

agstover picture agstover  路  3Comments

bostrot picture bostrot  路  3Comments

kmahsi picture kmahsi  路  3Comments