How to make a telegram bot (2024)

What is Bot?

According to Wikipedia, It is a software application that runs automated tasks (scripts) over the Internet. In other terms, It is a program written to mimic human behaviour in order to perform some tasks. Bots take input and do simple and repetitive tasks, which is much faster than humans.

There are two types of bots:

  • Good Bots: Bots that are beneficial to organizations as well as individuals such as ChatBots, Social Media bots, etc
  • Bad Bots: These are the bots that are used to perform malicious activities such as Scraping and Spamming.

In this, We will make Telegram Chatbot, which would send a copy of the input that the user has sent.

Making our Telegram Chatbot

We will be using Python language to make the bot and will be using Telegram package for our bot.You can know more about the telegram package from here

Firstly, we will generate our telegram token. Below are the steps to follow to generate your own token.

  1. Search BotFather on Telegram.
  2. Type /start to get started.
  3. Type /newbot to get a bot.
  4. Enter your Bot name and unique Username, which should end with the bot.
  5. Then, you would get your Bot token.

After generating our token, we will make a python program to create a Telegram bot that will send the Text, Emojis, and Stickers similar to the user's input.

  • Importing libraries required.
import loggingfrom telegram.ext import Updater, Filters, CommandHandler, MessageHandler
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', #take time,level,name level=logging.INFO)logger = logging.getLogger(__name__)

This script does a basic configuration for the logging system. It takes time, level, and name.

  • Now, we will make a variable Token, which will take your Telegram token.
TOKEN = "ENTER YOUR TOKEN" 
  • After writing the token, we will make some functions that our bot will perform.
def start(bot,update): name = update.message.from_user.first_name #first name of the user messaging reply = "Hi!! {}".format(name) bot.send_message(chat_id = update.message.chat_id, text = reply) #sending messagedef help(bot,update): reply = "How can I help You" bot.send_message(chat_id = update.message.chat_id, text = reply) #sending messagedef echo_text(bot,update): reply = update.message.text bot.send_message(chat_id = update.message.chat_id, text = reply)def sticker(bot,update): reply = update.message.sticker.file_id bot.send_sticker(chat_id = update.message.chat_id, sticker = reply)def error(bot,update): logger.error("sh*t!! Update {} caused error {}".format(update,update.error))

start function would be taking the user's input and would be sending, Hi, with the user's name.

help function will prompt the message of how can I help you.

echo_text and sticker function will send the same message or the stickers which the user has sent.

error function would be printing the error message on the command prompt.

  • Finally, we will make the main function, which would be executed first on running the program. It will take the updates and handle the updates.
def main(): updater = Updater(TOKEN) #take the updates dp = updater.dispatcher #handle the updates dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) dp.add_handler(MessageHandler(Filters.text, echo_text)) #if the user sends text dp.add_handler(MessageHandler(Filters.sticker, sticker)) #if the user sends sticker dp.add_error_handler(error) updater.start_polling() logger.info("Started...") updater.idle()if __name__=="__main__": main()

Save the program and execute it to check the working of the telegram bot on telegram.

You can get the source code to make the Telegram bot from this Github Repository Bot :robot:. You can also make some changes to the code to make the bot do cool stuff such as Getting News, Articles, or Movies recommendations.

How to make a telegram bot (1)

Written byRajan Puri

Just a beginner trying to learn more and more

How to make a telegram bot (2024)
Top Articles
I Tried TRX® For A Week, And I Definitely Felt Stronger By The End
How many times a month should you shop for groceries?
Is Sam's Club Plus worth it? What to know about the premium warehouse membership before you sign up
The Atlanta Constitution from Atlanta, Georgia
Ret Paladin Phase 2 Bis Wotlk
Find All Subdomains
Stolen Touches Neva Altaj Read Online Free
Lichtsignale | Spur H0 | Sortiment | Viessmann Modelltechnik GmbH
All Obituaries | Ashley's J H Williams & Sons, Inc. | Selma AL funeral home and cremation
Lesson 2 Homework 4.1
UEQ - User Experience Questionnaire: UX Testing schnell und einfach
The fabulous trio of the Miller sisters
Accuradio Unblocked
6813472639
Youravon Comcom
Kp Nurse Scholars
Wgu Academy Phone Number
Outlet For The Thames Crossword
Kcwi Tv Schedule
Parc Soleil Drowning
Why Are Fuel Leaks A Problem Aceable
Barista Breast Expansion
Pioneer Library Overdrive
Saxies Lake Worth
Vera Bradley Factory Outlet Sunbury Products
Gunsmoke Tv Series Wiki
Jesus Calling Feb 13
Airg Com Chat
Does Circle K Sell Elf Bars
Craigslist Central Il
Whas Golf Card
Kstate Qualtrics
One Credit Songs On Touchtunes 2022
Back to the Future Part III | Rotten Tomatoes
Wildfangs Springfield
Autozone Locations Near Me
In Polen und Tschechien droht Hochwasser - Brandenburg beobachtet Lage
3400 Grams In Pounds
Noaa Marine Weather Forecast By Zone
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Go Bananas Wareham Ma
Craigslist en Santa Cruz, California: Tu Guía Definitiva para Comprar, Vender e Intercambiar - First Republic Craigslist
Ethan Cutkosky co*ck
Santa Clara County prepares for possible ‘tripledemic,’ with mask mandates for health care settings next month
Movie Hax
Online College Scholarships | Strayer University
Theatervoorstellingen in Nieuwegein, het complete aanbod.
Minecraft: Piglin Trade List (What Can You Get & How)
Diablo Spawns Blox Fruits
Game Like Tales Of Androgyny
7 National Titles Forum
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5672

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.