Examples of Telegram bots for own automation

Examples of Telegram bots for own automation

No one can be surprised with Telegram bots. Telegram recently celebrated its 10th anniversary and I decided to make a text version of my video. The idea is simple – sometimes there are difficulties in order to come up with what to write a Telegram bot about, and I decided to share a selection of bots that I have developed and use in my life.

Moreover, these will not be direct bots, but rather methods of using telegram-bot-api to solve various tasks.

Sending messages

The first and simplest example of using Telegram is sending messages. You can send a message when the site is down, as well as receive notifications about new applications. For example, if we have a company website, when a new application arrives, you can receive a message via Telegram. This is the basic way to use Telegram.

Downloading a file from the server

I don’t know about you, but I regularly find myself needing to download something from a server I SSH into. For example, I generated some report with a script and I want to download it.

It is quite lazy to connect via sftp and go to this folder again, and anyway, then this file will be sent, most likely, to someone in Telegram. I wrote a small bash script that allows me to run a command and specify a file path. As a result, this file arrives in my inbox, and then I do whatever I want with it. When I wrote this script, I did not think that I would use it so often. As a result, this file resides on almost every server I use.

Important: Given that this script simply stores the bot-token, it is recommended to create a separate bot for this purpose, so as not to worry about someone else leaking this token.

Automatic backups on the server

Another example related to the previous one is sending automatic backups. I understand that it is not always good to use telegrams in file storage format, but we had a project where the client was not ready to pay for backup support and said something like “well, I don’t need backups, the project is not critical”. But we guys are scientists and still his backup.

The backup mechanics are simple – there is a bash script that creates a tar.gz from the desired folder, splits the archive into 40MB and simply drops them into the chat.

The script itself will be thrown into the crown at 5 in the morning every day. The system has been in operation for several years and has specifically saved the client several times ass the situation Of course, it is not as convenient as a normal backup system – files must be collected into one, transferred to the server. But it’s really worth it!

Creating an MR through a bot

I have a lot of different projects in my gallery and we have our own telegram chat for each project. Some projects are made on microservice architecture. We are working on the flow feature of the branch that flows into stage (with auto-deployment to the test bench) and subsequent injection into release.

After developing some big feature for 5 services, it becomes necessary to make several MR (Merge Request) from the stage to the release at once. And this, as a rule, I do. I got bored of it pretty quickly, and we made a small bot that understands the project in question through chat and creates these MRs by itself. A trifle is nice.

From this automation, I had the idea that many routine operations can be transferred to an assistant bot, and since then, the development of this background bot began and it is expanding in various directions.

Integration with the task system in Notion

I made a separate video for this job. But I will briefly describe it in the current selection. The bottom line is this: I keep my tasks in Notion and creating tasks through their interface is a pain in the ass.

Notion itself is beautiful, but it takes a long time to load, then by the time you reach the desired page, etc., it is easier to score and not record the task. Plus, I would like other people to be able to set tasks for me without seeing the rest of the tasks.

Not much code and now a limited circle of people can write to my bot with a task for me, and then I will take care of its implementation myself.

If Notion had a normal system of webhooks, then I would also notify the user about the completed task. But for now it will come off like that.

So it turns out that people do not have access to my Notion, but at the same time they can dump tasks in Notion that I will need to analyze later. Of course, no one abuses it, and they use it only when they can get me to do something or when they are already doing something non-urgent.

Fortnite server status tracking

If I share a selection of robots, then it is a sin not to share it. It is not related to work and productivity. I play Fortnite and I usually play right during work hours – spend 30-40 minutes and jump back into work. But the problem is that Fortnite likes to go for maintenance at night US time, which means that it does not work for us at 12-13 o’clock.

It is very unpleasant to find out about this after gathering the boys to play. So I wrote a bot that regularly visits status.epicgames.com and texts me about server status changes.

As a result, I always know that the server is down for maintenance and I can work calmly without planning a wonderful break.

Saving images in Yandex.Disk

Somehow I had a child, and then another one! And being a parent = getting lots of different pictures of your kids from different people and usually via Telegram. I would really like to store these photos in the cloud (I use Yandex disk), but it is too difficult for a lazy person like me to carry them by hand.

As a result, the solution turned out to be very simple – I made a robot to whom I forward photos from other people, and the robot translates these photos into folders every month. I had the idea to add face recognition to notice who is in the photo, but I put it in a long drawer for now. It is enough for me that the photos are saved in a place convenient for me after minimal actions on my part.

Personal secretary

My bot @amorevbot, by default, acts as my secretary. Any person can write to him and, in a separate chat, a thread will be created in which I will already communicate from my side, and my messages will be sent on behalf of the bot to this person.

This bot is needed for those who want to contact me after my content on my youtube or telegram channel. The result is a single point of entry to communicate with me, but without sending me a message directly. Also, I separate the personal communication of people I know from definitely strangers.

There are a lot of ready-made solutions for these tasks on the Internet, but I did not like all of them because you cannot teach the bot to create isolated threads to communicate with people. As a result, it all turns into a garbage dump of messages, among which I need to find exactly what belongs to a certain person.

Tracking currency rates

The next way to use the Telegram bot is to track currency rates. I am not an investor at all and moreover I have a lot of experience in trading stock markets in the past and I always recommend everyone to stay away from it.

But the dollar rate is quite an important metric for me — sometimes I order various goods from AliExpress and the dollar rate directly affects the final cost for me. I added the mechanic of tracking currency rates to my bot, and now the bot writes me the current rate.

It is important that he does not write a new message, but updates a single message in the channel. I wrote about the mechanics of this robot in detail here.

Connecting to a GPS tracker

Another interesting case, which is also related to my personal life. I bought myself some Chinese GPS trackers. They work as they should, but very inconvenient. Their official app is user abuse.

These trackers are convenient in some cases – throw them in the car when you leave them in an unfamiliar place for a long time, put them in your child’s pocket before going to a zoo, etc. I bought the trackers themselves for 800 rubles (the dollar was then 55).

As a result, I quite cutely connected to my personal account and made it so that you can enable a bot that will send me a message with coordinates and location through the visa itself. Next, while the bot is enabled, it will update it every 5 minutes.

I don’t need to go into a separate app, I just go into a separate chat with the bot and see the current location of my tracker. You can also temporarily add people to this chat with whom you would like to share the location of the tracker — I add people who went with me and my child on a trip to the chat with the tracker, and the child walks with the tracker in his pocket.

Sending data to a Google spreadsheet

It’s about the same mechanics as in the case of Notion. I write a message to the bot and a row is automatically created in a Google spreadsheet. As a result, adding something to the table has become much faster and, in some cases, it helps in my fight against laziness.

It turns out some one-way communication from the Telegram bot to the Google table – cool, good and easy.

Bot for tracking traffic jams

In the summer of 2022, I vacationed in Sochi and went there by car. The road from Moscow to Sochi is simply beautiful and goes in one breath… except for the serpentine at the end. I didn’t expect it to derail me so much. The main problem there is traffic jams — standing in a traffic jam on a serpentine on the mechanics is very painful. Especially in the heat!

While I was sitting in Sochi, I was thinking about how to optimize my way home. The thought occurred to me to monitor the state of traffic jams on the serpentine on different days and choose the optimal moment. To do this, I wrote a bot that enters Yandex maps, checks the status and sends the result to me.

Every 10 minutes the message was updated with a new screenshot, which was very convenient! I looked at how things were going and chose the most optimal time for the start (to drive quickly, but not to leave at night).

On the day of departure, I also used this bot – I turned it on well in advance and just watched when the picture on the road became acceptable and moved at the right moment.

Now I use this bot sometimes, because I rarely drive to Moscow.

Bot tracker for gallery

I have my own galley company, where we write various projects (including robots) outsourced. And in my case, it turned out to be a real problem at the end of the month to collect all the work we did and present it to the client.

For a while I was relying on my head, then I was relying on the heads of the developers and that they would remember at the end of the month what they were doing. But at one point, I realized that it was pointless to count on it, and the realization that “money was slipping through my fingers” was disturbing.

Then, for our task tracker, we wrote a simple bot that every 2 hours asks the developer “what he did for the last 2 hours” and in interactive mode allows you to quickly track time in the piggy bank. At the end of the month, the bot collects reports in a Google spreadsheet for each developer, and then we create invoices for our clients.

After implementation, we saw an increase in revenue and, at first, I was surprised at how much we were doing for customers – the invoices became predictable and the data collection became absolutely simple. I was satisfied!

Conclusion

These are not all the works I had to write. These are only works that I mentioned while preparing this material. I’m regularly expanding the capabilities of my personal assistant bot (connecting a command parser, connecting it to air conditioners by voice, connecting it to cameras in the office for security) and regularly come across new ideas for what can be done as a Telegram bot.

I will be glad if you share your bots in the comments and I will be glad to subscribe to my tg channel @gmoreva and YouTube channel @amorev.

Thank you for attention!

Related posts