Chat / Android
Chat Android v4
Chat Android
Chat
Android
Version 4
Home
/
Chat
/
Android
/
Message

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.

// Creates a scheduled user message after 5 minutes.
val params = ScheduledUserMessageCreateParams(
    scheduledAt = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5)
).apply {
    message = "Text message"
    translationTargetLanguages = listOf("en", "ko")
    data = null
    customType = null
    mentionType = MentionType.USERS
    mentionedUserIds = listOf(MENTIONED_USER_ID)
    metaArrays = null
    appleCriticalAlertOptions = null
    pushNotificationDeliveryOption = null
}

// The returned message is a pending message instance for the scheduled message.
// It can be used in the same way as pending message from channel.sendUserMessage().
val pendingScheduledUserMessage = groupChannel.createScheduledUserMessage(params) { scheduledUserMessage, e ->
    if (e != null) {
        // Handle error.
    }

    // A user message has been successfully scheduled.
    // scheduledUserMessage.scheduledInfo will contain scheduled information.
    // scheduledUserMessage.sendingStatus will be SendingStatus.SCHEDULED.
}

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

// Create a scheduled file message.
val params = ScheduledFileMessageCreateParams(
    scheduledAt = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5)
).apply {
    // Set `fileUrl` or `file` exclusively.
    fileUrl = FILE_URL
    file = FILE
    
    fileName = "Name of the file"
    mimeType = MIME_TYPE
    fileSize = FILE_SIZE
    thumbnailSizes = listOf(ThumbnailSize(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT))
    data = null
    customType = null
    mentionType = MentionType.USERS
    mentionedUserIds = listOf(MENTIONED_USER_ID)
    metaArrays = null
    appleCriticalAlertOptions = null
    pushNotificationDeliveryOption = null
}

// The returned message is a pending message instance for the scheduled message.
// It can be used in the same way as pending message from channel.sendFileMessage().
val pendingScheduledFileMessage = groupChannel.createScheduledFileMessage(params) { scheduledFileMessage, e ->
    if (e != null) {
        // Handle error.
    }

    // A file message has been successfully scheduled.
    // scheduledUserMessage.scheduledInfo will contain scheduled information.
    // scheduledUserMessage.sendingStatus will be SendingStatus.SCHEDULED.
}