Skip to main content

Webhook

Dlg Messaging Platform can feed many events and situations related to your bot to webhook that you create on your own servers. In this way, you can get the status of all messages you send to your users through your bot and the responses your users have written to these messages and you can take different actions according to these events. The platform will forward these events and conditions to your webhook by making a POST request.

How to Configure WebHook?#

You can only configure your bot by entering the following configuration parameters in the server.conf file of the dialog-server application.

modules {
webbots {
info : [
{
botUserName : "your_bot_username",
webhook : {
id : "id_of_your_webhook",
url : "http://my_sample_webhook_url.com/",
app_secret : "ffeceefiaae0aec8naich2queid1thoohi3pohSah7ohgaedaengiethah1ahthuumee12affcqq12",
verify_token : "",
subscribed_webhook_events : ["MessageEchoes",MessageDeliveries","MessageReads","Messages"]
}
},
...
]
}
}
ConfigurationDescription
botUserNameThe username of your Webbot. This should be the username information entered by admin when creating the bot.
idThis information is passed back to your webhook. In this way, if you have more than one webbot in the system and all meet the same webhook with this id you can distinguish. If you wish, you can provide a single webhook id for all your webbots. It all depends on the webhook you develop.
urlURL address of your Webhook. The Dlg Platform will send requests to this url.
app_secretUsed to validate requests from the DLG platform. With the app secret value that you specify, Dlg Platform creates the SHA1 HMAC of each message it sends to you and adds this value as "X-Signature" to the header of the request. You can verify incoming requests by checking the HMAC.
verify_tokenUsing this information, your webhook will validate the Dlg Platform, but its development has not yet completed.
subscribed_webhook_eventsThe Dlg Platform only transmits events that you subscribe to. You can define these events to the system with this parameter. You can enter at least one or all of the values of "MessageDeliveries", "MessageReads", "MessageEchoes" as an array, and subscribe to events.

Webhook Events#

Below are the types of events you can get from the Dlg Platform. Different and new events will be added later. All of the events or subscribed events will be forward to your webhook by the platform.

Webhook EventDescription
MessageEchoesWhen you subscribe to this event, you can receive information that messages are sent to the recipient
MessageDeliveriesIf you subscribe to this event, you can receive the message ids information that has been strictly received by the recipients via your webbot.
MessageReadsIf you subscribe to this event, you can receive the message ids information that has been read by the recipients via your webbot.
MessagesWhen users write to you, they are delivered to your webhook via your webhook. To receive these messages, you must subscribe to this event.

Event Format#

All webhook events are delivered to your webhook in the following format. In this format, your webhook id information, sender bot id, receiver id number, customer number, event forwarding time are included in each event type. The content of the event varies by event type. In another matter, the DLG platform collects a maximum of 10 events and transmits them at once, instead of sending each event to your system one by one. Of course, if 10 events have not accumulated within 5 seconds, it will forward the events that have occurred so far to your webhook. All events are sent in the entry array object.

Here is an example event format.

{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560172933001,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560172926374,
...
}
]
}
]
}

The meaning of the parameters of the above json object is as follows.

ParameterTypeDescription
objectStringBy default, this field will return to you as "dialog".
entryArray<entry>This field is the array where events are passed. One or more event objects will be sent to you. You can receive at least one and up to 10 events from each entry.

entry#

ParameterTypeDescription
idStringThe ID information you gave during the configuration for your Webbot is sent back to you through this field.
timeNumberThe sent time of the event to your webhook by the Dlg Platform (epoch milliseconds)
messagingArray<messaging>An array containing each event information. For future reference, this is designed as an array, but will only be passed to you with one object. Therefore, you can take the first element and use it.

messaging#

ParameterTypeDescription
sender<sender>Webbot's information
recipient<recipient>Recipient's information
timestampNumberEvent time (epoch miliseconds)
Event DatasıEvent DataThe event content is different for each event.

sender#

ParameterTypeDescription
idStringIt is the unique id information of Webbot on the Dlg platform.

recipient#

ParameterTypeDescription
appCustomerIdStringThe customer number of the user to whom the message was delivered.
idStringThe unique id information of the user on the DLG platform to which the message is delivered.

Event Data#

MessageEchoes

Message Echo event is the event that occurs when the message is sent to the user via the bot. This event indicates to the user that the message was sent. This does not mean that the event has been delivered to the user.

The content of the sample MessageEcho is as follows.

"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-92"
}
ParameterTypeDescription
app_idStringIt is the unique id information of Webbot on the Dlg platform.
is_echoBooleanDefault returns true.
midStringid of the message

Below is an example entry for the MessageEcho event.

{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560172933001,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560172926374,
"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-92"
}
}
]
}
]
}

MessageDeliveries

The Message Deliveries event is the event that occurs when message or messages are delivered to recipient via the bot. When this event is forwarded to your webhook, all messages with IDs in the event have been delivered to the user.

Sample delivery content is as follows.

"delivery": {
"mids": [
"messageId-92"
],
"watermark": 1560195968593
}
ParameterTypeDescription
midsArray[String]An array containing the message ids of messages forwarded to the user. All message ids in this array are delivered to the user.
watermarkNumberThe time of the delivery event (epoch milliseconds). All messages before this time in this parameter have been delivered.

Below is an example entry for the MessageDeliveries event.

{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560195973608,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560172926374,
"delivery": {
"mids": [
"messageId-92",
"messageId-93"
],
"watermark": 1560195968593
}
}
]
}
]
}

MessageReads

This event is forwarded to your webhook when the user reads the messages.

Example read content is as follows.

"reads": {
"mids": [
"messageId-92"
],
"watermark": 1560197145045
}
ParameterTypeDescription
midsArray[String]An array containing the message ids that the user read. All message ids in this array have been read by the user.
watermarkNumberThe time of the read event (epoch milliseconds). All messages before this time in this parameter have been read.

Below is an example entry for the MessageReads event.

{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560197150060,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560197145045,
"reads": {
"mids": [
"messageId-92"
],
"watermark": 1560197145045
}
}
]
}
]
}

Messages

When the user responds to your webbot, this event will send the user message to your webhook.

Example message content is as follows.

"message": {
"mid": "messageId-92",
"text": "Hello"
}

If the user has pressed one of the buttons of a template message containing the button you sent, the sample message content will be as follows.

"message": {
"mid": "messageId-92",
"text": "[messageId-92]:Approve"
}
ParameterTypeDescription
midStringThe id of the last message delivered to the user. The user has replied to this message.
textStringThis is the content of the user's response. If the user has typed text to you, you will receive the text directly from the user. If the user has sent a message such as OTP (mobile confirmation code), generictemplate, buttontemplate or quickreply type to the user and pressed the buttons of this message, you will get a reply to the message as [[messageId-92]: Hello ". In this way, you can detect which message the user has pushed, and take the necessary actions for the relevant message id.

Below is an example entry for the Messages event.

{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560198179122,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560198174092,
"message": {
"mid": "messageId-92",
"text": "Hello"
}
}
]
}
]
}

Some Sample Event Requests#

  1. When a message is forwarded to the user by the bot, the MessageEchoes and MessageDeliveries event are normally forwarded to the webhook as follows.
{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560199033954,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560199028642,
"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-101"
}
}
]
},
{
"id": "OTP",
"time": 1560199033954,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560199028982,
"delivery": {
"mids": [
"messageId-101"
],
"watermark": 1560199028982
}
}
]
}
]
}
  1. Another example is that the user can receive messages via webbot and read them instantly while the chat screen is open. In this case you will get an event content like the one below.
{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560199722035,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560199716748,
"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-102"
}
}
]
},
{
"id": "OTP",
"time": 1560199722035,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560199717421,
"delivery": {
"mids": [
"messageId-102"
],
"watermark": 1560199717421
}
}
]
},
{
"id": "OTP",
"time": 1560199722035,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560199717448,
"reads": {
"mids": [
"messageId-102"
],
"watermark": 1560199717448
}
}
]
}
]
}
  1. You can send messages to multiple users at the same time. In the sample event request below, webbot sent a message to customer numbers 70021 and 70022 at approximately same times and a message was sent to customer 70021 but not yet to customer 70022.
{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560200490563,
"messaging": [
{
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"sender": {
"id": "1614379680"
},
"timestamp": 1560200485050,
"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-103"
}
}
]
},
{
"id": "OTP",
"time": 1560200490563,
"messaging": [
{
"recipient": {
"appCustomerId": "70022",
"id": "1588406039"
},
"sender": {
"id": "1614379680"
},
"timestamp": 1560200488953,
"messageEcho": {
"app_id": 1614379680,
"is_echo": true,
"mid": "messageId-101"
}
}
]
},
{
"id": "OTP",
"time": 1560200490563,
"messaging": [
{
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"sender": {
"id": "1614379680"
},
"timestamp": 1560200485546,
"delivery": {
"mids": [
"messageId-103"
],
"watermark": 1560200485546
}
}
]
}
]
}
  1. Another example is to send messages to the user, but the user read the messages sent to him after a while. In this case, only the reading events will be as follows when the user reads the messages. As it can be seen from the content below, the user has read the message id messageId-103, messageId-104 and messageId-105.
{
"object": "dialog",
"entry": [
{
"id": "OTP",
"time": 1560201130747,
"messaging": [
{
"sender": {
"id": "1614379680"
},
"recipient": {
"appCustomerId": "70021",
"id": "243540663"
},
"timestamp": 1560201125731,
"reads": {
"mids": [
"messageId-103",
"messageId-104",
"messageId-105"
],
"watermark": 1560201125731
}
}
]
}
]
}