WEBVTT

00:00.080 --> 00:06.590
Now that your account is correctly set up and configured, let's create a bot on the Telegram app.

00:06.620 --> 00:11.930
We first need to do that and then we will be able to use this bot in a python program.

00:11.930 --> 00:16.310
So you're going to search here for bot father like this.

00:17.400 --> 00:22.830
So you type exactly like this and you're going to go with the first one, the certified one, because

00:22.830 --> 00:29.280
you can see you have many well, fake but father okay with slightly different username, but you just

00:29.280 --> 00:37.980
go with the bot father and this bot father is basically going to allow you to create new bots.

00:38.340 --> 00:43.200
So you click on Start or you just send slash, you can see slash start.

00:43.200 --> 00:49.170
If you don't have a start button and you have a help here, I can help you to create and manage telegram

00:49.170 --> 00:49.680
bots.

00:49.710 --> 00:50.430
ET cetera.

00:50.430 --> 00:51.330
ET cetera.

00:51.330 --> 00:55.740
And so you can create bots, you can edit bots, you have settings.

00:55.770 --> 00:56.520
ET cetera.

00:56.550 --> 00:58.440
You're going to do new bots.

00:58.470 --> 01:04.560
Okay, So slash new bots, you can either click on this or just write new bot.

01:05.870 --> 01:06.410
All right.

01:06.440 --> 01:07.220
A new boat.

01:07.400 --> 01:09.260
So you choose a name for the boat.

01:10.280 --> 01:13.040
Okay, Let's name it goes boat.

01:13.220 --> 01:15.860
So that's just the name we're going to see.

01:15.860 --> 01:18.800
And then we need to choose a username.

01:19.040 --> 01:22.370
It needs to end in a boat, as you can see.

01:22.400 --> 01:27.140
So let's try API, Arduino course.

01:27.650 --> 01:36.500
But okay, so if it tells you that the name is already taken, then you try another name.

01:36.500 --> 01:37.100
Okay.

01:37.280 --> 01:39.740
Until you have a name that is unique.

01:39.740 --> 01:43.370
So this name doesn't have to be unique, but this name will be unique.

01:43.370 --> 01:47.750
So if you try, of course to have the same as me, well, that's not going to work.

01:47.750 --> 01:48.950
And then you see down.

01:48.950 --> 01:49.880
Congratulations.

01:49.880 --> 01:50.360
ET cetera.

01:50.360 --> 01:51.020
ET cetera.

01:51.020 --> 01:53.660
And you have a token here.

01:53.660 --> 01:55.970
That is the most important thing.

01:56.120 --> 01:56.540
Okay?

01:56.540 --> 02:00.170
And you can see, keep your token secure and store it safely.

02:00.170 --> 02:02.180
This should be secret.

02:02.180 --> 02:06.300
So why I'm showing you this now is simply because.

02:06.300 --> 02:10.860
Well, I'm going to use this token when I record the videos and then I'm going to change it.

02:10.860 --> 02:15.180
So if you try to use this exact token, you're not going to be able to use my bot.

02:15.210 --> 02:15.780
Okay?

02:15.870 --> 02:21.210
The token basically will allow you to connect to the bot from your Python program.

02:21.210 --> 02:26.550
So for the bot you have a name, you have a username that is unique and a token.

02:26.760 --> 02:33.450
Now let's do a start for example, again to get the help you can see, for example, what I can do is

02:33.450 --> 02:38.430
revoke both token access for that boat.

02:38.760 --> 02:43.230
You can see your token was replaced with a new one and then you have this.

02:43.260 --> 02:48.060
Okay, so this token here is not valid anymore.

02:48.270 --> 02:49.590
This is the new one.

02:49.590 --> 02:54.180
And so basically I'm going to revoke my token after I record the course.

02:54.540 --> 02:54.810
Okay.

02:54.810 --> 02:55.620
So we have a token.

02:55.620 --> 02:58.290
We're going to come back to this token just a bit later.

02:58.290 --> 03:04.070
And now what we are going to do, we're going to create a group chat, okay?

03:04.080 --> 03:08.370
That we are going to use for, for sending notifications.

03:08.370 --> 03:11.190
So you click here.

03:11.490 --> 03:12.630
New group.

03:14.160 --> 03:19.710
Let's name this group course group, so you name it as you want.

03:20.580 --> 03:22.470
You can add members.

03:22.500 --> 03:28.620
Let's search for RPI, Arduino course bot.

03:28.620 --> 03:32.160
So I find the bot and I create the group.

03:32.820 --> 03:33.090
Okay.

03:33.090 --> 03:41.040
So you can see now in the group view group info, we have two members, so me and the bot.

03:41.070 --> 03:42.470
We have just created.

03:42.480 --> 03:42.960
Okay.

03:42.960 --> 03:46.530
And so you can add other persons if you want.

03:47.960 --> 03:52.610
And well, we are going to communicate with the bot through this group here.

03:53.270 --> 03:56.300
So the telegram configuration is done for the bot.

03:56.330 --> 03:59.240
Now let's go back to bot Father.

03:59.720 --> 03:59.820
Okay.

03:59.870 --> 04:06.710
If you don't have it here, you just search for it and let's copy the token.

04:06.920 --> 04:11.510
Now, what I'm going to do is I'm going to show you how basically to store the token somewhere on your

04:11.510 --> 04:15.740
Raspberry Pi and just get it on your python code.

04:15.740 --> 04:19.400
And then in the next lesson, we are going to control the bot with Python.

04:19.400 --> 04:23.000
So just a bit more of configuration and that's it.

04:23.000 --> 04:25.310
So let's open a terminal actually.

04:26.600 --> 04:33.080
And what I'm gonna do is basically we are in the home directory, so we have this.

04:33.080 --> 04:38.270
But if I do dash A to list all I have also the hidden files.

04:38.750 --> 04:39.290
Okay.

04:39.500 --> 04:42.560
And there is one hidden directory here.

04:43.100 --> 04:43.880
Local.

04:43.880 --> 04:53.270
So dot local we are going to go in to local LS and let's do a okay.

04:53.270 --> 04:55.400
We are going to go in share.

04:56.570 --> 04:56.870
Okay.

04:56.870 --> 05:02.270
And I'm going to create a new file here and put the token inside.

05:02.270 --> 05:06.680
So here we won't be able to make a 100% secure file for the token.

05:06.680 --> 05:11.300
But basically by hiding the file somewhere, that is a bit hard to find.

05:11.330 --> 05:17.270
This is a bit more secure than just putting, for example, the token on the desktop or putting in the

05:17.270 --> 05:21.710
home directory or directly hardcoding the token in the code.

05:21.710 --> 05:23.450
So I'm going to create here.

05:23.450 --> 05:30.200
So nano, let's name Dot, we are going to create a hidden file as well.

05:30.350 --> 05:35.120
Telegram bot token.

05:35.240 --> 05:40.730
Okay, press enter and I'm going to paste the token with Ctrl shift and V.

05:41.420 --> 05:41.720
Okay.

05:41.720 --> 05:50.990
This is the token that I got from here and I'm going to save it with Ctrl s and Ctrl X to quit.

05:51.500 --> 05:53.810
Now you can see if I do well, nothing.

05:53.810 --> 06:00.350
If I do dash a, I can see I have my telegram bot token here.

06:00.590 --> 06:04.490
So once again, this is not 100% secure solution.

06:04.490 --> 06:09.770
If you want something completely secure, you would need to use, for example, the OAuth two protocol.

06:09.770 --> 06:14.230
But that's something really more complex and outside of the scope of this course.

06:14.240 --> 06:19.880
So now that we have our token saved here, let's open.

06:23.830 --> 06:24.940
Thonny python ide.

06:27.180 --> 06:30.210
Okay, let's create a new file.

06:31.020 --> 06:34.890
USR bin env and python three.

06:38.460 --> 06:42.060
And let's just write the code to get the token.

06:42.060 --> 06:47.460
So what we need to do, we just need to open the file we have just created and save the token inside

06:47.460 --> 06:47.940
a variable.

06:47.940 --> 07:02.520
So we've open and then so slash home slash by slash dot local slash share and slash dot telegram.

07:03.090 --> 07:03.900
But.

07:05.540 --> 07:05.720
Okay.

07:06.350 --> 07:06.620
Okay.

07:06.620 --> 07:12.740
So make sure you have the correct path here for the file with read permission.

07:13.470 --> 07:13.610
Okay.

07:13.610 --> 07:15.900
We don't need to write as f.

07:15.920 --> 07:16.130
Okay.

07:16.130 --> 07:21.170
So we're going to open this file and get it as f in this block of code.

07:21.170 --> 07:22.580
And we do Telegram.

07:24.980 --> 07:32.440
Token is equal to f dot red dot is trip.

07:33.950 --> 07:34.580
And now.

07:34.580 --> 07:39.940
Well this is important is that you don't print the telegram token.

07:39.950 --> 07:46.760
Basically if you design a more secure application and then you just print the token you got in the code.

07:46.760 --> 07:50.210
Well all the security you have done is just useless.

07:50.210 --> 07:55.520
So I'm still going to print it just once to make sure that it's working.

07:58.220 --> 07:58.790
Okay.

07:58.790 --> 07:59.720
I use strip.

07:59.720 --> 07:59.960
Okay.

07:59.960 --> 08:05.660
Because maybe at the end of the file we have some new line character or some carriage return that we

08:05.660 --> 08:06.140
don't want.

08:06.140 --> 08:08.330
So we make sure that they are gone.

08:08.330 --> 08:13.070
Because if we have, for example, a new line character, that's not going to work after that.

08:13.070 --> 08:14.780
So let's just run this.

08:16.190 --> 08:19.400
Let's name it Telegram bot.

08:20.890 --> 08:27.640
Okay, we have the token and now I'm going to do this and remove the print and we are not going to print

08:27.640 --> 08:30.760
the token anymore now that we know it's working.

08:30.760 --> 08:32.890
And let's now use this bot.
