DEV Community

Cover image for Making Telegram Bots using Python(Pyrogram)
Swanit Anuran
Swanit Anuran

Posted on

Making Telegram Bots using Python(Pyrogram)

Hello Buddies, Let's make a Telegram Quote Bot using Pyrogram and python-arq today.

Pre-requisite knowledge:

  1. Basic Python Programming
  2. Basic Knowledge about Telegram bots.

Let's start:

First go to @BotFather and create a new bot and Take its bot token.

Then go to @ARQRobot and make a API KEY.

Install these Required Python Packages using pip3 install -U <package name>:

  • pyrogram
  • TgCrypto
  • python-arq
  • aiohttp

We need python version greater or equal to 3.9.0 to run this. So if you have python version lower than this. Upgrade it first.

Now let's Setup the Clients

Clients

This is how we will setup the clients for the quote bot.

Now let's define how to Quotify

Defining Quotely

We have defined how to quote

Now let's take on the how to setup the command for using the quote function

Command

We setup q as the command, and pyrogram takes /as the default handler

Now we are going to setup that it takes input only when we reply to a text message with the command.
For that we are going to use this:

reply_to_message

Now let's check what the user gave with the command, if it's 'r' we will quote the message with the message being replied too. If its an integer we are goin to
quote the given number of messages from the replied message

taking r or int

Now the else: part

Else

Quoting done! Oh but we didn't even started the bot.

run

Add this in the end to run the bot else it won't even run. Now save the file named bot.py

Now to run and test the bot we will do
python3 -m bot.py

Top comments (0)