From cd5fc2f6599feef9a7efbe71bb39034a32991015 Mon Sep 17 00:00:00 2001 From: Ting Chien Meng Date: Wed, 18 Dec 2024 19:25:30 -0500 Subject: [PATCH] handle http image --- .../client-telegram/src/messageManager.ts | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/client-telegram/src/messageManager.ts b/packages/client-telegram/src/messageManager.ts index 68b710c2a9f..99a2212a30b 100644 --- a/packages/client-telegram/src/messageManager.ts +++ b/packages/client-telegram/src/messageManager.ts @@ -622,22 +622,34 @@ export class MessageManager { caption?: string ): Promise { try { - if (!fs.existsSync(imagePath)) { - throw new Error(`File not found: ${imagePath}`); - } - - const fileStream = fs.createReadStream(imagePath); - - await ctx.telegram.sendPhoto( - ctx.chat.id, - { - source: fileStream, - }, - { - caption, + if (/^(http|https):\/\//.test(imagePath)) { + // Handle HTTP URLs + await ctx.telegram.sendPhoto( + ctx.chat.id, + imagePath, + { + caption, + } + ); + } else { + // Handle local file paths + if (!fs.existsSync(imagePath)) { + throw new Error(`File not found: ${imagePath}`); } - ); - + + const fileStream = fs.createReadStream(imagePath); + + await ctx.telegram.sendPhoto( + ctx.chat.id, + { + source: fileStream, + }, + { + caption, + } + ); + } + elizaLogger.info(`Image sent successfully: ${imagePath}`); } catch (error) { elizaLogger.error("Error sending image:", error);