LeadML Messaging


Creating a custom LeadML application allows you to manage the response to inbound messages. You can direct messages to your custom LeadML application directly from the Inbound route of a message channel, or you can redirect to it from within a flow created with the Flow tool.

Request

Your LeadML application will be called with POST request with following parameters in application/x-www-form-urlencoded format.

Name Description Example
MessageSid UUID generated for the message when received. It is always unique for each message 78f4203e-c432-4dbd-a530-37afcff665a9
Type Type of message: email, sms, facebook, webchat, control SMS
ReceivedAt Time when the message was originally received by LeadDesk 2020-02-03T06:26:38+00:00
From Sender identifier e.g. phone number +358401234567
To Receiver identifier e.g. phone number +358457654321
SessionSid Message’s session UUID. Same sender and receiver within a short period of time will be assigned to same session 6b3fbaf2-18f2-436c-b0ed-ea5f4cbf0bac
Body Message content Hello world!
Meta JSON encoded array of meta information with name and value pairs
[{"name":"a","value":"b"}]
Attachments JSON encoded array of media items (NumMedia tells how many items there are in the array)
[{
"url":"http://...",
"filename":"readme.txt",
"size":123
},{"url":"http://...",
"filename":"readme.1st",
"size":456
}]
ContentType Content type of Body: plain/text or application/json for requests of the bundle type plain/text

Meta fields

Meta fields allow extending the basic message model with unique properties of the original message type. Meta fields are always optional and they might not be present. Different message types should prefer using the common meta field names to make message parsing easier.

Below is a list of commonly used meta field names.

Name Description
subject Subject/Title/Header of the message
plain_text Plain text version of body if available. Used when the actual message body’s content type is something else than text/plain
to_raw Raw ‘to’ header from the email message
cc_raw Raw ‘cc’ header from the email message
utc_timestamp Arrival time in UTC
messaging_id Row ID of the messaging database for the message in question. Not to be confused with MessageSid or UUID’s

Requests can include the meta attribute previous_messages creating a “bundled message”. This bundled message is a JSON object with the keys inbound, outbound and meta.

  • – The value of the inbound key is an array with the inbound messages received.
  • – The value of the outbound key is an array with the outbound messages sent.
  • – The value of the meta key is an array with the meta messages received.

The MessageSid, Type, ContentType and Body fields of such requests are the same as for the last message sent by the user.

Example of request form parameters

{
   "MessageSid": "c02711cf-3513-4d33-b598-2a7cf963e023",
   "From": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
   "To": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
   "Body": "transfer",
   "ReceivedAt": "2023-09-12T22:58:58+03:00",
   "Type": "webchat",
   "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
   "ContentType": "text\/plain",
   "Meta": "(for details see below)",
   "Attachments": "[]"
}

Example of a meta form parameter

[
    {
        "name": "messaging_id",
        "value": "527"
    },
    {
        "name": "utc_timestamp",
        "value": "2023-09-12 19:58:41.901794"
    },
    {
        "name": "widget_url",
        "value": "http:\\\/\\\/localhost:3000\\\/"
    },
    {
        "name": "previous_messages",
        "value": {
            "inbound": [
                {
                    "MessageSid": "c47dda18-314a-452c-a083-f2812e89e281",
                    "ReceivedAt": "2023-09-12T22:57:54+03:00",
                    "Type": "webchat",
                    "From": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "To": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "Body": "first message",
                    "ContentType": "text\\\/plain",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "messaging_id",
                            "value": "525"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:57:54.533169"
                        },
                        {
                            "name": "widget_url",
                            "value": "http:\\\/\\\/localhost:3000\\\/"
                        }
                    ],
                    "Attachments": []
                },
                {
                    "MessageSid": "1c8a609e-257d-4860-ace1-f1ac8b4a83e8",
                    "ReceivedAt": "2023-09-12T22:58:25+03:00",
                    "Type": "webchat",
                    "From": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "To": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "Body": "second message",
                    "ContentType": "text\\\/plain",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "messaging_id",
                            "value": "526"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:58:25.728550"
                        },
                        {
                            "name": "widget_url",
                            "value": "http:\\\/\\\/localhost:3000\\\/"
                        }
                    ],
                    "Attachments": []
                },
                {
                    "MessageSid": "c02711cf-3513-4d33-b598-2a7cf963e023",
                    "ReceivedAt": "2023-09-12T22:58:41+03:00",
                    "Type": "webchat",
                    "From": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "To": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "Body": "transfer",
                    "ContentType": "text\\\/plain",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "messaging_id",
                            "value": "527"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:58:41.901794"
                        },
                        {
                            "name": "widget_url",
                            "value": "http:\\\/\\\/localhost:3000\\\/"
                        }
                    ],
                    "Attachments": []
                }
            ],
            "outbound": [
                {
                    "MessageSid": "c4c8b2d6-bc20-4cdc-84ac-e6e72eff3834",
                    "ReceivedAt": "2023-09-12T22:57:34+03:00",
                    "Type": "webchat",
                    "From": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "To": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "Body": "Hello, you made it to your Chatbot! How may I help?",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "chatbot_id",
                            "value": "8a7afade-97ef-11ed-8f84-0ac2ad902135"
                        },
                        {
                            "name": "chatbot_name",
                            "value": "LeadDesk demo"
                        },
                        {
                            "name": "messaging_id",
                            "value": "548"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:57:34.112402"
                        }
                    ],
                    "Attachments": []
                },
                {
                    "MessageSid": "c7388801-4310-4539-9316-35104f371f66",
                    "ReceivedAt": "2023-09-12T22:57:56+03:00",
                    "Type": "webchat",
                    "From": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "To": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "Body": "Hey, sorry I did not understand. Please try again.",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "chatbot_id",
                            "value": "8a7afade-97ef-11ed-8f84-0ac2ad902135"
                        },
                        {
                            "name": "chatbot_name",
                            "value": "LeadDesk demo"
                        },
                        {
                            "name": "messaging_id",
                            "value": "549"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:57:56.395512"
                        }
                    ],
                    "Attachments": []
                },
                {
                    "MessageSid": "23008134-c5d8-4c9d-a214-501b8cf92e25",
                    "ReceivedAt": "2023-09-12T22:58:27+03:00",
                    "Type": "webchat",
                    "From": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "To": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "Body": "Hey, sorry I did not understand. Please try again.",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "chatbot_id",
                            "value": "8a7afade-97ef-11ed-8f84-0ac2ad902135"
                        },
                        {
                            "name": "chatbot_name",
                            "value": "LeadDesk demo"
                        },
                        {
                            "name": "messaging_id",
                            "value": "550"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:58:27.973994"
                        }
                    ],
                    "Attachments": []
                },
                {
                    "MessageSid": "59057b41-bcb3-40c0-86d2-34354975d6a2",
                    "ReceivedAt": "2023-09-12T22:58:44+03:00",
                    "Type": "webchat",
                    "From": "106158D8-4429-4A6A-87DA-4E7C32EA87AE",
                    "To": "56ffbfe6-2dde-417b-a8a2-cc3204aa8088",
                    "Body": "ok, will transfer",
                    "SessionSid": "a666a601-e843-4816-8734-2f7159877e0c",
                    "Meta": [
                        {
                            "name": "chatbot_id",
                            "value": "8a7afade-97ef-11ed-8f84-0ac2ad902135"
                        },
                        {
                            "name": "chatbot_name",
                            "value": "LeadDesk demo"
                        },
                        {
                            "name": "messaging_id",
                            "value": "551"
                        },
                        {
                            "name": "utc_timestamp",
                            "value": "2023-09-12 19:58:44.310106"
                        }
                    ],
                    "Attachments": []
                }
            ],
            "meta": []
        }
    }
]