reddotapp25 commited on
Commit
e6bc654
·
verified ·
1 Parent(s): 61581ee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import telebot
2
+ import os
3
+
4
+ # Get token from HF Secrets
5
+ TOKEN = os.environ.get('BOT_TOKEN')
6
+ bot = telebot.TeleBot(TOKEN)
7
+
8
+ # Handle the /start command
9
+ @bot.message_handler(commands=['start'])
10
+ def send_welcome(message):
11
+ bot.reply_to(message, "Hello World! Send me a number and I'll square it.")
12
+
13
+ # Handle text messages
14
+ @bot.message_handler(func=lambda message: True)
15
+ def calculate_square(message):
16
+ text = message.text
17
+
18
+ # Check if input is a number
19
+ if text.isdigit():
20
+ num = int(text)
21
+ square = num * num
22
+ bot.reply_to(message, f"According to HF, square of {num} is {square}")
23
+ else:
24
+ bot.reply_to(message, "I only accept numbers! (e.g., 5)")
25
+
26
+ # Start the 'Infinity Polling'
27
+ print("Bot is starting...")
28
+ bot.infinity_polling()