Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Conversations Attributes



Overview

overview page anchor

The attributes property unlocks the potential to add additional context about specific objects. You can use this functionality to build many capabilities into your application. Some common use cases you could build are:

  • Skill-based routing for Conversations
  • Avatar URLs in a User profile
  • Context about customers (i.e. referral source, product type, etc.)
  • Message replies/threading
  • Emoji reactions to messages
  • Profile information
  • Message metadata
  • Customer loyalty status
  • Non-chat Participant display name

This property is optional, and the field value is a JSON object that can store up to 16 KB depending on the object. If the attributes are not set, then an empty object is returned.

You can use the attributes field in any of the following Conversations objects:

  • Participant (up to 4 KB)
  • User (up to 16 KB)
  • Conversation (up to 16 KB)
  • Message (up to 4 KiB)

Refer to Conversations length limits(link takes you to an external page) for more details.


Set or modify Attributes

set-or-modify-attributes page anchor

You can set the attributes of an object by calling the update method on the object you want to add to. For example, you can add attributes to an existing Message by passing the correct method and specifying the attributes on that Message object.

You can also add attributes to objects when you create them. For example, you can set attributes when you add a Participant to a Conversation.

To retrieve the attributes for an object, just make sure to invoke the corresponding method or property. The attributes will be returned in JSON format.

Set or Modify Attributes

set-or-modify-attributes-1 page anchor
Node.js
Typescript

_24
/* Using Attributes */
_24
_24
// add attributes to a message
_24
const message = await conversation.prepareMessage().setBody("message text");
_24
_24
await conversation.setAttributes("attribute");
_24
await conversation.setAttributes(2);
_24
await conversation.setAttributes(true);
_24
await conversation.setAttributes({attributeKey: "attributeValue"});
_24
await conversation.setAttributes(["attribute", "anotherAttribute"]);
_24
_24
// get the attributes
_24
const messageAttributes = message.attributes;
_24
_24
// add participant to the conversation with attributes
_24
await conversation.add("identity", "attribute");
_24
await conversation.add("identity", 2);
_24
await conversation.add("identity", true);
_24
await conversation.add("identity", {attributeKey: "attributeValue"});
_24
await conversation.add("identity", ["attribute", "anotherAttribute"]);
_24
_24
// get the attributes
_24
const participant = await conversation.getParticipantByIdentity("identity");
_24
const participantAttributes = participant.attributes;


Listen for changes to these objects

listen-for-changes-to-these-objects page anchor

To receive events about updates to object attributes, listen for "update" events at the Client object (e.g. conversationUpdated, messageUpdated, etc.). The event update reason will indicate that the attributes were changed and include the updated object.


Well done! You can continue learning more about Conversations by checking out the following guides:


Rate this page: