I did a quick test by running two instances of a node app with telegraf, sending messages to me every 5 seconds using bot.telegram.sendMessage
.
const { Telegraf } = require('telegraf')
const bot = new Telegraf("<MY_BOT_TOKEN>")
bot.launch().then(
setInterval(() => {
bot.telegram.sendMessage('<MY_CHAT_ID>', `hello from ${process.env.INSTANCE_NUMBER}`)
}, 5000)
)
It worked properly, but I also got this error
Error: 409: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running
About which I found this. Anyway, both the instances kept sending me messages without any problem.
I would say that this depends on the library, which besides sending these messages is also polling the telegram API for updates, even if I didn't set up any callback to manage them.
Indeed if you check the sendMessage documentation of Telegram Bot API, it doesn't mention such an error.
This means that you should be able to send such sendMessage
calls from multiple instances of the same bot without any problem, just pay attention to the library you are using and what it's doing under the hood. You may even want to implement your own calls instead of relying on existing apps if they don't suit your use case.
update
I tried to send messages without launching the bot (which makes it fetch updates i guess) and i didn't get the errors
const { Telegraf } = require('telegraf')
const bot = new Telegraf("<MY_BOT_TOKEN>")
setInterval(() => {
bot.telegram.sendMessage('<MY_CHAT_ID>', `hello from ${process.env.INSTANCE_NUMBER}`)
}, 5000))
at this point, I'm quite confident you can do it.