Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/meteor/app/livechat/imports/server/rest/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ const getUploadFile = async (details: Omit<IUpload, '_id'>, fileUrl: string) =>
throw new Meteor.Error('error-invalid-url', 'Invalid URL');
}

const response = await fetch(fileUrl, { redirect: 'error' });
// Follow redirects to support Twilio media URLs that redirect to actual media location
const response = await fetch(fileUrl, { redirect: 'follow' });

const content = Buffer.from(await response.arrayBuffer());

const contentSize = content.length;

if (response.status !== 200 || contentSize === 0) {
logger.warn(`Failed to fetch file from ${fileUrl}: status ${response.status}, size ${contentSize}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really want to have this log, change it to be an object instead of templates

logger.error({ msg: 'Failed to fetch file', fileUrl, status: response.status, contentSize });

throw new Meteor.Error('error-invalid-file-uploaded', 'Invalid file uploaded');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ export class Twilio implements ISMSProvider {
returnData.media.push(media);
}

// Append media URLs to the message body for better visibility
if (returnData.media.length > 0) {
const links = returnData.media
.map((media) => media.url)
.filter((url) => !!url) // skip empty URLs
.join('\n');

returnData.body = [returnData.body, links].filter(Boolean).join('\n');
}

Comment on lines +102 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this.

Suggested change
// Append media URLs to the message body for better visibility
if (returnData.media.length > 0) {
const links = returnData.media
.map((media) => media.url)
.filter((url) => !!url) // skip empty URLs
.join('\n');
returnData.body = [returnData.body, links].filter(Boolean).join('\n');
}

return returnData;
}

Expand Down
Loading