Telebot / app.py
Apex-X's picture
Create app.py
3530ac4
raw
history blame
1.16 kB
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
# Set up logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
# Replace 'YOUR_BOT_TOKEN' with the token you received from BotFather
TOKEN = '6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI'
# Create an Updater object to interact with the Telegram Bot API
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
# Define a command handler for the /start command
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Hello! I am your Telegram bot.")
# Define a function to echo user messages
def echo(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
# Register the command and message handlers with the dispatcher
start_handler = CommandHandler('start', start)
echo_handler = MessageHandler(Filters.text & ~Filters.command, echo)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(echo_handler)
# Start the bot
updater.start_polling()
updater.idle()