/ SDKs / JavaScript
SDKs
Chat SDKs JavaScript v4
Chat SDKs JavaScript
Chat SDKs
JavaScript
Version 4

Create a scheduled message

Copy link

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

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

ScheduledUserMessageCreateParams

Copy link
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.

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

ScheduledFileMessageCreateParams

Copy link
interface ScheduledFileMessageCreateParams extends FileMessageCreateParams {
  scheduledAt: number;
}