Find a conversation between user in Skygear Chat


I have a user list, when I click on a user I have the detail of it. and I want every time I click on send message I find our old post if possible


Hi, you can use getConversations to get a list of all conversations the current user involved with. And than you can loop through to find the conversations between users


yes, I have already done. but my problem is that every time I click on send message this create a new conversation instead of finding the conversation between the two


This sounds like a coding logic problem in your code base? Maybe you can post the relevant code here so we can help.

Logically, you shouldnā€™t have any code about ā€œcreate a new conversationā€ in send message.

const conversationOptions = {
      distinctByParticipants: true
    const conversationMeta = {
      received : this.nom_docteur
    const query = new skygear.Query(skygear.UserRecord);
    skygear.publicDB.query(query).then((records) => {
    const user = records[0];
    skygearChat.createConversation([user,], this.nom_docteur,conversationMeta, conversationOptions).then((conversation)=>{
    // a new direct conversation is created
      this.navCtrl.push("ChatDetailPage", conversation);
    console.log('Conversation created!', conversation);
    }).catch((err)=> {
    console.log('Failed to create conversation');
    }, (error) => {

my concern is that a times I click on send message this finds the subsequent messages between the two users


@arsene from the code you sent, it didnā€™t try to use getConversations() to find existing conversations, so it will create new conversation every time the code is run.

Take a look at Fetching existing conversations


time to try it !!! is there the parameter to put?


There are 3 parameters: getConversations(page: number, pageSize: number, includeLastMessage: boolean)

Reference here:


i use this code yet
let loading = this.loadingCtrl.create({
skygearChat.getConversations().then((data)=> {
this.conversation = data;ā€˜conversationā€™, this.conversation);
console.log(ā€˜All conversationsā€™, data);
}, function (err) {
console.log(ā€˜Failed to retrieve conversationsā€™);


my problem is to create when i click on send message in user profil


Hi @arsene, I hope I understand your need correctly (let me know if i am wrong :stuck_out_tongue_winking_eye:):

You want to make a send button so that when you click on it, you will see all the previous messages you sent to/received from the user.

If this is right, you need to do two things in the send button:

1. Create a conversation or get an existing conversation

In this step, you either use createConversation (with distinctByParticipant=true) or getConversation. The createConversation function is more convenient because if the conversation already exists, Skygear Chat will return an existing conversation to you, instead of creating a new one

2. Fetch messages in a conversation

Now that you have a conversation, you need to put that conversation to getMessages to fetch previous messages.


Here is an example, I hope it makes sense.

    console.log('Conversation created!', conversation);
    return skygearChat.getMessages(conversation, 10, new Date());
}).catch((err)=> {
    console.log('Failed to create conversation');
}).then((messages) => {
    console.log('previous messages', messages);


thank you for the answer @cheungpat , but it is the same thing as my previous code. but my concern is that if there is a conversation that exists we are referred to that


Sorry I misunderstood your question. If you want a new conversation (ignoring existing conversation), it is simple: donā€™t use distinctByParticipants=true

Your code will look something like:

const conversationOptions = {
  distinctByParticipants: false // or omit this altogether
// ...
skygearChat.createConversation([user,], this.nom_docteur,conversationMeta, conversationOptions)

You should use createConversation without distinctByParticipant=true. In this case a new conversation is always created, no matter the user you are talking to have a conversation with you already. In other words, ignore existing conversation and always create anew.

In this case, the user will not see messages from a previous conversation, because the conversation is a new one.


without lying to you, I do not find myself. Iā€™m waiting if there will be a follow up to this request


thank you for the assistance, I solve the problem. thank you