Telegram Wiki Bot in Python
Hello Friends, Here We’ll learn, how to create very basic Telegram Wiki Bot which will return us summery of any word. For instance, we say “wiki nepal” then it will return Wikipedia summary of Nepal. we’ll use Python3
There are two parts. First, create the bot on Telegram mobile app. Second, Make Python server for the bot and its logic. So, Let’s Start.
Creating Bot
- Install Telegram app on your mobile
- Complete your profile
- Now search for BotFather and select it
- Click on Start
- Follow the instruction given by BotFather to create your bot.
- When you finish, you will have BOT_TOKEN. keep it. it will be needed in the future.
Programming
- Install python-telegram-bot
pip install python-telegram-bot --upgrade- Install Wikipedia
pip install wikipedia- Now create file bot.py
- All the code of the file is given below (can’t copy). You can get it from here
- Further, we’ll discuss, how the code is working
Working
- First, we have imported necessary libraries.
- Initialize Updater with BOT_TOKEN, what we got from BotFather.
- Create get_wiki function which extracts Wikipedia summary.
- Define textpro function to process our incoming messages.
- it features message, sender name, and chat id.
- If the message starts with “wiki” then it replies Wikipedia summary of given word. Else replies “Invalid command”.
- Supported message format: wiki your word
- Then we have added Message Handler.
- and Started polling.
- Run the file, Your Telegram Wikipedia Bot is live now.
Advanced Telegram Bot
Telegram Bot API provides many more features like sending Audo, Video, Documents or other files. You can explore them from here.
Get Shivam Agrawal’s stories in your inbox
Join Medium for free to get updates from this writer.
I have developed this LifeBot which supports Song, Book, and Wiki commands. You can find its source code here.
Resources
Hope, you enjoyed :)








