---
title: "Message"
description: "One turn, with a user bubble, Markdown reply and response actions."
---

# Message

One turn, with a user bubble, Markdown reply and response actions.

## Usage

Copy the question or Markdown reply, edit the question, and toggle positive or negative feedback. Copy confirmation resets after two seconds. The reply is a fixed local sample.

## Example

````contract
use uiFontFamily, MessageFrame, MessageContent, MessageFooter, BubbleFrame, MessageAction, MessageEditor from "@rightui/ui"
use Markdown from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  state prompt = "How do I add a settings dialog? It should open from the gear icon in the header."
  state editing = false
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state copiedUntil = 0
  derive copied = rightuiDemoTime < copiedUntil
  state feedback = ""
  state replayUntil = 0
  derive replaying = rightuiDemoTime < replayUntil
  action edit(value: string)
    prompt = value
  action toggleEdit
    editing = not editing
  action copyUser
    copyText(prompt)
  action copy
    copyText("Import Dialog, then open it from your header button.\n\n```contract\nuse Button, Dialog from \"@rightui/ui\"\n```\n\nKeep a boolean open state in the parent. Pass it to `Dialog`, update it from the button action, and clear it in `dismiss`. Put the settings form in the Dialog slot.")
    copiedUntil = rightuiDemoTime + 2000
    rightuiRunDemo(2000)
  action like
    feedback = feedback == "like" ? "" : "like"
  action dislike
    feedback = feedback == "dislike" ? "" : "dislike"
  action retry
    replayUntil = rightuiDemoTime + 800
    rightuiRunDemo(800)
  view
    column width="100%" max-width="28rem" margin="ui.space-0 auto" gap="ui.space-32" padding="ui.space-24 ui.space-0" min-width=0
      MessageFrame(id="ai-message-user", align="end")
        MessageContent(id="ai-message-user-content", align="end")
          if editing
            MessageEditor(id="ai-message-editor", value=prompt, edit=edit, save=toggleEdit)
          else
            BubbleFrame(id="ai-message-bubble", align="end", variant="muted")
              text prompt font-family=uiFontFamily(uiFont) data-rightui-font="body"
          MessageFooter(id="ai-message-user-footer", align="end")
            MessageAction(id="ai-message-user-copy", label="Copy", icon="copy", pressed=false, press=copyUser)
            MessageAction(id="ai-message-edit", label="Edit", icon="pencil", pressed=editing, press=toggleEdit)
      MessageFrame(id="ai-message-assistant", align="start")
        MessageContent(id="ai-message-answer", align="start")
          Markdown(id="ai-message-markdown", content="Import Dialog, then open it from your header button.\n\n```contract\nuse Button, Dialog from \"@rightui/ui\"\n```\n\nKeep a boolean open state in the parent. Pass it to `Dialog`, update it from the button action, and clear it in `dismiss`. Put the settings form in the Dialog slot.")
          MessageFooter(id="ai-message-footer", align="start")
            MessageAction(id="ai-message-copy", label=(copied ? "Copied" : "Copy"), icon=(copied ? "check" : "copy"), pressed=false, press=copy)
            MessageAction(id="ai-message-helpful", label="Good response", icon="hand.thumbsup", pressed=(feedback == "like"), press=like)
            MessageAction(id="ai-message-unhelpful", label="Bad response", icon="hand.thumbsdown", pressed=(feedback == "dislike"), press=dislike)
            MessageAction(id="ai-message-retry", label="Retry", icon="arrow.clockwise", pressed=false, press=retry)
          if replaying
            text "Replaying response…" role="status" font-size="ui.text-xs" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"

````

## Keyboard

Tab to controls; Enter or Space to activate buttons.

## Demo runtime

Timed examples use an injected clock. Add these members to your root component. Replace the scripted state with events from your TypeScript or Rust data source when connecting a model.

```contract
use defaultFontWeights from "@rightui/ui"
  state demoTime = 0
  state demoUntil = 0
  provide
    uiFont = "theme"
    uiWeights = defaultFontWeights()
    rightuiDemoTime = demoTime
    rightuiRunDemo = runDemo
  action runDemo(duration: number)
    demoUntil = max(demoUntil, demoTime + duration)
  action tickDemo
    demoTime = min(demoUntil, demoTime + 32)
  task demoClock when demoTime < demoUntil
    every(32, tickDemo)
```

## Source

File: patterns/ai-elements/message.contract

````contract
use uiFontFamily, MessageFrame, MessageContent, MessageFooter, BubbleFrame, MessageAction, MessageEditor from "@rightui/ui"
use Markdown from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  state prompt = "How do I add a settings dialog? It should open from the gear icon in the header."
  state editing = false
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state copiedUntil = 0
  derive copied = rightuiDemoTime < copiedUntil
  state feedback = ""
  state replayUntil = 0
  derive replaying = rightuiDemoTime < replayUntil
  action edit(value: string)
    prompt = value
  action toggleEdit
    editing = not editing
  action copyUser
    copyText(prompt)
  action copy
    copyText("Import Dialog, then open it from your header button.\n\n```contract\nuse Button, Dialog from \"@rightui/ui\"\n```\n\nKeep a boolean open state in the parent. Pass it to `Dialog`, update it from the button action, and clear it in `dismiss`. Put the settings form in the Dialog slot.")
    copiedUntil = rightuiDemoTime + 2000
    rightuiRunDemo(2000)
  action like
    feedback = feedback == "like" ? "" : "like"
  action dislike
    feedback = feedback == "dislike" ? "" : "dislike"
  action retry
    replayUntil = rightuiDemoTime + 800
    rightuiRunDemo(800)
  view
    column width="100%" max-width="28rem" margin="ui.space-0 auto" gap="ui.space-32" padding="ui.space-24 ui.space-0" min-width=0
      MessageFrame(id="ai-message-user", align="end")
        MessageContent(id="ai-message-user-content", align="end")
          if editing
            MessageEditor(id="ai-message-editor", value=prompt, edit=edit, save=toggleEdit)
          else
            BubbleFrame(id="ai-message-bubble", align="end", variant="muted")
              text prompt font-family=uiFontFamily(uiFont) data-rightui-font="body"
          MessageFooter(id="ai-message-user-footer", align="end")
            MessageAction(id="ai-message-user-copy", label="Copy", icon="copy", pressed=false, press=copyUser)
            MessageAction(id="ai-message-edit", label="Edit", icon="pencil", pressed=editing, press=toggleEdit)
      MessageFrame(id="ai-message-assistant", align="start")
        MessageContent(id="ai-message-answer", align="start")
          Markdown(id="ai-message-markdown", content="Import Dialog, then open it from your header button.\n\n```contract\nuse Button, Dialog from \"@rightui/ui\"\n```\n\nKeep a boolean open state in the parent. Pass it to `Dialog`, update it from the button action, and clear it in `dismiss`. Put the settings form in the Dialog slot.")
          MessageFooter(id="ai-message-footer", align="start")
            MessageAction(id="ai-message-copy", label=(copied ? "Copied" : "Copy"), icon=(copied ? "check" : "copy"), pressed=false, press=copy)
            MessageAction(id="ai-message-helpful", label="Good response", icon="hand.thumbsup", pressed=(feedback == "like"), press=like)
            MessageAction(id="ai-message-unhelpful", label="Bad response", icon="hand.thumbsdown", pressed=(feedback == "dislike"), press=dislike)
            MessageAction(id="ai-message-retry", label="Retry", icon="arrow.clockwise", pressed=false, press=retry)
          if replaying
            text "Replaying response…" role="status" font-size="ui.text-xs" color="ui.muted-foreground" font-family=uiFontFamily(uiFont) data-rightui-font="body"

````
