File Message

To create a file message, you need to leverage the FileRepository. Create a file and pass the file ID into the createFileMessage later on. This method also accepts an optional caption parameter to be able to display additional text with the message. You can add up to 1,000 characters of text caption per message.

Here's a small example on how to create a message with an image attached. The process is pretty simple:

  1. Upload a file.

  2. Create a message with the uploaded file ID.

import { MessageRepository, MessageType  } from '@amityco/js-sdk';

// this function takes in input a File from a <input type="file" />
const createFileMessage = (file: File) => {
  // first, create the file object.
  const liveFile = FileRepository.createFile({ file })

  // second, create the message object with the fileId from the liveFile
  const liveMessage = MessageRepository.createFileMessage({
    channelId: 'my-channel',
    fileId: id, // id of the file created with FileRepository.createFile
    caption: 'have a look!',
    tags: ['tag1', 'tag2'],
  })
}

Last updated