export function createPlugin(config, ctx) {
const bot = new TelegramBot(config.token);
return {
register(reg) {
// Register the channel adapter
reg.channel({
sendMessage: async (chatId, threadId, text, opts) => {
await bot.api.sendMessage(chatId, text);
},
supportsMessaging: () => true,
});
},
async start() {
// Start polling for messages
bot.on("message:text", async (botCtx) => {
const response = await ctx.prompt(
`telegram:${botCtx.chat.id}`,
config.agentMapping.default,
botCtx.message.text
);
// Response is sent back via the channel adapter
});
await bot.start();
},
async stop() {
await bot.stop();
},
};
}