3

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.

Akhil M
  • 544
  • 6
  • 8
  • Where in the documentation is friendlyName referred to, can you share the source you are referring to? https://www.twilio.com/docs/conversations/api/conversation-participant-resource#add-a-conversation-participant-sms – Alan Apr 02 '22 at 10:34

2 Answers2

1

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 });
     });
philnash
  • 70,667
  • 10
  • 60
  • 88
  • Yup we can use the attributes but the problem is that when we sent the notifications Twilio will use the friendly name in the notifications, Like You have a new message from . If there is no friendly name then it will use the identity(unique and should not be exposed). And when we try to add new user there is an option to add friendly name. Thanks for the support. – Akhil M Apr 04 '22 at 14:42
  • 1
    Ah, ok. The friendly name actually comes from the underlying [user resource](https://www.twilio.com/docs/conversations/api/user-resource) which is created automatically when you create a participant but can be created or updated by you too. That's the resource you can set a friendly name on. – philnash Apr 04 '22 at 21:30
0

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!

ealvess
  • 519
  • 5
  • 12