fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 35s
Deploy Dev / Push (pull_request) Successful in 12s
Deploy Dev / Deploy dev (pull_request) Successful in 13s

This commit is contained in:
emmatveev 2024-11-29 20:24:55 +03:00
parent aae0871671
commit 05dc1ceda2
2 changed files with 20 additions and 5 deletions

View File

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

View File

@ -1,6 +1,10 @@
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