Spaces:
No application file
No application file
File size: 771 Bytes
e6bc654 | 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 | import telebot
import os
# Get token from HF Secrets
TOKEN = os.environ.get('BOT_TOKEN')
bot = telebot.TeleBot(TOKEN)
# Handle the /start command
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "Hello World! Send me a number and I'll square it.")
# Handle text messages
@bot.message_handler(func=lambda message: True)
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() |