fix(gateway): wire Telegram plugin into gateway plugin host (#99)
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Some checks failed
ci/woodpecker/push/ci Pipeline failed
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #99.
This commit is contained in:
@@ -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<void> {
|
||||
await this.plugin.start();
|
||||
}
|
||||
|
||||
async stop(): Promise<void> {
|
||||
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,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user