Spaces:
No application file
No application file
| import telebot | |
| import os | |
| # Get token from HF Secrets | |
| TOKEN = os.environ.get('BOT_TOKEN') | |
| bot = telebot.TeleBot(TOKEN) | |
| # Handle the /start command | |
| def send_welcome(message): | |
| bot.reply_to(message, "Hello World! Send me a number and I'll square it.") | |
| # Handle text messages | |
| def calculate_square(message): | |
| text = message.text | |
| # Check if input is a number | |
| if text.isdigit(): | |
| num = int(text) | |
| square = num * num | |
| bot.reply_to(message, f"According to HF, square of {num} is {square}") | |
| else: | |
| bot.reply_to(message, "I only accept numbers! (e.g., 5)") | |
| # Start the 'Infinity Polling' | |
| print("Bot is starting...") | |
| bot.infinity_polling() |