-
Notifications
You must be signed in to change notification settings - Fork 1
/
telegram_bot.py
53 lines (45 loc) · 2.19 KB
/
telegram_bot.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
import telebot
from config import TELEGRAM_BOT_TOKEN
from message_handler import process_message, send_help
from logger import logger
from openai_manager import OpenAiManager
class TelegramBot:
def __init__(self):
self.bot = telebot.TeleBot(TELEGRAM_BOT_TOKEN)
def start(self):
@self.bot.message_handler(commands=['start', 'help'])
def handle_help(message):
response = send_help()
self.bot.reply_to(message, response)
@self.bot.message_handler(commands=['update'])
def handle_update(message):
message_text = message.text
message_text = message_text.replace('/update', '', 1).strip()
if not message_text:
self.bot.reply_to(message, "The message is empty. Please provide the required information.")
return
try:
process_message(message_text)
self.bot.reply_to(message, "The Notion database has been updated successfully.")
except Exception as e:
logger.exception(f"Failed to update the Notion database,{e}")
self.bot.reply_to(message, f"An error occurred while updating the Notion database: {e}")
@self.bot.message_handler(commands=['openai'])
def handle_update(message):
message_text = message.text
message_text = message_text.replace('/openai', '', 1).strip()
if not message_text:
self.bot.reply_to(message, "The message is empty. Please provide the required information.")
return
try:
openai_manager = OpenAiManager(message_text)
result = openai_manager.get_prompt_result()
process_message(result)
self.bot.reply_to(message, "The Notion database has been updated successfully.")
except Exception as e:
logger.exception(f"Failed to update the Notion database,{e}")
self.bot.reply_to(message, f"An error occurred while updating the Notion database: {e}")
try:
self.bot.infinity_polling()
except Exception as e:
logger.exception(f"Failed to start the bot,{e}")