Class ChatMessageBubble
One message in a chat conversation.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ChatMessageBubble : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The two roles look deliberately different. A User message is a filled, right-aligned bubble carrying the prompt text and, above it, whatever the message was sent with. A Assistant message has no bubble at all: its content runs flush with the conversation so long answers do not sit inside a box.
Four containers are exposed as slots. sentWith holds the context chips and file
pills the message was sent with, and only shows inside a user bubble. The content container
(what Add reaches) holds richer assistant content, for instance a
ChatActivityTimeline or a ChatTodoList. footer and
actions sit under the message, the latter typically holding a
ChatMessageActions row. Every slot collapses to nothing while it is empty, so
there is no state to keep in sync.
trimContent is opt-in on purpose: backends often pad prompt text, but the bubble must never mutate whitespace-sensitive caller content unless it is asked to. Internal newlines are always preserved.
Examples
A user message with an action row under it.
var message = new ChatMessageBubble
{
role = ChatMessageRole.User,
content = " Make the player jump higher ",
trimContent = true
};
message.actions.Add(new ChatMessageActions { content = message.content });
parentElement.Add(message);
An assistant message carrying an activity timeline under its answer.
var answer = new ChatMessageBubble
{
role = ChatMessageRole.Assistant,
content = "I raised the jump force to 8."
};
answer.Add(new ChatActivityTimeline());
parentElement.Add(answer);
In UXML. Children land in the content container.
<appui:ChatMessageBubble role="User" content="Hello" />
<appui:ChatMessageBubble role="Assistant" content="Hi there" />
Constructors
ChatMessageBubble()
Default constructor.
Declaration
public ChatMessageBubble()
Fields
actionsUssClassName
The styling class of the actions slot.
Declaration
public const string actionsUssClassName = "appui-chat-message-bubble__actions"
Field Value
| Type | Description |
|---|---|
| string |
bubbleUssClassName
The styling class of the bubble surface.
Declaration
public const string bubbleUssClassName = "appui-chat-message-bubble__bubble"
Field Value
| Type | Description |
|---|---|
| string |
containerUssClassName
The styling class of the content container.
Declaration
public const string containerUssClassName = "appui-chat-message-bubble__container"
Field Value
| Type | Description |
|---|---|
| string |
contentUssClassName
The styling class of the message text.
Declaration
public const string contentUssClassName = "appui-chat-message-bubble__content"
Field Value
| Type | Description |
|---|---|
| string |
footerUssClassName
The styling class of the footer slot.
Declaration
public const string footerUssClassName = "appui-chat-message-bubble__footer"
Field Value
| Type | Description |
|---|---|
| string |
roleUssClassName
The ChatMessageBubble role styling class.
Declaration
public const string roleUssClassName = "appui-chat-message-bubble--"
Field Value
| Type | Description |
|---|---|
| string |
sentWithUssClassName
The styling class of the "sent with" row.
Declaration
public const string sentWithUssClassName = "appui-chat-message-bubble__sent-with"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ChatMessageBubble main styling class.
Declaration
public const string ussClassName = "appui-chat-message-bubble"
Field Value
| Type | Description |
|---|---|
| string |
Properties
actions
The per-message action row, under everything else.
Declaration
public VisualElement actions { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
content
The message text.
Declaration
[CreateProperty]
[UxmlAttribute]
public string content { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Reading this back returns exactly what was set, not the trimmed rendering, so a caller can hand the same string to a copy action without it having been silently rewritten.
contentContainer
Richer message content, for instance an activity timeline or a todo list. This is what
Add reaches.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
footer
The slot under the message, before the actions.
Declaration
public VisualElement footer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
role
Who authored the message. Assistant by default.
Declaration
[CreateProperty]
[UxmlAttribute]
public ChatMessageRole role { get; set; }
Property Value
| Type | Description |
|---|---|
| ChatMessageRole |
sentWith
What the message was sent with: context chips and file pills. Only visible on a user message.
Declaration
public VisualElement sentWith { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
trimContent
Whether leading and trailing whitespace is trimmed from content before it is displayed. False by default. Internal newlines are always preserved.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool trimContent { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
GetRoleUssClassName(ChatMessageRole)
Declaration
public static string GetRoleUssClassName(ChatMessageRole enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ChatMessageRole | enumValue |
Returns
| Type | Description |
|---|---|
| string |