Skip to content

Commit

Permalink
Create telegram_bot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored May 11, 2024
1 parent 26398cb commit 089f0de
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions telegram_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Original code
def handle_message(message):
if message.text == "/start":
#...

# Improved code
from telegram.ext import CommandHandler, MessageHandler

def handle_start(update, context):
"""Handle the /start command"""
#...

def handle_message(update, context):
"""Handle incoming messages"""
if update.message.text == "/start":
handle_start(update, context)
else:
#...

telegram_handler = CommandHandler("start", handle_start)
telegram_handler = MessageHandler(Filters.text, handle_message)

0 comments on commit 089f0de

Please sign in to comment.