File size: 1,158 Bytes
3530ac4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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()
|