Now that your account is correctly set up and configured, let's create a bot on the Telegram app.
We first need to do that and then we will be able to use this bot in a python program.
So you're going to search here for bot father like this.
So you type exactly like this and you're going to go with the first one, the certified one, because
you can see you have many well, fake but father okay with slightly different username, but you just
go with the bot father and this bot father is basically going to allow you to create new bots.
So you click on Start or you just send slash, you can see slash start.
If you don't have a start button and you have a help here, I can help you to create and manage telegram
bots.
ET cetera.
And so you can create bots, you can edit bots, you have settings.
ET cetera.
You're going to do new bots.
Okay, So slash new bots, you can either click on this or just write new bot.
All right.
A new boat.
So you choose a name for the boat.
Okay, Let's name it goes boat.
So that's just the name we're going to see.
And then we need to choose a username.
It needs to end in a boat, as you can see.
So let's try API, Arduino course.
But okay, so if it tells you that the name is already taken, then you try another name.
Okay.
Until you have a name that is unique.
So this name doesn't have to be unique, but this name will be unique.
So if you try, of course to have the same as me, well, that's not going to work.
And then you see down.
Congratulations.
ET cetera.
And you have a token here.
That is the most important thing.
Okay?
And you can see, keep your token secure and store it safely.
This should be secret.
So why I'm showing you this now is simply because.
Well, I'm going to use this token when I record the videos and then I'm going to change it.
So if you try to use this exact token, you're not going to be able to use my bot.
Okay?
The token basically will allow you to connect to the bot from your Python program.
So for the bot you have a name, you have a username that is unique and a token.
Now let's do a start for example, again to get the help you can see, for example, what I can do is
revoke both token access for that boat.
You can see your token was replaced with a new one and then you have this.
Okay, so this token here is not valid anymore.
This is the new one.
And so basically I'm going to revoke my token after I record the course.
Okay.
So we have a token.
We're going to come back to this token just a bit later.
And now what we are going to do, we're going to create a group chat, okay?
That we are going to use for, for sending notifications.
So you click here.
New group.
Let's name this group course group, so you name it as you want.
You can add members.
Let's search for RPI, Arduino course bot.
So I find the bot and I create the group.
Okay.
So you can see now in the group view group info, we have two members, so me and the bot.
We have just created.
Okay.
And so you can add other persons if you want.
And well, we are going to communicate with the bot through this group here.
So the telegram configuration is done for the bot.
Now let's go back to bot Father.
Okay.
If you don't have it here, you just search for it and let's copy the token.
Now, what I'm going to do is I'm going to show you how basically to store the token somewhere on your
Raspberry Pi and just get it on your python code.
And then in the next lesson, we are going to control the bot with Python.
So just a bit more of configuration and that's it.
So let's open a terminal actually.
And what I'm gonna do is basically we are in the home directory, so we have this.
But if I do dash A to list all I have also the hidden files.
Okay.
And there is one hidden directory here.
Local.
So dot local we are going to go in to local LS and let's do a okay.
We are going to go in share.
Okay.
And I'm going to create a new file here and put the token inside.
So here we won't be able to make a 100% secure file for the token.
But basically by hiding the file somewhere, that is a bit hard to find.
This is a bit more secure than just putting, for example, the token on the desktop or putting in the
home directory or directly hardcoding the token in the code.
So I'm going to create here.
So nano, let's name Dot, we are going to create a hidden file as well.
Telegram bot token.
Okay, press enter and I'm going to paste the token with Ctrl shift and V.
Okay.
This is the token that I got from here and I'm going to save it with Ctrl s and Ctrl X to quit.
Now you can see if I do well, nothing.
If I do dash a, I can see I have my telegram bot token here.
So once again, this is not 100% secure solution.
If you want something completely secure, you would need to use, for example, the OAuth two protocol.
But that's something really more complex and outside of the scope of this course.
So now that we have our token saved here, let's open.
Thonny python ide.
Okay, let's create a new file.
USR bin env and python three.
And let's just write the code to get the token.
So what we need to do, we just need to open the file we have just created and save the token inside
a variable.
So we've open and then so slash home slash by slash dot local slash share and slash dot telegram.
But.
Okay.
So make sure you have the correct path here for the file with read permission.
Okay.
We don't need to write as f.
Okay.
So we're going to open this file and get it as f in this block of code.
And we do Telegram.
Token is equal to f dot red dot is trip.
And now.
Well this is important is that you don't print the telegram token.
Basically if you design a more secure application and then you just print the token you got in the code.
Well all the security you have done is just useless.
So I'm still going to print it just once to make sure that it's working.
Okay.
I use strip.
Okay.
Because maybe at the end of the file we have some new line character or some carriage return that we
don't want.
So we make sure that they are gone.
Because if we have, for example, a new line character, that's not going to work after that.
So let's just run this.
Let's name it Telegram bot.
Okay, we have the token and now I'm going to do this and remove the print and we are not going to print
the token anymore now that we know it's working.
And let's now use this bot.