diff --git a/packages/client-telegram/src/index.ts b/packages/client-telegram/src/index.ts index b702c7e2d5..44e2432169 100644 --- a/packages/client-telegram/src/index.ts +++ b/packages/client-telegram/src/index.ts @@ -7,6 +7,7 @@ export const TelegramClientInterface: Client = { const botToken = runtime.getSetting("TELEGRAM_BOT_TOKEN"); const tg = new TelegramClient(runtime, botToken); await tg.start(); + elizaLogger.success( `✅ Telegram client successfully started for character ${runtime.character.name}` ); @@ -17,4 +18,4 @@ export const TelegramClientInterface: Client = { }, }; -export default TelegramClientInterface; +export default TelegramClientInterface; \ No newline at end of file diff --git a/packages/client-telegram/src/messageManager.ts b/packages/client-telegram/src/messageManager.ts index 0dd1e121fc..981553037f 100644 --- a/packages/client-telegram/src/messageManager.ts +++ b/packages/client-telegram/src/messageManager.ts @@ -130,7 +130,7 @@ Note that {{agentName}} is capable of reading/seeing/hearing various forms of me ` + messageCompletionFooter; export class MessageManager { - private bot: Telegraf; + public bot: Telegraf; private runtime: IAgentRuntime; private imageService: IImageDescriptionService; @@ -482,4 +482,4 @@ export class MessageManager { console.error("Error sending message:", error); } } -} +} \ No newline at end of file diff --git a/packages/client-telegram/src/telegramClient.ts b/packages/client-telegram/src/telegramClient.ts index 6d729746d6..28e3bde130 100644 --- a/packages/client-telegram/src/telegramClient.ts +++ b/packages/client-telegram/src/telegramClient.ts @@ -15,39 +15,6 @@ export class TelegramClient { this.bot = new Telegraf(botToken); this.messageManager = new MessageManager(this.bot, this.runtime); - elizaLogger.log("Setting up message handler..."); - this.bot.on("message", async (ctx) => { - try { - elizaLogger.log("📥 Received message:", ctx.message); - await this.messageManager.handleMessage(ctx); - } catch (error) { - elizaLogger.error("❌ Error handling message:", error); - await ctx.reply( - "An error occurred while processing your message." - ); - } - }); - - // Handle specific message types for better logging - this.bot.on("photo", (ctx) => { - elizaLogger.log( - "📸 Received photo message with caption:", - ctx.message.caption - ); - }); - - this.bot.on("document", (ctx) => { - elizaLogger.log( - "📎 Received document message:", - ctx.message.document.file_name - ); - }); - - this.bot.catch((err, ctx) => { - elizaLogger.error(`❌ Telegram Error for ${ctx.updateType}:`, err); - ctx.reply("An unexpected error occurred. Please try again later."); - }); - elizaLogger.log("✅ TelegramClient constructor completed"); } @@ -60,7 +27,51 @@ export class TelegramClient { elizaLogger.log( "✨ Telegram bot successfully launched and is running!" ); - elizaLogger.log(`Bot username: @${this.bot.botInfo?.username}`); + + await this.bot.telegram.getMe().then((botInfo) => { + this.bot.botInfo = botInfo; + }); + + console.log(`Bot username: @${this.bot.botInfo?.username}`); + + this.messageManager.bot = this.bot; + + // Include if you want to view message maanger bot info + // console.log(`Message Manager bot info: @${this.messageManager.bot}`); + + elizaLogger.log("Setting up message handler..."); + + this.bot.on("message", async (ctx) => { + try { + console.log("📥 Received message:", ctx.message); + await this.messageManager.handleMessage(ctx); + } catch (error) { + elizaLogger.error("❌ Error handling message:", error); + await ctx.reply( + "An error occurred while processing your message." + ); + } + }); + + // Handle specific message types for better logging + this.bot.on("photo", (ctx) => { + elizaLogger.log( + "📸 Received photo message with caption:", + ctx.message.caption + ); + }); + + this.bot.on("document", (ctx) => { + elizaLogger.log( + "📎 Received document message:", + ctx.message.document.file_name + ); + }); + + this.bot.catch((err, ctx) => { + elizaLogger.error(`❌ Telegram Error for ${ctx.updateType}:`, err); + ctx.reply("An unexpected error occurred. Please try again later."); + }); // Graceful shutdown handlers const shutdownHandler = async (signal: string) => { @@ -93,4 +104,4 @@ export class TelegramClient { await this.bot.stop(); elizaLogger.log("Telegram bot stopped"); } -} +} \ No newline at end of file