Skip to content

Commit cd5fc2f

Browse files
committed
handle http image
1 parent e47b1d9 commit cd5fc2f

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

packages/client-telegram/src/messageManager.ts

+27-15
Original file line numberDiff line numberDiff line change
@@ -622,22 +622,34 @@ export class MessageManager {
622622
caption?: string
623623
): Promise<void> {
624624
try {
625-
if (!fs.existsSync(imagePath)) {
626-
throw new Error(`File not found: ${imagePath}`);
627-
}
628-
629-
const fileStream = fs.createReadStream(imagePath);
630-
631-
await ctx.telegram.sendPhoto(
632-
ctx.chat.id,
633-
{
634-
source: fileStream,
635-
},
636-
{
637-
caption,
625+
if (/^(http|https):\/\//.test(imagePath)) {
626+
// Handle HTTP URLs
627+
await ctx.telegram.sendPhoto(
628+
ctx.chat.id,
629+
imagePath,
630+
{
631+
caption,
632+
}
633+
);
634+
} else {
635+
// Handle local file paths
636+
if (!fs.existsSync(imagePath)) {
637+
throw new Error(`File not found: ${imagePath}`);
638638
}
639-
);
640-
639+
640+
const fileStream = fs.createReadStream(imagePath);
641+
642+
await ctx.telegram.sendPhoto(
643+
ctx.chat.id,
644+
{
645+
source: fileStream,
646+
},
647+
{
648+
caption,
649+
}
650+
);
651+
}
652+
641653
elizaLogger.info(`Image sent successfully: ${imagePath}`);
642654
} catch (error) {
643655
elizaLogger.error("Error sending image:", error);

0 commit comments

Comments
 (0)