Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
Message
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Create a scheduled message

You can create a scheduled user message to send at a later time by passing ScheduledUserMessageCreateParams as an argument to the createScheduledUserMessage() method.

// Create a scheduled user message.
const params: ScheduledUserMessageCreateParams = {
  message: 'Off work, WOOHOO!',
  scheduledAt: TODAY_AT_SIX_PM,
};
channel.createScheduledUserMessage(params)
  .onPending((message: SendableMessage) => {
    // Pending scheduled message is received.
  })
  .onSucceeded((message: SendableMessage) => {
    // Scheduled message is received.
  })
  .onFailed((err: Error, message: SendableMessage) => {
    // An error is received. Failed message is null.
  });
const handler: GroupChannelHandler = new GroupChannelHandler();
handler.onMessageReceived = (channel: BaseChannel, message: BaseMessage) => {
  // Sent scheduled message is received.
};
sb.groupChannel.addGroupChannelHandler('groupChannelHandler', handler);

ScheduledUserMessageCreateParams

interface ScheduledUserMessageCreateParams extends UserMessageCreateParams {
  scheduledAt: number;
}

You can create a scheduled file message to send at a later time by passing ScheduledFileMessageCreateParams as an argument to the createScheduledFileMessage() method.

// Creates a scheduled file message.
const params: ScheduledFileMessageCreateParams = {
  file: FILE,
  scheduledAt: TODAY_AT_SIX_PM,
};
channel.createScheduledFileMessage(params)
  .onPending((message: SendableMessage) => {
    // Pending scheduled message is received.
  })
  .onSucceeded((message: SendableMessage) => {
    // Scheduled message is received.
  })
  .onFailed((err: Error, message: SendableMessage) => {
    // An error is received. Failed message is null.
  });
const handler: GroupChannelHandler = new GroupChannelHandler();
handler.onMessageReceived = (channel: BaseChannel, message: BaseMessage) => {
  // Sent scheduled message is received.
};
sb.groupChannel.addGroupChannelHandler('groupChannelHandler', handler);

ScheduledFileMessageCreateParams

interface ScheduledFileMessageCreateParams extends FileMessageCreateParams {
  scheduledAt: number;
}