# Message

One turn of a conversation, an article with a hidden heading naming the speaker. from: "you" (the reader's words in a quiet bubble on the end side, line breaks kept), "agent" (an AI: Avatar's agent mark and its required name, which tell people it is an AI; its heading says "(AI)") or "person" (another person, a hand-over: avatar, name). children is the content (Response for an agent's answer), with time and attachments (chips). status: sending (in the time's place, so the turn keeps its height), streaming (aria-busy, a working line in words), done, stopped (what arrived kept) or failed (error in words, Retry). Actions on a Toolbar under it, always shown and reachable by keyboard and touch, never on hover alone: Copy (copyText, "Copied" announced), Helpful and Not helpful (feedback, defaultFeedback, onFeedbackChange; pressed again clears), Retry (onRetry), Edit (onEdit, the reader's turn) and the app's own (actions); none while a reply streams. Inside a Conversation it reports its start and end for the thread's one announcement (announcement gives a summary). Every string is a prop.

Page: https://turtlekit.dev/components/message

## Import

```tsx
import { Message } from "turtlekit";
```

## Props

### Message

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What was said: Response for an agent's answer, the reader's words as text (their line breaks are kept). |
| `time` | `Date \| string \| number` |  | When it was said: shown as the clock time, in the reader's locale and zone. |
| `status` | `MessageStatus` | `done` | Default "done". |
| `error` | `ReactNode` |  | Why it failed and what to do, for status "failed" ("The connection dropped. |
| `attachments` | `ReadonlyArray<AttachmentItem>` |  | Files with the turn, as chips: they open through their `href`, or `onOpenAttachment`. |
| `onOpenAttachment` | `(id: string) => void` |  |  |
| `attachmentsLabel` | `string` | `Attached files` | Names the files' list. |
| `copyText` | `string` |  | The text Copy puts on the clipboard (a reply's Markdown, the reader's words). |
| `onRetry` | `() => void` |  | Shows Retry: send the reader's turn again, or ask for the reply again. |
| `onEdit` | `() => void` |  | Shows Edit, on the reader's turn: put its words back in the prompt box to change them. |
| `feedback` | `"helpful" \| "not-helpful"` |  | The reader's rating of a reply (controlled); null for none. |
| `defaultFeedback` | `"helpful" \| "not-helpful"` |  |  |
| `onFeedbackChange` | `(feedback: MessageFeedback \| null) => void` |  | The rating changed; null when it was pressed again to clear it. |
| `actions` | `ReactNode` |  | More actions after the kit's own, on the same toolbar: IconButtons ("Share", "Read aloud"). |
| `announcement` | `string` |  | What the conversation says once when this reply finishes, instead of its whole text: a summary for a long or visual reply ("A table of three plans, with prices"). |
| `headingLevel` | `2 \| 3 \| 4 \| 5 \| 6` |  | The hidden heading's level, which names the speaker. |
| `picture` | `string` |  | A person's photo, or an agent's own mark as a picture. |
| `headingLabel` | `(name: string, from: MessageFrom) => string` | `HEADING` | The hidden heading: (name, from) => "You said", `${name} (AI) said` for an agent, `${name} said` for a person. |
| `actionsLabel` | `string` | `Message actions` | Names the actions' toolbar. |
| `copyLabel` | `string` | `Copy` | Default "Copy". |
| `copiedLabel` | `string` | `Copied` | Said and shown after copying. |
| `retryLabel` | `string` | `Retry` | Default "Retry". |
| `editLabel` | `string` | `Edit` | Default "Edit". |
| `helpfulLabel` | `string` | `Helpful` | Default "Helpful". |
| `notHelpfulLabel` | `string` | `Not helpful` | Default "Not helpful". |
| `workingLabel` | `string` | `Writing a reply` | The words while a reply streams. |
| `sendingLabel` | `string` | `Sending` | The words while the reader's turn is on its way. |
| `stoppedLabel` | `string` | `You stopped this reply` | The words under a stopped reply. |
| `failedLabel` | `string` |  | A failed turn's words when there is no `error`: "Not sent" for the reader's, "This reply didn't finish" otherwise. |
| `from` (required) | `"you" \| "agent" \| "person"` |  | Who speaks: "you" (the reader), "agent" (an AI) or "person" (another person, after a hand-over). |
| `name` | `string` |  | The agent's or the person's name, on every turn ("Acme Assistant", "Maya Chen"); the reader's defaults to "You". |

## Shapes its props take

### AttachmentItem

| Prop | Type | Default | What it does |
| --- | --- | --- | --- |
| `id` (required) | `string` |  |  |
| `name` (required) | `string` |  |  |
| `size` | `number` |  | Bytes. |
| `type` | `string` |  | The file's MIME type ("application/pdf", "image/png"), as `File.type` gives it. |
| `kind` | `string` |  | What kind of file it is, when the name's extension does not say it ("Spreadsheet"). |
| `preview` | `string` |  | An image's address (an object URL while it uploads, the stored file's after): shown as the chip's thumbnail. |
| `status` | `"done" \| "error" \| "uploading"` |  | "uploading" shows its progress, "error" its message; default "done". |
| `progress` | `number` |  | 0–100 while uploading. |
| `error` | `string` |  | What went wrong and what to do ("Too large to send. |
| `href` | `string` |  | Where the file opens (in a sent message): the chip becomes a link. |

## Rules it keeps

- `colour.not-alone`
- `a11y.accessible-name`
- `composition.feedback-near-cause`

## Examples

Every example on the page, as one file:

```tsx
import { useEffect, useState } from "react";
import { Card, Conversation, Inset, Message, Num, Text, toast } from "turtlekit";
import type { MessageStatus } from "turtlekit";

/**
 * The three speakers: the reader's words on the end side, the AI agent with its mark and name, and a person from the
 * team after a hand-over. Each agent reply keeps its actions in reach.
 */
export function Speakers() {
  return (
    <Card>
      <Inset>
        <Conversation label="Conversation with Acme support" height="30rem">
          <Message from="you" time="2026-11-25T10:02:00Z" copyText="I was charged twice for November.">
            I was charged twice for November.
          </Message>
          <Message
            from="agent"
            name="Acme Assistant"
            time="2026-11-25T10:02:00Z"
            copyText="I can see two payments on 1 November. A refund needs someone from billing."
            onFeedbackChange={(rating) => rating && toast.success("Thanks for telling us.")}
          >
            <Text as="p">
              I can see two payments on 1 November, the second a minute after the first. A refund needs
              someone from billing: I have passed them your account and both payments.
            </Text>
          </Message>
          <Message from="person" name="Maya Chen" picture="/media/maya.jpg" time="2026-11-25T10:05:00Z">
            <Text as="p">
              Hi, Maya from billing here. I have refunded the second payment; it reaches your card in three to
              five days.
            </Text>
          </Message>
        </Conversation>
      </Inset>
    </Card>
  );
}

/**
 * A reply that failed, in words, with Retry. Retry asks again; the reply streams, then lands (a timer stands in for
 * the model here).
 */
export function FailedReply() {
  const [status, setStatus] = useState<MessageStatus>("failed");
  useEffect(() => {
    if (status !== "streaming") return;
    const timer = setTimeout(() => setStatus("done"), 1600);
    return () => clearTimeout(timer);
  }, [status]);
  return (
    <Card>
      <Inset>
        <Conversation label="Conversation about October's unpaid invoices" height="18rem">
          <Message from="you" time="2026-11-25T11:20:00Z">
            How much is still unpaid from October?
          </Message>
          <Message
            from="agent"
            name="Acme Assistant"
            time="2026-11-25T11:20:00Z"
            status={status}
            error="The connection dropped before the reply finished. Your question is kept."
            onRetry={() => setStatus("streaming")}
            copyText={status === "done" ? "Three October invoices are unpaid." : undefined}
          >
            {status === "done" ? (
              <Text as="p">
                Three October invoices are unpaid,{" "}
                <Num value={4180} format="currency" currency="GBP" maximumFractionDigits={0} /> in all. The
                oldest, to Harbour Dental, is 12 days late.
              </Text>
            ) : null}
          </Message>
        </Conversation>
      </Inset>
    </Card>
  );
}

/** The reader's question with a screenshot (its chip opens the picture) and a PDF. */
export function WithAttachments() {
  return (
    <Card>
      <Inset>
        <Conversation label="Conversation about this week's projects" height="26rem">
          <Message
            from="you"
            time="2026-11-25T14:40:00Z"
            attachments={[
              {
                id: "overview",
                name: "northwind-overview.png",
                type: "image/png",
                size: 248_000,
                preview: "/media/dashboard.png",
                href: "/media/dashboard.png",
              },
              {
                id: "plan",
                name: "website-redesign-plan.pdf",
                type: "application/pdf",
                size: 1_240_000,
              },
            ]}
          >
            Which project should I worry about this week?
          </Message>
          <Message
            from="agent"
            name="Acme Assistant"
            time="2026-11-25T14:40:00Z"
            copyText="The website redesign: it is due in 4 days and 24 of its 61 tasks are still open."
            onFeedbackChange={(rating) => rating && toast.success("Thanks for telling us.")}
          >
            <Text as="p">
              The website redesign. It is due in 4 days and 24 of its 61 tasks are still open, while the plan
              puts the last two weeks on testing alone. Ask whether the launch can move, or which pages can
              wait.
            </Text>
          </Message>
        </Conversation>
      </Inset>
    </Card>
  );
}
```
