Member-only story

Building a Scalable Telegram Chatbot with Python and Serverless Function.

Maxime
AWS Tip
Published in
8 min readJan 2, 2023

--

Photo by Pradamas Gifarry on Unsplash

Let’s define what we want to do: we want to have in Telegram a bot that is capable of answering our questions. We want to code it in Python. And to make it available to everyone by deploying it on a serverless function (serverless because we want a scalable solution without worrying about the underlying infrastructure). This project is a good opportunity to learn about Telegram bots, and to explore deployments possibilities with AWS (Amazon Web Servicies).

For my projects I like to split it in differents steps:

  1. First step, create telegram chatbot.
  2. The second step is to add Chat GPT in our chatbot.
  3. And the last step is to deploy it on an AWS function.

1. Create a telegram chatbot

What is Telegram ? It is a cloud-based messaging app that allows users to send text, photos, and other media to each other.

Telegram is known for its focus on security and privacy, as well as its fast, reliable messaging capabilities and support for bots. Telegram has a large user base, with over 500 million monthly active users as of 2021.

In order to create a bot we need to contact the father of all bots in telegram : @BotFather. We will ask him to create a /newbot and choose a name for it.

Once the name is set, the bot father will provide us the HTTP API key. We keep this key safe and secure. We will need it in our script.

Now let’s create a folder on our machine and create a virtual environnement, I recommend using python 3.9. We will store our key in a .env folder as

BOT_TOKEN = hereisyouranonymouskeythatnoonemustsee

Now we need to install some packages. Activate your virtual environnement and install the packages by running the following command :

pip install python-telegram-bot requests python-dotenv

Once everything is installed we can start coding our bot. In a file named bot.py we import the packages we…

--

--

Published in AWS Tip

Best AWS, DevOps, Serverless, and more from top Medium writers .

Written by Maxime

Data Science - Biology 🇫🇷🇺🇦

Responses (1)

Write a response