|
from typing import Dict, Optional, Any |
|
from bot_definitions import BotType, call_transfer, simple_dialin, simple_dialout, voicemail_detection |
|
|
|
|
|
class BotRegistry: |
|
def __init__(self): |
|
self.bots: Dict[str, BotType] = { |
|
"call_transfer": call_transfer, |
|
"simple_dialin": simple_dialin, |
|
"simple_dialout": simple_dialout, |
|
"voicemail_detection": voicemail_detection, |
|
} |
|
|
|
def get_bot(self, name: str) -> Optional[BotType]: |
|
return self.bots.get(name) |
|
|
|
def detect_bot_type(self, body: Dict[str, Any]) -> Optional[str]: |
|
for bot in self.bots.values(): |
|
if bot.config_key in body: |
|
return bot.name |
|
if all(key in body for key in ["From", "To", "callId", "callDomain"]): |
|
return "call_transfer" |
|
return None |
|
|
|
def setup_configuration(self, config: Dict[str, Any]) -> Dict[str, Any]: |
|
body = {} |
|
bot_name = config.get("bot_type") |
|
bot = self.get_bot(bot_name) |
|
if bot: |
|
body[bot.config_key] = config.get("settings", {}) |
|
return body |