platforms.factory module
- platforms.factory.create_platform(pcfg, message_handler, media_cache=None, message_update_handler=None, message_delete_handler=None, config=None, reaction_update_handler=None)[source]
Instantiate the correct platform adapter for a single platform config.
Dispatches on
pcfg.typeto build the matching connector (MatrixPlatform,DiscordPlatform,DiscordSelfPlatform,WebChatPlatform, orRedisPlatformAdapter), lazily importing the chosen platform module so unused dependencies are never loaded. Each adapter is wired with the gateway’s inbound callbacks (new message, update, delete, reaction) plus the sharedMediaCacheand globalConfig, and per-platform secrets such as tokens, homeserver, and credentials are pulled out ofpcfgwith sane defaults. The adapter itself owns the actual platform connection and event loop; this function only constructs it. Called by the gateway service (gateway_main) during startup, once per enabled entry incfg.platforms, with the returned adapter appended to its adapter list and later bound to an outbound stream consumer.- Parameters:
pcfg (
PlatformConfig) – Configuration for one platform, including itstypediscriminator and any platform-specific keys.message_handler (
Callable[...,Any]) – Coroutine invoked when a new inbound message arrives on the platform.media_cache (
MediaCache|None) – Shared cache used to deduplicate and store downloaded attachments; passed through to platforms that support it.message_update_handler (
Optional[Callable[...,Any]]) – Optional callback for edited messages.message_delete_handler (
Optional[Callable[...,Any]]) – Optional callback for deleted messages.config (
Config|None) – Global bot configuration handed to each adapter.reaction_update_handler (
Optional[Callable[...,Any]]) – Optional callback for reaction add/remove events.
- Return type:
- Returns:
A constructed platform adapter instance for the requested type.
- Raises:
ValueError – If
pcfg.typedoes not match any known platform.