botalka/daemons/mailbox.py
emmatveev c08a02073f
All checks were successful
Deploy Dev / Build (pull_request) Successful in 6s
Deploy Dev / Push (pull_request) Successful in 7s
Deploy Dev / Deploy dev (pull_request) Successful in 10s
fix
2024-11-27 16:13:49 +03:00

31 lines
870 B
Python

from telebot import apihelper
from daemons import base
from utils import platform
from utils import queues
class Daemon(base.Daemon, queues.TasksHandlerMixin):
def execute(self):
self.poll()
@property
def queue_name(self):
return 'botalka_mailbox'
def process(self, payload):
bot = platform.platform_client.get_config('bots')[payload['project']][payload['name']]
if not bot['mailbox_enabled']:
return
if bot['type'] == 'telegram':
token = bot['secrets']['telegram_token']
self.process_telegram(token, payload['body'])
else:
print('Unknown bot type:', bot['type'])
def process_telegram(self, token, payload):
try:
apihelper.send_message(token, **payload)
except Exception as exc:
print('Error', str(exc))