slimshadow commited on
Commit
76feee5
·
verified ·
1 Parent(s): 57e0605

Create bot.py

Browse files
Files changed (1) hide show
  1. bot.py +39 -0
bot.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from telegram import Update
3
+ from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes
4
+
5
+ # Enable logging
6
+ logging.basicConfig(
7
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
8
+ level=logging.INFO
9
+ )
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # Define a start command handler
13
+ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
14
+ await update.message.reply_text('Hello! I am your Telegram bot. Send me a message!')
15
+
16
+ # Define an echo message handler
17
+ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
18
+ user_message = update.message.text
19
+ await update.message.reply_text(f'You said: {user_message}')
20
+
21
+ # Define a main function to run the bot
22
+ def main():
23
+ # Replace 'YOUR_BOT_TOKEN' with your bot's token from BotFather
24
+ BOT_TOKEN = '8046464181:AAEhWZa1_xbXFMPSmRGfrkJ4x7PZsGIwpRA
25
+
26
+ # Create the Application
27
+ application = ApplicationBuilder().token(BOT_TOKEN).build()
28
+
29
+ # Register command handlers
30
+ application.add_handler(CommandHandler('start', start))
31
+
32
+ # Register message handler for echo functionality
33
+ application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
34
+
35
+ # Run the bot
36
+ application.run_polling()
37
+
38
+ if __name__ == '__main__':
39
+ main()