Twilio conversation JS SDK - a proper way of fetching user conversations

1.1k views Asked by At

I'm trying to display all user's conversations sorted by last message creation date and I'm a little bit confused.

I see getSubscribedConversation method in docs (https://media.twiliocdn.com/sdk/js/conversations/releases/1.1.0/docs/Client.html#getSubscribedConversations__anchor) but it says nothing about page size and sorting. It returns paginator so I assume it doesn't return all conversations at once.

On the other hand I see some examples in twilio github projects where conversations are added to the list only by listening for conversationAdded event (which indeed fires even for previously created conversations) but it doesn't seem like a clean solution - if user belongs to 50 conversation then I should handle every single event and rerender the list 50 times?

To sum up, I have following questions:

  1. Does getSubscribedConversation returns all user's conversations at once?
  2. If no, then what is default page size and is it possible to change it (together with sorting)
  3. If getSubscribedConversation return paginator indeed - wouldn't it break if I add conversation from conversationAdded event in the meantime?
1

There are 1 answers

3
babycourageous On BEST ANSWER

I can't answer all your questions but I can give some insight on a couple -

From what I can tell, getSubscribedConversations returns 50 Conversations. I have not found a way to change that limit or sort it (I'm not entirely sure in what order Twilio returns them even).

For a project I'm working on we need Conversations sorted in order of recent message. The way I'm currently dealing with it is by storing the most recent message on an attribute on the Conversation. I also initialize the app by loading all the conversations with a recursive function.

Hope that sheds some light for you.