Spaces:
Paused
Paused
File size: 1,339 Bytes
76feee5 5323463 76feee5 |
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 34 35 36 37 38 39 40 |
import logging
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, ContextTypes
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
logger = logging.getLogger(__name__)
# Define a start command handler
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text('Hello! I am your Telegram bot. Send me a message!')
# Define an echo message handler
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
user_message = update.message.text
await update.message.reply_text(f'You said: {user_message}')
# Define a main function to run the bot
def main():
# Replace 'YOUR_BOT_TOKEN' with your bot's token from BotFather
BOT_TOKEN = '8046464181:AAEhWZa1_xbXFMPSmRGfrkJ4x7PZsGIwpRA'
# Create the Application
application = ApplicationBuilder().token(BOT_TOKEN).build()
# Register command handlers
application.add_handler(CommandHandler('start', start))
# Register message handler for echo functionality
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
# Run the bot
application.run_polling()
if __name__ == '__main__':
main()
|