Creating a Message

POST https://driftapi.com/conversations/<conversationId>/messages

Creates a new message in the conversation specified by the given conversationId. A partial message should be given as the request body with following format:

{
  "type": "chat",    //or "private_note"
  "body": "string",  //(optional)
  "buttons": [       //(optional)
     {"value": "yes please",
      "label": "yes please",
      "type": "reply"}], 
  "userId": 12345    //(optional)
}

The response includes the fully created message model in the data field.

{
    "data": {
        "messages": [
            {
                "id": 12342019624,
                "conversationId": 1230200520,
                "body": "<p>Hi there <span class=\"driftiwyg-tag-property\">Elias</span></p>",
                "author": {
                    "id": 1230056,
                    "type": "user",
                    "bot": true
                },
                "type": "chat",
                "createdAt": 1237922759452,
                "attributes": {}
            },
            {
                "id": 12367319626,
                "conversationId": 1230200520,
                "body": "<p>Do you need assistance with something?</p>",
                "author": {
                    "id": 1230056,
                    "type": "user",
                    "bot": true
                },
                "type": "chat",
                "createdAt": 1237922759509,
                "buttons": [
                    {
                        "value": "yes please",
                        "label": "yes please",
                        "type": "reply"
                    },
                    {
                        "value": "Nah I'm ok just browsing",
                        "label": "Nah I'm ok just browsing",
                        "type": "reply"
                    }
                ],
                "attributes": {}
            },
            {
                "id": 12367319635,
                "conversationId": 1230200520,
                "body": "yes please",
                "author": {
                    "id": 1238157803,
                    "type": "contact",
                    "bot": false
                },
                "type": "chat",
                "createdAt": 1237922759589,
                "context": {
                    "ip": "12.34.45.239",
                    "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
                    "href": "http://www.yourwebsite.com",
                    "title": "Main Testing",
                    "referrer": "",
                    "timezone": "America/New_York",
                    "location": {
                        "city": "Hialeah",
                        "region": "Florida",
                        "country": "US",
                        "countryName": "United States",
                        "postalCode": "33015",
                        "latitude": 25.9381,
                        "longitude": -80.3146
                    },
                    "locale": "en"
                },
                "attributes": {
                    "preMessages": []
                }
            }
        ]
    },
    "pagination": {
        "more": false
    }
}

Field Definitions

FieldDescription
bodyThe message body as a string.
typeRequired The message type. Chat is used for creating a public message in the conversation, while the private notes will be shown only to the agents.
buttonsMessageButton objects to include in the message body. These will show up as clickable buttons in the posted message - can be used to trigger events on click.
userIdIf userId not specified, the bot user for the account will be used as the message author. You can also specify a userId of a known user in the organization's account here. The message from the API will appear as if posted by that particular user/agent in the conversation.

📘

The message API renders the body as HTML

Tags like <a>, <p>, <b>, etc. should all work.

Note for urls to expand or unfurl as clickable links in the conversation view, ex: when posting a youtube link in the chat, you should post the link as an a tag.

{
  "body": "hey there, check this out <a href='https://www.youtube.com/watch?v=kD30F_tjogs'>here</a>",
  "type": "chat"
}

Javascript in the message is not supported.