Skip to content

Attachment

Any type of file can be attached to a message. Images, files, videos, audio, and more.

Attachment object

The remoteStaticAttachment type contains the following

{
  data: Uint8Array; // the decoded data
  filename: string; // the filename
  mimeType: string; // the mime type
}

Receive an image

Now that you understand how images are represented, you can receive them in your app. Here's an example of how you can receive an image in your app:

const {
  message: {
    content: { attachment },
  },
} = context;
 
if (attachment && typeId === "remoteStaticAttachment") {
  const { data, filename, mimeType } = attachment;
  // Parse the data to a base64 string
  const base64Image = Buffer.from(data).toString("base64");
  // Get the data URL in base64
  const dataUrl = `data:image/jpeg;base64,${base64Image}`;
}