Threads & Replies

Last Edit: Jun 06 2020

Threads and replies provide your users with a way to go into more detail about a specific topic.

This can be very helpful to keep the conversation organized and reduce noise. To create a thread you simply send a message with a parent_id. Have a look at the example below:


const reply = await channel.sendMessage({
    text: 'Hey, I am replying to a message!',
    parent_id: parentID,
    show_in_channel: false,
});
                    

// set the parent id to make sure a message shows up in a thread
Message message = new Message();
message.setText("hello world");
message.setParentId(parentMessage.getId());

// send the message to the channel
channel.sendMessage(message, new MessageCallback() {
    @Override
    public void onSuccess(MessageResponse response) {
        
    }

    @Override
    public void onError(String errMsg, int errCode) {

    }
});
                    

let channel = Client.shared.channel(type: .messaging, id: "general")
let message = Message(text: "Hello!")
let replyMessage = Message(parentId: message.id, text: "What's up?")
channel.send(message: replyMessage) { (result) in
    // handle result
}
                    

// set the parent id to make sure a message shows up in a thread
val parentMessage = Message()
val message = Message()
message.text = "hello world"
message.parentId = parentMessage.id

// send the message to the channel
channelController.sendMessage(message).enqueue { 
    val message = it.data()
}
                    

$response = $channel->sendMessage([
		'text' => 'Hey, I am replying to a message!',
		'parent_id' => 'parent-id',
		'show_in_channel' => false
		], 
		'jenny'
	);
                    
If you specify show_in_channel, the message will be visible both in a thread of replies as well as the main channel.

Messages inside a thread can also have reactions, attachments and mention as any other message.

Thread Pagination

When you read a channel you do not receive messages inside threads. The parent message includes the count of replies which it is usually what apps show as the link to the thread screen. Reading a thread and paginating its messages works in a very similar way as paginating a channel.


// retrieve the first 20 messages inside the thread
await channel.getReplies(parentMessageId, {limit: 20});

// retrieve the 20 more messages before the message with id "42"
await channel.getReplies(parentMessageId, {limit: 20, id_lte: "42"});
                    

val limit = 20
// retrieve the first 20 messages inside the thread
client.getReplies(parentMessageId, limit).enqueue {
    val replies = it.data()
}
// retrieve the 20 more messages before the message with id "42"
client.getRepliesMore(parentMessageId, "42", limit).enqueue {
    val replies = it.data()
}
                    

let message = Message(text: "Hello!")
// retrieve the first 20 messages inside the thread
message.replies(pagination: [.limit(20)]) { (result) in
// handle result
}
    
// retrieve the 20 more messages before the message with id "42"
message.replies(pagination: [.lessThanOrEqual("42"), .limit(20)]) { (result) in /**/ }