Merge pull request 'master' (#22) from master into prod

Reviewed-on: #22
This commit is contained in:
emmatveev 2024-11-29 20:35:37 +03:00
commit 185ce0c5ce
2 changed files with 19 additions and 5 deletions

View File

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

View File

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