0

I am trying to create a "conversation history" page on my app, where you see the "participant's" name and the last message of the conversation (see attached image). I understand the image would have to come from another database.

I have most recently tried the following

  1. Get a list of existing conversations for the logged in user using client.conversations.users.userConversations.list()

  2. Iterate over the number of conversations, and get the last message from each conversation and get participant data

participant = client.conversations.conversations(existingConversationSidAtIndex.conversationSid).messages.list({limit: 1})

AND

client.conversations.users(participant.accountSid).fetch()
  1. Map over those two datasets and merge the participant data with the last message data

There must be a more efficient way?

card

IWI
  • 1,528
  • 4
  • 27
  • 47

1 Answers1

2

Twilio developer evangelist here.

I think you have the way to do this with the API correct. You likely have 2 options here to make things more efficient/performant.

  1. Cache the data in your own database so you don't have to look it up from the API every time.

  2. Get this data in the front end of your application using the Conversations SDK.

philnash
  • 70,667
  • 10
  • 60
  • 88