Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
|
3 |
+
|
4 |
+
# Set up logging
|
5 |
+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
6 |
+
level=logging.INFO)
|
7 |
+
|
8 |
+
# Replace 'YOUR_BOT_TOKEN' with the token you received from BotFather
|
9 |
+
TOKEN = '6516533220:AAEoq0ohv4xAraIw7lB7BZVHKyUg85wo3mI'
|
10 |
+
|
11 |
+
# Create an Updater object to interact with the Telegram Bot API
|
12 |
+
updater = Updater(token=TOKEN, use_context=True)
|
13 |
+
dispatcher = updater.dispatcher
|
14 |
+
|
15 |
+
# Define a command handler for the /start command
|
16 |
+
def start(update, context):
|
17 |
+
context.bot.send_message(chat_id=update.effective_chat.id, text="Hello! I am your Telegram bot.")
|
18 |
+
|
19 |
+
# Define a function to echo user messages
|
20 |
+
def echo(update, context):
|
21 |
+
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
|
22 |
+
|
23 |
+
# Register the command and message handlers with the dispatcher
|
24 |
+
start_handler = CommandHandler('start', start)
|
25 |
+
echo_handler = MessageHandler(Filters.text & ~Filters.command, echo)
|
26 |
+
|
27 |
+
dispatcher.add_handler(start_handler)
|
28 |
+
dispatcher.add_handler(echo_handler)
|
29 |
+
|
30 |
+
# Start the bot
|
31 |
+
updater.start_polling()
|
32 |
+
updater.idle()
|