Messaging

This section highlights the steps you will need to follow to begin integrating chat messaging into your products

The message payload is always the same regardless of which Development Kit the user is using. Users also have a choice on what type of message they want to send.‌

Major API simplification

We rewrote the message repository from the ground up, deprecating the old code but keeping it working. If you don't want to refactor your code just yet, don't worry, you can still upgrade just fine.

declare class MessageRepository {
	static getMessage(messageId: string): LiveObject

  static queryMessages(parameters: {
    channelId?: string,
    type?: string,
    parentId?: string | null,
    filterByParentId?: boolean,
    isDeleted?: boolean,
    tags?: string[],
    excludeTags?: string[],
  }): LiveCollection

  static createMessage(parameters: {
    channelId: string,
    type: string,
    data?: Object,
    fileId?: string,
    parentId?: string,
    tags?: string[],
    metadata?: Object,
    mentionees?: Array<{ type: string, userIds?: string[] }>,
  }): LiveObject

  static createTextMessage(parameters: {
    channelId: string,
    text: string,
    parentId: string,
    tags: string[],
    metadata: Object,
    mentionees?: Array<{ type: string, userIds?: string[] }>,
  }): LiveObject

  static createImageMessage(parameters: {
    channelId: string,
    caption: string,
    imageId: string,
    parentId: string,
    tags: string[],
    metadata: Object,
  }): LiveObject

  static createFileMessage(parameters: {
    channelId: string,
    caption: string,
    fileId: string,
    parentId: string,
    tags: string[],
    metadata: Object,
  }): LiveObject

  static async updateMessage(parameters: {
    messageId: string,
    data?: Object,
    tags?: string[],
    metadata?: Object,
    mentionees?: Array<{ type: string, userIds?: string[] }>,
  }): Promise<boolean>

  static async deleteMessage(messageId: string): Promise<boolean>

  static async addReaction(parameters: {
    messageId: string,
    reactionName: string,
  }): Promise<boolean>

  static async removeReaction(parameters: {
    messageId: string,
    reactionName: string,
  }): Promise<boolean>

  static async flag(messageId: string | { messageId: string }): Promise<boolean>

  static async unflag(messageId: string | { messageId: string }): Promise<boolean>

  static async isFlaggedByMe(messageId: string | { messageId: string }): Promise<boolean>

  @deprecated
  constructor()

  @deprecated
  messagesForId(messageId: string): LiveObject

  @deprecated
  messagesForChannel({
    channelId: string,
    tags?: Array<string>,
    parentId?: string,
    filterByParentId?: boolean,
  }): LiveCollection

  @deprecated
  createTextMessage({
    channelId: string,
    text: string,
    tags: Array<string>,
    parentId?: string,
  }): LiveObject

  @deprecated
  async addReaction(parameters: {
    messageId: string,
    reactionName: string,
  }): Promise<boolean>

  @deprecated
  async removeReaction(parameters: {
    messageId: string,
    reactionName: string,
  }): Promise<boolean>

  @deprecated
  async flag(messageId: string): Promise<boolean>

  @deprecated
  async unflag(messageId: string): Promise<boolean>
}

@deprecated
declare class MessageEditorRepository {
  get messageId(): string

  constructor(messageId: string)

  async editText(text: string): Promise<void>

  async delete(): Promise<void>
}

@deprecated
declare class MessageFlagRepository {
  get messageId(): string

  get privileges(): string[]

  constructor(messageId: string)

  async flag(): Promise<void>

  async unflag(): Promise<void>

  async isFlaggedByMe(): Promise<boolean>
}

List of corresponding methods

Before Refactoring

After Refactoring

messageRepo.messageForId

MessageRepository.getMessage

messageRepo.messagesForChannel

MessageRepository.queryMessages

messageRepo.createTextMessage

MessageRepository.createTextMessage

messageRepo.addReaction

MessageRepository.addReaction

messageRepo.removeReaction

MessageRepository.removeReaction

messageRepo.flag

MessageRepository.flag

messageRepo.unflag

MessageRepository.unflag

editRepo.editText

MessageRepository.updateMessage

editRepo.delete

MessageRepository.deleteMessage

flagRepo.flag

MessageRepository.flag

flagRepo.unflag

MessageRepository.unflag

flagRepo.isFlaggedByMe

MessageRepository.isFlaggedByMe

Message Description

Name

Data Type

Description

Attributes

messageId

string

The id of this message

​Content

parentId

string

The messageId of the parent of this message

​Content

childrenNumber

integer

The number of messages with parentId of this message

​Content

channelId

string

The name of the channel this message was created in

​Content

userId

string

The name of the user this message was created by

​Content

type

string

The message type

enum*: text custom image file

tags

Array.<string>

The message tags

​Content

data

Object

The message data (any text will be stored in text key)

text: Text message

isDeleted

boolean

The message has been marked as deleted

​Content

channelSegment

integer

The sequence number of a message in channel

​Content

createdAt

date

The date/time the message was created at

​Content

updatedAt

date

The date/time the message was updated at

​Content

editedAt

date

The date/time the message was edited at

​Content

flagCount

integer

The number of users that have flagged this message

​Content

hashFlag

Object

A hash for checking internally if this message was flagged by the user

​Content

reactions

Object

The reaction data (stored as a reactionName and counter key/value pair)

Example: { like: 1, dislike: 2 }

reactionsCount

integer

The total number of reactions on this message

​Content

myReactions

Array.<string>

List of user's reactions on this message

​Content

mentionees

Array.<Object>

List of mentionees

Example: [{ type: 'channel' }, { type: 'user', userIds: 'userId1', 'userId2' }]

Messages are JSON content containers that can have up to 20,000 characters or can weigh up to 100KB for custom messages. They will be synchronized among all channel users in real-time. If a message requires larger binary data (such as when sending files), we recommend to upload the data to another cloud storage service, such as AWS S3, and store the URL to the content in the message data.

In addition the JSON message type, the SDK also provides support for common text and image message types. These additional types are built on top of the standard JSON message layer.

In case of image messages, the SDK freely provides a cloud storage service that will process and store all images uploaded: you don't need to setup and manage a separate cloud storage service for this common case.

All messaging methods are contained in a MessageRepository class. Before calling any messaging methods, you must ensure to first instantiate a repository instance using the ASCClient instance you created on setup.

import { MessageRepository } from '@amityco/js-sdk';
const messageRepo = new MessageRepository();

Last updated