Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Twilio + NodeJS how to check efficiently if two users have participated in a conversation together

I am trying to query Twilio to see if 2 users have ever engaged in a conversation. I query conversations.user.userConversations to get a list of conversations the primary user has been in, then i filter that list to check where the participantSid of the main user in any of their conversations matches the sid of the participant user.

My function doesnt work, why?

const checkForExistingConversations = async (loggedInUserSid, participantUserSid) => 

{
  let existingConversations = await client.conversations.users(loggedInUserSid)
      .userConversations
      .list()
  existingConversations.filter((convo) =>  convo.participantSid === participantUserSid)  // here is the issue
  return existingConversations
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The filter method does not mutate the array, but returns a new one, so your function should look like this:

const checkForExistingConversations = async (loggedInUserSid, participantUserSid) => 
{
  let existingConversations = await client.conversations.users(loggedInUserSid)
      .userConversations
      .list()
  return existingConversations.filter((convo) =>  convo.participantSid === participantUserSid)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading