messages.downloadAttachmentUrl()

Retrieve an attachment's URL using messageId and attachmentId, which is useful for image attachments.

To tell if an attachment is an image, use:

const message = ...
const attachment = message.attachments[0]
const isImage = attachment.contentType.indexOf('image/') === 0

Definition

client.messages.downloadAttachmentUrl(
messageId: string|Message,
attachmentId: string|number
):Promise<string,Error>

Parameters

ParameterTypeDescription
messageIdstring|MessageMessage ID
attachmentIdstring|numberAttachment ID

Response

An error will be thrown if any of the arguments are invalid.

Otherwise, once the returned Promise is resolved, you will have access to the attachment URL as a string

Example

const url = await client.messages.downloadAttachmentUrl(
message.id,
message.attachments[0].id
);
console.log('attachment URL is', url);

In your HTML (After making sure the URL is of an image attachment):

<img src="URL goes here" alt="attachment-image">