# chat_send_message

Send Chat Message

## Beschreibung

Posts a message to a chat channel or DM — optionally with file
attachments (images, PDFs, video, any MIME type). Synchronous:
hits the DB and Turbo-broadcasts to members before returning.

- Body is GFM Markdown, ≤ 32 KB. `@handle` mentions resolve
  against active account members; response's `mentions` echoes
  what mapped (resolve handles via `account_list_users`).
- `attachment_ids` entries come from `attachment_upload` —
  pass the `att_…` id or the `file_url`, either works. Body
  becomes optional when at least one attachment is present.
- `parent_message_id` threads the post (single-level only).
- Not idempotent — retries create duplicate rows.
- Workspace members can post to public channels and their threads
  without joining the channel. Private channels and DMs require
  channel membership; account admins retain tenant-wide access.

## Zugriff

Zugriffsprofil: `basic`. Module: `chat`.
Die Freigabe im Profil ersetzt keine Account-, Workspace- oder Rollenberechtigung.

## Parameter

| Name | Typ | Pflicht | Beschreibung |
| --- | --- | --- | --- |
| `account_id` | string | Ja | Account prefix ID (e.g., acct_abc123). |
| `channel_id` | string | Ja | Channel prefix ID (e.g., chan_xyz789) from chat_list_channels. |
| `body` | string | Nein | Markdown content. Do not escape the string — use literal newlines and special characters, not escape sequences. Supports GFM plus @handle mentions (resolved against active account members). Max 32 KB. Optional when attachment_ids is present. |
| `parent_message_id` | string | Nein | Thread this reply under this root message's prefix ID (msg_…). Single-level threading only — replies to replies are rejected. |
| `attachment_ids` | array | Nein | Attachment handles from attachment_upload — att_… ids or file_urls, mixed freely. Each blob may only be attached to one chat message. Body may be empty when at least one attachment is present. |

## Eingabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "account_id": {
      "type": "string",
      "description": "Account prefix ID (e.g., acct_abc123)."
    },
    "channel_id": {
      "type": "string",
      "description": "Channel prefix ID (e.g., chan_xyz789) from chat_list_channels."
    },
    "body": {
      "type": "string",
      "maxLength": 32768,
      "description": "Markdown content. Do not escape the string — use literal newlines and special characters, not escape sequences. Supports GFM plus @handle mentions (resolved against active account members). Max 32 KB. Optional when attachment_ids is present."
    },
    "parent_message_id": {
      "type": "string",
      "description": "Thread this reply under this root message's prefix ID (msg_…). Single-level threading only — replies to replies are rejected."
    },
    "attachment_ids": {
      "type": "array",
      "maxItems": 20,
      "items": {
        "type": "string"
      },
      "description": "Attachment handles from attachment_upload — att_… ids or file_urls, mixed freely. Each blob may only be attached to one chat message. Body may be empty when at least one attachment is present."
    }
  },
  "required": [
    "account_id",
    "channel_id"
  ],
  "type": "object"
}
```

## Ausgabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "message": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Message prefix ID (msg_…)."
        },
        "body": {
          "type": "string"
        },
        "user": {
          "type": "object",
          "properties": {
            "id": {
              "type": [
                "string",
                "null"
              ]
            },
            "handle": {
              "type": [
                "string",
                "null"
              ]
            },
            "name": {
              "type": "string"
            }
          }
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "parent_message_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "replies_count": {
          "type": "integer"
        },
        "mentions": {
          "type": "object",
          "description": "Server-side resolution of @handle tokens in body — confirms what you intended actually mapped.",
          "properties": {
            "resolved_users": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "handle": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            },
            "mention_all": {
              "type": "boolean",
              "description": "True when `@all` was used."
            }
          }
        },
        "reactions": {
          "type": "array",
          "description": "Always an empty array on a freshly-sent message — here for shape parity with chat_get_messages.",
          "items": {
            "type": "object"
          }
        },
        "attachments": {
          "type": "array",
          "description": "Files attached to this message (via attachment_ids). Same shape as chat_get_messages.",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "filename": {
                "type": "string"
              },
              "mime_type": {
                "type": "string"
              },
              "byte_size": {
                "type": "integer"
              },
              "download_url": {
                "type": "string",
                "format": "uri",
                "description": "Signed URL, valid 30 minutes."
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "required": [
        "id",
        "body",
        "user",
        "created_at",
        "parent_message_id",
        "replies_count",
        "mentions",
        "reactions",
        "attachments"
      ]
    }
  },
  "required": [
    "message"
  ],
  "type": "object"
}
```
