diff --git a/.env.example b/.env.example index 8ff3234..f0680bb 100644 --- a/.env.example +++ b/.env.example @@ -18,3 +18,17 @@ BETTER_AUTH_URL=http://localhost:4000 # Gateway GATEWAY_PORT=4000 + +# Discord Plugin (optional — set DISCORD_BOT_TOKEN to enable) +# DISCORD_BOT_TOKEN= +# DISCORD_GUILD_ID= +# DISCORD_GATEWAY_URL=http://localhost:4000 + +# Telegram Plugin (optional — set TELEGRAM_BOT_TOKEN to enable) +# TELEGRAM_BOT_TOKEN= +# TELEGRAM_GATEWAY_URL=http://localhost:4000 + +# Authentik SSO (optional — set AUTHENTIK_CLIENT_ID to enable) +# AUTHENTIK_ISSUER=https://auth.example.com +# AUTHENTIK_CLIENT_ID= +# AUTHENTIK_CLIENT_SECRET= diff --git a/apps/gateway/package.json b/apps/gateway/package.json index f177e02..08d0482 100644 --- a/apps/gateway/package.json +++ b/apps/gateway/package.json @@ -20,6 +20,7 @@ "@mosaic/coord": "workspace:^", "@mosaic/db": "workspace:^", "@mosaic/discord-plugin": "workspace:^", + "@mosaic/telegram-plugin": "workspace:^", "@mosaic/log": "workspace:^", "@mosaic/memory": "workspace:^", "@mosaic/types": "workspace:^", diff --git a/apps/gateway/src/plugin/plugin.module.ts b/apps/gateway/src/plugin/plugin.module.ts index 2d63f5f..68a4861 100644 --- a/apps/gateway/src/plugin/plugin.module.ts +++ b/apps/gateway/src/plugin/plugin.module.ts @@ -7,6 +7,7 @@ import { type OnModuleInit, } from '@nestjs/common'; import { DiscordPlugin } from '@mosaic/discord-plugin'; +import { TelegramPlugin } from '@mosaic/telegram-plugin'; import { PluginService } from './plugin.service.js'; import type { IChannelPlugin } from './plugin.interface.js'; @@ -26,9 +27,23 @@ class DiscordChannelPluginAdapter implements IChannelPlugin { } } +class TelegramChannelPluginAdapter implements IChannelPlugin { + readonly name = 'telegram'; + + constructor(private readonly plugin: TelegramPlugin) {} + + async start(): Promise { + await this.plugin.start(); + } + + async stop(): Promise { + await this.plugin.stop(); + } +} + const DEFAULT_GATEWAY_URL = 'http://localhost:4000'; -function createPluginRegistry(logger: Logger): IChannelPlugin[] { +function createPluginRegistry(): IChannelPlugin[] { const plugins: IChannelPlugin[] = []; const discordToken = process.env['DISCORD_BOT_TOKEN']; const discordGuildId = process.env['DISCORD_GUILD_ID']; @@ -50,8 +65,13 @@ function createPluginRegistry(logger: Logger): IChannelPlugin[] { const telegramGatewayUrl = process.env['TELEGRAM_GATEWAY_URL'] ?? DEFAULT_GATEWAY_URL; if (telegramToken) { - logger.warn( - `Telegram plugin requested for ${telegramGatewayUrl}, but @mosaic/telegram-plugin is not implemented yet.`, + plugins.push( + new TelegramChannelPluginAdapter( + new TelegramPlugin({ + token: telegramToken, + gatewayUrl: telegramGatewayUrl, + }), + ), ); } @@ -63,7 +83,7 @@ function createPluginRegistry(logger: Logger): IChannelPlugin[] { providers: [ { provide: PLUGIN_REGISTRY, - useFactory: (): IChannelPlugin[] => createPluginRegistry(new Logger('PluginModule')), + useFactory: (): IChannelPlugin[] => createPluginRegistry(), }, PluginService, ],