async def handler(request): data = await request.json() is_valid = validate_data(data) if is_valid: custom_send(chat_id=data['chat_id'], text=data['text']) return web.Response(status=200) else: err = f'data {data} must contain chat_id and text keys' LOG.error(err) return web.Response(status=500, body=err)
def add_module_handlers(module_name): try: module = importlib.import_module(f'bot.modules.{module_name}').Module LOG.info( f'module imported - {module.name} (handlers: {len(module.handlers)})' ) for handler in module.handlers: dispatcher.add_handler(handler) except Exception as e: LOG.error(e)