Skip to content

Commit

Permalink
handle http image
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 committed Dec 19, 2024
1 parent e47b1d9 commit cd5fc2f
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,22 +622,34 @@ export class MessageManager {
caption?: string
): Promise<void> {
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);
Expand Down

0 comments on commit cd5fc2f

Please sign in to comment.