Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a message to all users when the bot wake up

I've started tinkering with python recently and I'm on my way to create my very first telegram bot mainly for managing my Raspberry Pi and a few things connected to it. The bot is done but I would like to send a message to all the users that have already interacted with the bot when it starts, basically saying something like "I'm ready!", but I haven't been able to find any information about it.

Is there any specific method in the API already done to do this? Or should I create another file to store the chat_id from all the users and read it with python?

Thank you all for your help!! Regards!

like image 273
GuillermoG Avatar asked Oct 26 '25 08:10

GuillermoG


1 Answers

You should have a Database that stores Chat-id(s) of Clients that interact with your bot. If you're able to put them into a list, then the job is half done. All you need to do is to create a "for loop", and send message to all the ID(s) in the list. Example:

message = "Good morning"
chats =[1234447488,3748838477,4748848578,7463638488]
for chat in chats:
    bot.send_message(chat_id=chat,text= "message")

In case of of clients that have deleted your bot, you may experience an error. You can catch that with try and except.

like image 115
Thehackitect Avatar answered Oct 28 '25 20:10

Thehackitect



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!