---
agentTools:
  projectIndex: https://devdocs.drift.com/llms.txt
---

# Message Model

Messages make up a conversation.

[block:api-header]
{
  "title": "Schema"
}
[/block]

[block:code]
{
  "codes": [
    {
      "code": "{\n  \"id\": long (int),\n  \"orgId\": int,\n  \"body\": string,\n  \"author\": {\n    \"type\": string, // one of {contact, user}\n    \"id\": long,\n    \"bot\": boolean\n  },\n  \"type\": string, // one of {chat, private_note},\n  \"conversationId\": long,\n  \"createdAt\": timestamp,\n  \"buttons\": [MessageButton],\n  \"context\": {\n    \"ip\": string,\n    \"userAgent\": string\n  },\n  \"attributes\": object // additional information (see below)\n}",
      "language": "json"
    }
  ]
}
[/block]

[block:parameters]
{
  "data": {
    "0-0": "id",
    "1-0": "orgId",
    "2-0": "body",
    "3-0": "author",
    "4-0": "type",
    "5-0": "conversationId",
    "6-0": "createdAt",
    "7-0": "buttons",
    "8-0": "context",
    "h-0": "Field Name",
    "h-1": "Description",
    "0-1": "A unique identifier for the message. Should be treated as long or integer 64 bit data type.",
    "1-1": "The Drift organization this message belongs to",
    "2-1": "The text contents of this message, if applicable. See the message body section for details on the format.",
    "3-1": "An object describing who authored this message. `author.type` is `contact` if the author was a contact and `user` if they were a user. `author.id` uniquely identifies the author within the object type specified by `author.type`. Bot indicates whether the posting user is a bot (won't be true for contacts).",
    "5-1": "The `id` field of the conversation this message is a part of.",
    "6-1": "A Unix timestamp representing the moment this message was created",
    "8-1": "An optional object representing potential metadata about where the message was published from.",
    "7-1": "A (potentially absent) list of objects representing buttons presented to contacts from this message. See the section on message buttons for details.",
    "4-1": "Specifies the type of this message; one of `chat`, or `private_note`. See the section types of messages below for details.",
    "9-0": "attributes",
    "9-1": "Other metadata on the message.\n\nPossible fields:\n`preMessages` (object): If there were messages in the conversation *prior* to this current message, i.e. supplied by a bot user or on behalf of a drift user, these will be supplied here. This is generally present on the first site visitor message.\n`developer_app_id` (string): The dev app ID will be included if the message was posted via the API."
  },
  "cols": 2,
  "rows": 10
}
[/block]

[block:api-header]
{
  "title": "Types of Messages"
}
[/block]

There are 2 types of messages, corresponding to the `type` field in that object:

* `chat` Messages are the most ubiquitous type. They correspond to a regular text-based communication from either a contact or a user and are visible to both. `chat` type messages may also contain buttons, in which case they're only visible to the conversation's contact.
* `private_note`s are messages that can only be created by a user and seen by other users. These are useful for sharing sensitive, but useful information to users in the context of the communication they're having with a given contact.

[block:api-header]
{
  "title": "Message Bodies"
}
[/block]

The `message.body` field is the primary vehicle for communicating information in messages. It follows a format that resembles HTML in order to allow for limited richness, but is heavily and automatically restricted. In particular, HTML reserved characters are automatically converted to their corresponding HTML entities if they're outside the context of an allowed tag. `<b>`, `<em>`, and `<a>` tags are allowed, but most others are automatically stripped, as well as any styles on the allowed ones. Ultimately, you can treat this field as plain text and not include any tags.

[block:api-header]
{
  "title": "Message Buttons"
}
[/block]

A `chat` message can be made interactive with buttons.

Buttons can be set as a list in the `message.button` field and have the following format:

[block:code]
{
  "codes": [
    {
      "code": "{\n  \"label\": string,\n  \"value\": string,\n  \"type\": {reply},\n  \"style\": {primary, danger},\n  \"reaction\": {\n    \"type\": {replace, delete},\n    \"message\": string\n  }\n}",
      "language": "json"
    }
  ]
}
[/block]

[block:parameters]
{
  "data": {
    "h-0": "Field Name",
    "h-1": "Description",
    "0-0": "label",
    "0-1": "For all button types, the `label` field is what is actually displayed as a label on the button to the user or contact.",
    "1-0": "value",
    "1-1": "For `reply` type buttons, `value` must equal `label`.",
    "2-0": "type",
    "2-1": "Optional: defaulted to `reply`\n`reply` type buttons cause the text in the button to be immediately used as a new `chat` message by the contact when pressed. `reply`s are only ever rendered to contacts (users will only see the `body` of the message) and are the only type allowed in `chat` messages."
  },
  "cols": 2,
  "rows": 3
}
[/block]