Personalize the user details panel
Add your own data about a user, such as their orders or loyalty tier, to the Details panel of their conversations in Conversations. You attach the data and a web component that renders it to the user record through the Management API. Operators then see that business context next to the chat.
How the panel renders your widgets
Open a conversation in Conversations and select Details in its header. The panel shows the conversation's User, Touchpoint, Status, Sentiment, Started, Last message, Messages, ID, Topics, and Summary.
Below those fields, it renders the widgets of the user behind the conversation. Two fields of the user record drive them:
| Field | Type | Purpose |
|---|---|---|
context | JSON object | The data: any keys and values, such as loyaltyTier or orders |
contextConfiguration.widgets | List | The widgets that display the data |
Each widget is a custom element defined by a script you host. A widget definition has:
tagName: the custom element to create, such asorders-list.url: the script that defines the element.inputs: the properties to set. For each{ "name": "orders" }, the panel sets the element'sordersproperty tocontext.orders. The optionaltypeis a hint and isn't checked.
For each widget, the panel loads the script unless an element with that tag is already defined, creates the element, sets its inputs, and appends it to the panel. Your component decides how the data looks.
A conversation with an anonymous visitor has no user record, so it shows no widgets.
Before you begin
- Update on the Users row of your role, or an administrator account. See Manage roles and users.
- An API key. See Access Rational AI via API.
- The ID of the user to personalize, and their current given and family names.
- A place to host a JavaScript file that operators' browsers can load over HTTPS.
The widget script runs inside the Control Room page, with the session of the operator who opens the conversation. Load only scripts you control.
Build the widget
-
Write a custom element that reads its data from a property. This one renders an
ordersarray:// orders-list.js
class OrdersList extends HTMLElement {
// The panel sets this property from context.orders
set orders(value) {
this._orders = value ?? [];
this.render();
}
render() {
this.innerHTML = `
<h2>Recent orders</h2>
<ul>
${this._orders.map((o) => `<li>${o.name} (<code>${o.sku}</code>)</li>`).join("")}
</ul>`;
}
}
customElements.define("orders-list", OrdersList); -
Host the file, for example at
https://cdn.example.com/widgets/orders-list.js.
A custom element's name must contain a hyphen and be unique on the page. If two widgets use the same tag, the panel loads only the first script and both render with it.
Attach the data and the widget to the user
Send PUT /api/management/v0/users/{id} with the user's names, the data in context, and the widget in contextConfiguration:
curl -X PUT "https://control-room.example.com/api/management/v0/users/$USER_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"givenName": "Jane",
"familyName": "Doe",
"context": {
"loyaltyTier": "Gold",
"orders": [
{ "name": "Paracetamolo", "sku": "FA-4294953" },
{ "name": "Ibuprofene", "sku": "FA-1485914" }
]
},
"contextConfiguration": {
"widgets": [
{
"tagName": "orders-list",
"url": "https://cdn.example.com/widgets/orders-list.js",
"inputs": [{ "name": "orders", "type": "array" }]
}
]
}
}'
The three fields are updated differently:
givenNameandfamilyNameare required and replace the stored names. Send the current names to keep them.contextis merged: the keys you send are added or replaced, and the other stored keys stay.contextConfigurationis replaced. Send the full list of widgets every time. Leaving the field out removes every widget.
The next time an operator opens a conversation with this user, the orders-list widget appears at the bottom of the Details panel.
Troubleshooting
| Symptom | What to check |
|---|---|
| Only the built-in fields show | The user has no contextConfiguration.widgets, or the conversation is anonymous. |
| The widget renders but is empty | The inputs names don't match keys in context, or the keys weren't sent. |
| The widget never appears | The url failed to load, or the script doesn't define the declared tagName. The browser console shows "Failed to load widget" with the tag name. |
| Widgets disappeared after an update | The update left out contextConfiguration, or sent only some widgets. It is replaced, not merged. |
| The user's name changed after an update | The request sent other values in givenName and familyName. |
Next steps
- Access Rational AI via API: API keys and authentication.
- Conversations: what operators do in Conversations.