So you have seen how to respond to some comments that you send from the telegram.
Chat with the bot.
But now what if you just want to send a message to that group, for example?
Because here we can send a message to the group when we have a callback function.
So basically when we first receive a message from the group, so you need to send something from the
group, get that in the Python program and send a message back.
Now, what if you just want to send a message without waiting for any input from the application?
Well, that's what I'm going to show you now.
I'm going to create a new program.
You and, well, let's just take what we need from here.
So the interpreter.
We are going to need also this to get the token.
Okay.
And now?
Well, we are not going to need the updater or the command handler.
We are going to simply do from telegram import bot.
Okay.
And we are going to create a bot is equal to bot with token is equal to telegram token.
And then from that bot we can just do bot dot send message and here like we did before, we need to.
So that's the same function here.
We need to give the chat ID and the text.
So chat ID is equal to well what is the chat ID of this group?
How to know that.
So you could go on internet and there are some methods to find the chat ID for this specific chat.
But now that we have already a program that can receive command from the chat, what we can do is just
use this program to get the chat ID and then use the chat ID in this other program.
Okay, let me show you how to do that.
So in the start handler that's a good place because we receive some context and some update from the
chat.
And as you can see here, we respond by using update dot effective chat.id.
So basically effective chat is the chat you are using here to send the start command here and then the
ID is the ID of this.
So I'm just going to select this.
I'm going to do here print update, dot effective chatted.
I'm going to run that.
So telegram bot.
Ready and send.
Start.
Okay, you can see hello from Python.
And we also have here the chat ID So for a group, usually you will have something that starts with
a dash.
Okay.
So minus sign with the chat id so you can just copy this.
And then go in the other program.
Let's create a variable here.
Chat ID is equal to this, so we keep it here.
Actually, we don't just keep it as an integer.
This is a string.
Okay?
So we make sure this is as a string and then chat ID is equal to chat ID, so no problem with this.
This is the name of the parameter and this is the argument that we give.
So we give the chat ID and then text is equal to let's use something different.
Let's send some French.
Bonjour.
And let's just add a print here.
Okay?
So we can know from the Python program that we have sent something.
So send message to chat.
Let's run this and let's look at the chat here.
Run script, let's name it.
Send notification.
Okay.
Send message to chat and you can see bonjour.
And we also have the notification here for the desktop application.
If you are using your phone, you should also receive a notification.
I just received a notification on my phone for this chat.
Okay.
If you don't have the notification on your phone, make sure you have correctly allowed notification
for Telegram, but this is specific to your phone.
Okay.
Now you can see we can both respond to comments that we send from the chat and we can also send independent
messages directly to the chat from a Python program.