my-test-bot / app.py
reddotapp25's picture
Create app.py
e6bc654 verified
Raw
History Blame Contribute Delete
771 Bytes
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()