Compare commits

..

No commits in common. "a5d3bd08c1f84b510ac9afefc7aba18f1de07d46" and "ad74b8de7adf2c173ee4a8487dacd4ac68e000db" have entirely different histories.

2 changed files with 5 additions and 20 deletions

View File

@ -1,5 +1,3 @@
import pydantic
from telebot import apihelper from telebot import apihelper
from daemons import base from daemons import base
@ -7,14 +5,6 @@ from utils import platform
from utils import queues from utils import queues
class Message(pydantic.BaseModel):
project: str
name: str
type: str
body: dict
method: str = 'send_message'
class Daemon(base.Daemon, queues.TasksHandlerMixin): class Daemon(base.Daemon, queues.TasksHandlerMixin):
def execute(self): def execute(self):
self.poll() self.poll()
@ -23,19 +13,18 @@ class Daemon(base.Daemon, queues.TasksHandlerMixin):
def queue_name(self): def queue_name(self):
return 'botalka_mailbox' return 'botalka_mailbox'
def process(self, payload: dict): def process(self, payload):
message = Message.model_validate(payload) bot = platform.platform_client.get_config('bots')[payload['project']][payload['name']]
bot = platform.platform_client.get_config('bots')[message.project][message.name]
if not bot['mailbox_enabled']: if not bot['mailbox_enabled']:
return return
if bot['type'] == 'telegram': if bot['type'] == 'telegram':
token = bot['secrets']['telegram_token'] token = bot['secrets']['telegram_token']
self.process_telegram(token, message.method, message.body) self.process_telegram(token, payload['body'])
else: else:
print('Unknown bot type:', bot['type']) print('Unknown bot type:', bot['type'])
def process_telegram(self, token, method, payload): def process_telegram(self, token, payload):
try: try:
getattr(apihelper, method)(token, **payload) apihelper.send_message(token, **payload)
except Exception as exc: except Exception as exc:
print('Error', str(exc)) print('Error', str(exc))

View File

@ -1,10 +1,6 @@
annotated-types==0.7.0
certifi==2024.8.30 certifi==2024.8.30
charset-normalizer==3.4.0 charset-normalizer==3.4.0
idna==3.10 idna==3.10
pydantic==2.10.2
pydantic_core==2.27.1
pyTelegramBotAPI==4.1.1 pyTelegramBotAPI==4.1.1
requests==2.32.3 requests==2.32.3
typing_extensions==4.12.2
urllib3==2.2.3 urllib3==2.2.3