File size: 1,715 Bytes
6172a47 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | """Messaging platform factory.
Creates the appropriate messaging platform adapter based on configuration.
To add a new platform (e.g. Discord, Slack):
1. Create a new class implementing MessagingPlatform in messaging/platforms/
2. Add a case to create_messaging_platform() below
"""
from loguru import logger
from .base import MessagingPlatform
def create_messaging_platform(
platform_type: str,
**kwargs,
) -> MessagingPlatform | None:
"""Create a messaging platform instance based on type.
Args:
platform_type: Platform identifier ("telegram", "discord", etc.)
**kwargs: Platform-specific configuration passed to the constructor.
Returns:
Configured MessagingPlatform instance, or None if not configured.
"""
if platform_type == "telegram":
bot_token = kwargs.get("bot_token")
if not bot_token:
logger.info("No Telegram bot token configured, skipping platform setup")
return None
from .telegram import TelegramPlatform
return TelegramPlatform(
bot_token=bot_token,
allowed_user_id=kwargs.get("allowed_user_id"),
)
if platform_type == "discord":
bot_token = kwargs.get("discord_bot_token")
if not bot_token:
logger.info("No Discord bot token configured, skipping platform setup")
return None
from .discord import DiscordPlatform
return DiscordPlatform(
bot_token=bot_token,
allowed_channel_ids=kwargs.get("allowed_discord_channels"),
)
logger.warning(
f"Unknown messaging platform: '{platform_type}'. Supported: 'telegram', 'discord'"
)
return None
|