top of page
  • Writer's pictureAlexey Bondarenko

Creating a personal assistant. Telegram Bot + Chat GPT (API)

Updated: Jun 10, 2023

Hello, world!


The Telegram app is my primary messenger. In addition to its main function of communication with people, it provides a cool opportunity to create bots that can be very useful.

I have decided to develop a Telegram bot, a personal assistant, that will save my time and provide all the necessary functions for me and my family.


In recent months, neural networks have become popular, and everyone who respects themselves tries to find ways to use them in their work. And, of course, I am no exception.

In this bot, I have decided to use the API from Chat GPT.

Also I have chosen Python as the programming language for this project.


It's a final version


Let's take a look at features:

Smart Translator Translates from any language to correct English, Finnish or Russian. This is not Google Translate - it's better. Without any grammar or logical errors.

Error Corrector You write a text in any language and it checks your text for grammar and punctuation errors, sends a corrected version and explains where you made mistakes.

Adds politeness to your text You got angry and write an angry text? Okay, it happens. Just send this message to the bot and it will rephrase the text in a polite form and you won't be embarrassed about it the next day.

Home Doctor Something got you sick and you want to ask a doctor about it? No problem, tell about yourself, tell about your condition and describe your symptoms to the bot in as much detail as possible. He will try to help. Can give useful recommendations. You can have a dialogue with him like with a regular person. Ask additional questions, clarify something, etc. In turn, if the bot needs additional information about your condition - he can ask you additional questions. Of course, this is not a substitute for a real doctor. But can be useful.

Kitchen Helper You opened the refrigerator and see cucumber, potatoes, tomatoes and bananas? Not clear what to cook from this .... No problem. The bot will help. Just write him a list of ingredients you have and he will determine a dish recipe for you that can be cooked from them. And will write to you how to cook it. In addition, you can simply ask him any dish and get detailed information in a couple of seconds.

Personal Assistant You can also ask the bot any question you have and he will try to answer it, using his knowledge of the world. He can be your psychologist, or help you calculate your taxes. In general, anything, free communication.


Why I need this bot?

Motivations:

  1. Time-saving: I wanted a bot that could automate tasks and provide quick access to information, saving me valuable time and improving my efficiency.

  2. Personalized assistance: My goal was to have a bot that offers tailored services and functions based on my specific needs and preferences, providing a personalized and convenient experience. (I don't need to generate the prompts every time)

  3. Convenience and accessibility: By integrating the bot into my preferred messaging app, like Telegram, I can easily access its features anytime, anywhere, without the need for additional applications or interfaces.

  4. Learning and experimentation: I saw an opportunity to gain hands-on experience with neural networks, APIs, and programming by developing this bot, allowing me to expand my knowledge and skills in these areas.

  5. Assistance for my family: I wanted the bot to benefit not only myself but also my family by including features that provide convenience and support in various aspects of our lives.


I may not claim to have perfect Python code, but the beauty lies in the fact that, in the end, everything works and brings value, which was the main goal.


 

Sequence of my actions

  1. Created a new Telegram bot.

  2. Obtained an API key for the bot.

  3. Obtained an API key for ChatGpt (by the way, it's a paid service).

  4. Deployed code for my bot's keyboards.

  5. Implemented callback handler processing.

  6. Developed code for each function.

  7. Deployed the Python code on a remote server.

The new bot creation via BotFather

The new keyboards creation

I used the 'aiogram' library for interacting with Telegram's API. Also, I have chosen two neural network models that I will later use in my functions: "text-davinci-003" for translation and "gpt-3.5-turbo" for others.

For the each button you need to create callback query handler like

Create a main function that will handle user messages and call the desired function

Create methods for all functions you need. Example for one:

To ensure that the bot works consistently and is accessible from anywhere, it needs to be deployed on a remote server. Since my application is small and doesn't generate revenue, I hosted it on a free server provided by https://replit.com

To prevent the server from going down, we need to continuously send requests to it. For this purpose, I used the service https://uptimerobot.com


 

The end.


I really enjoyed developing this chatbot.

159 views0 comments

Comments


bottom of page