Step-by-Step Tutorial: Building a Telegram Bot in Python [Part I – Basics]
Hello, It’s Jay here. And I’m here with the long-awaited series on Telegram Bot Development. We will be building a ChatBot using OpenAI API. So our series will be divided into a few parts.
Series Outline:
- Installing Python and Packages
- Preparing The Bot
- Coding Our Script
- Implementing Our Script Into The Bot
- Deploying The Bot
In this segment, we will cover the basics to get started. So without further ado let’s jump into it.
Install Python:
It’s obvious as we have already mentioned Python in the title, so we need to download and install Python.
- Go to https://www.python.org/downloads/ and click on Download Python 3.x.x, if your system doesn’t support the latest version, try the older versions.
- After downloading the executable file install it. Make sure you tick the Add to PATH checkbox, its the probably the most important part.
- Once you’re done installing it, open your command prompt and run
python --version
and you should see something similar:you’ll see the version that you’ve installed. If you see it, congratulations! You have successfully installed Python! But if you’re facing any problem you can google the error logs, and you’ll get a solution for sure.
2. Installing Necessary Packages:
We will be installing a few packages for our project.
- pyrogram: We will be using this wrapper for our bot. There are a lot of options out there like python telegram bot, Telethon, and Aiogram. It’s about your preference on which one to choose. I personally like Pyrogram. It has awesome docs and examples on its site and has some slight edges than the others.
- tgcrypto: TgCrypto is a high-performance, easy-to-install cryptography library specifically written in C for Pyrogram as a Python extension. It helps your pyrogram perform faster.
- requests: We need it to make HTTP requests to an API to send and fetch data.
To install these 3 packages all you need to do is run pip install pyrogram tgcrypto requests
from your command prompt. If you encounter any issues try replacing pip with pip3.
After running the command, you should see something like this:
This is about it.
Full Tutorial:
Hopefully, you got the hang of it. We will create a bot in the next tutorial. See you in the next one.
1 thought on “Step-by-Step Tutorial: Building a Telegram Bot in Python [Part I – Basics]”