Not able to add friendly name to participants when creating participant with conversation

659 Views Asked by At

I am using twilio for creating an chat API using conversion API (Twilio), I was able to create the converstaion and add new participant to the converstion, But when I try to add friendly name to participant, Its not adding.

client.conversations.conversations(conversionsSID)
   .participants
     .create({
        identity: identity,
        FriendlyName: name,
        attributes: JSON.stringify({
        profileImage: profileImage
     })
   }).then((participant) => {
      resolve({ participant: participant, error: null })
   }).catch((error) => {
      reject({ participant: null, error: error });
   });

I have tried with FriendlyName and friendly_name, both of that does't work.

2

There are 2 best solutions below

2
On

The participant resource does not have a FriendlyName property. You can see the available properties that you can use in the documentation for creating a conversation participant.

You are already using the attributes property to store a profile image, so you could use this to store your friendly name too. So, you could change your code to:

client.conversations.conversations(conversionsSID)
   .participants
     .create({
       identity: identity,
       attributes: JSON.stringify({
         name: name,
         profileImage: profileImage
       })
     }).then((participant) => {
       resolve({ participant: participant, error: null })
     }).catch((error) => {
       reject({ participant: null, error: error });
     });
0
On

You can do like this:

At first CreateConversation after that call update to the user

Client.conversations.users("US1f1ff79756794a28b55fbb1c8ac2b150").fetch().then((user) => {
    user.update({ friendlyName: "r2d2" })
      .then()
      .catch(error => {
        console.log(error);
      });
  });

cheers!