Message

<sl-message> | SlMessage
Since 2.5.0 experimental

Short summary of the component’s intended use.

<sl-message></sl-message>

Examples

User message

The avatar is positioned top right as an anchor for the message content. The avatar is optional and may be toggled off depending on the context.

The avatar is placed in the top right to anchor the message content when there are two or more lines.
<sl-message user-initials="FL" >
  <span slot="user-message">The avatar is placed in the top right to anchor the message content when there are two or more lines.</span>
</sl-message>

Agent message

The AI logomark is positioned top left as an anchor for the message content. Displaying the AI logomark is optional and may be toggled off depending on the context.

Displaying the AI name is also optional and is off by default.

The avatar is placed in the top right to anchor the message content when there are two or more lines. The avatar is placed in the top right to anchor the message content when there are two or more lines.
<sl-message type="agent">
  <span slot="agent-message">The avatar is placed in the top right to anchor the message content when there are two or more lines.</span>
</sl-message>

<sl-message
  type="agent"
  show-agent-label
  agent-label="AI agent"
>
<span slot="agent-message">The avatar is placed in the top right to anchor the message content when there are two or more lines.</span>
</sl-message>

Agent message responses

Agent message responses can include text, images, tables or other forms of content display.

Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim. This is just a basic card. No image, no header, and no footer. Just your content.
<sl-message type="agent" >
  <span slot="agent-message">Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.</span>
  <sl-card class="card-basic">
    This is just a basic card. No image, no header, and no footer. Just your content.
  </sl-card>
</sl-message>

Fallback message responses

You can add fallback messages to the user-message and agent-message attributes. If not, we also have preset fallback message content.

<sl-message type="user">
</sl-message>

<sl-message type="agent">
</sl-message>

<sl-message type="user" user-message="A sample prompt from the user.">
</sl-message>

<sl-message type="agent" agent-message="A message from your agent.">
</sl-message>

User message & agent message (both in context)

When the agent returns plain text responses, that means a canned response (displayed as a card) is not available.

The AI loader returns to it’s resting state (AI logomark) when a full plain text response has completed generating. The user message aligns right when placed in context of a conversational container and will display before generated responses in the conversation.

AI loader is currently working in progress. The agent logomark will be replaced with AI loader soon.

The avatar is placed in the top right to anchor the message content when there are two or more lines. Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.
<sl-message
  type="user-agent"
  agent-message="Plain text."
  user-initials="FL"
  user-message="Plain response."
>
  <span slot="user-message">
    The avatar is placed in the top right to anchor the message content when there are two or more lines.
  </span>
  <span slot="agent-message">
    Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.
  </span>
</sl-message>

User message max width

The user message maximum width should take up two thirds of the container where outputs are placed. Whereas, the agent message spans the full width.

This is a short plain text prompt by the user. Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim. The avatar is placed in the top right to anchor the message content when there are two or more lines. Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.
<sl-message
  type="user-agent"
  user-initials="FL"
>
  <span slot="user-message">
    This is a short plain text prompt by the user.
  </span>
  <span slot="agent-message">
    Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.
  </span>
</sl-message>

<sl-message
  type="user-agent"
  user-initials="FL"
>
  <span slot="user-message">
    The avatar is placed in the top right to anchor the message content when there are two or more lines.
  </span>
  <span slot="agent-message">
    Quam orci neque aliquam diam volutpat aliquam tincidunt erat amet. Faucibus pretium ornare egestas lacus. Mauris scelerisque dignissim ipsum aliquam rhoncus dignissim.
  </span>
</sl-message>

Usage patterns

Error state

In the case where the AI agent is in the process of generating a response (so when AI loader is active) but cannot be completed, return an error state to redirect the user on a continuous path instead of a dead end. Buttons show relevant options that the user can move forward with.

In the context of myhub, it is ideal if we can suggest prompts that lead the user to available canned responses.

Plain text prompt That’s outside what we can help with here. Alternatively, we can provide information on the following prompts.
Prompt Prompt Prompt
<sl-message
  type="user-agent"
  user-initials="FL"
>
  <span slot="user-message">
    Plain text prompt
  </span>
  <span slot="agent-message">That’s outside what we can help with here. Alternatively, we can provide information on the following prompts.</span>
  <div class="button-group">
    <sl-button variant="tertiary">Prompt</sl-button>
    <sl-button variant="tertiary">Prompt</sl-button>
    <sl-button variant="tertiary">Prompt</sl-button>
  </div>
</sl-message>

Overflow

Generated responses should not autoscroll to the end. Enable scroll when there is overflow in the conversation container to let user manually scroll.

Plain text prompt
Lorem ipsum dolor sit amet consectetur. Mauris augue in turpis vitae. Natoque lectus varius malesuada nibh. Sit risus hendrerit neque pharetra nibh placerat enim morbi viverra. Tristique quis interdum dictumst diam leo donec massa ut proin. Rutrum egestas cursus sagittis arcu fames ultrices proin tempus.
Dui proin eget viverra nibh elit sit aenean. Purus ut tristique non faucibus sit a. Viverra imperdiet vulputate vitae elementum odio ultrices amet senectus. Diam massa volutpat elementum facilisis nullam pharetra purus id diam. Id eget risus nunc pulvinar urna nulla lectus. Nec massa ullamcorper tempor adipiscing nisi nisi dictum. Egestas imperdiet quam nec semper dui sit velit. Pharetra nibh enim commodo eu pellentesque dui. Venenatis facilisis pulvinar neque elementum.
<div class="conversation-container">
  <div class="message">
    <sl-message
      type="user"
      user-initials="FL"
    >
    <span slot="user-message">
      Plain text prompt
    </span>
    </sl-message>
    <div class="agent-message-container">
      <sl-message
        type="agent"
      >
      <div slot="agent-message">
        <span>
          Lorem ipsum dolor sit amet consectetur. Mauris augue in turpis vitae. Natoque lectus varius malesuada nibh. Sit risus hendrerit neque pharetra nibh placerat enim morbi viverra. Tristique quis interdum dictumst diam leo donec massa ut proin. Rutrum egestas cursus sagittis arcu fames ultrices proin tempus.
        </span>
        <br>
        <span>
          Dui proin eget viverra nibh elit sit aenean. Purus ut tristique non faucibus sit a. Viverra imperdiet vulputate vitae elementum odio ultrices amet senectus. Diam massa volutpat elementum facilisis nullam pharetra purus id diam. Id eget risus nunc pulvinar urna nulla lectus. Nec massa ullamcorper tempor adipiscing nisi nisi dictum. Egestas imperdiet quam nec semper dui sit velit. Pharetra nibh enim commodo eu pellentesque dui. Venenatis facilisis pulvinar neque elementum.
        </span>
      </div>
      </sl-message>
    </div>
  </div>
  <sl-ai-prompt></sl-ai-prompt>
</div>

<style>
  .conversation-container {
    display: flex;
    flex-direction: column;
    gap: var(--hds-space-10x, 40px);

  }

  .message {
    overflow: auto;
  }

  .agent-message-container {
    max-height: 200px;
  }
</style>

[component-metadata:sl-message]

Slots

Name Description
agent-message An agent message slot to display the message and content from agent.
user-message An user message slot to display the user prompt.

Learn more about using slots.

Properties

Name Description Reflects Type Default
type The message sender 'user' | 'agent' | 'user-agent' 'user'
hideAvatar
hide-avatar
Whether the avatar is hidden boolean false
userInitials
user-initials
The user initials, default to ‘FL’ which stands for Firstname Lastname. string 'FL'
userMessage
user-message
The user message, default to ‘Plain text prompt’. string 'Plain text prompt'
agentMessage
agent-message
The agent message, default to ‘Full plain text response sample’. string 'Full plain text response sample.'
hideAgentLogo
hide-agent-logo
Whether the agent logomark is hidden or not, default to show. boolean false
showAgentLabel
show-agent-label
Whether the agent label is hidden or not, default to hide. boolean false
agentLabel
agent-label
The name of the agent, default to ‘Agent name’. string 'Agent name'
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Parts

Name Description
base The component’s base wrapper.
user-message The part that wrappers the user-message.
agent-message The part that wrappers the agent-message.

Learn more about customizing CSS parts.

Dependencies

This component automatically imports the following dependencies.

  • <sl-avatar>
  • <sl-icon>