Webhook Block
This chapter will explain what a webhook block is and how to use it.
Basic Concept
In the dialogue flow, sometimes the bot needs to obtain multiple information from the third-party interface, and fill the information into the corresponding receiving slot for continued use in the subsequent process. At this time, we can use the webhook block. The webhook block can complete the acquisition of the values of multiple slots through one call to the third-party interface in one block.
Webhook Setting
We can fill in the URL of the third-party interface under Formal setting, and set the timeout time for it.
Interface request format
When sending a request, the values of multiple slots can be concatenated and sent together according to the needs of the third-party interface.
The format of the interface request is as follows:
http://yourhttpserver:port?attr1_name={slot1_name}&attr2_name={_slot2_name}
Among them, there are two ways to write the slot name:
When using {slot1_name}
, if the value belongs to an entity, the normalized value of the entity value will be used uniformly.
When using {_slot1_name}
, the current text value of the slot is used directly.
For example, the user said to the bot on January 1, 2022: "I want to book a conference room for today." The slot "meeting_date" gets the slot value "today", and it is queried that "today" belongs to the "date" entity.
If using:
http://yourhttpserver:port?attr_name={meeting_date}
Then, attr_name="2022-01-01".
If using:
http://yourhttpserver:port?attr_name={_meeting_date}
Then, attr_name="today".
Interface return format
The webhook block can receive the values of multiple slots from the third-party interface, and receive message to be sent to the user.
The value of the slot: usually needs to be returned, otherwise the slot is empty, which affects the dialogue flow.
Message to be sent to the user: optional.
The return parameters of the interface are as follows:
{
"slots": [{
"name":"new_slot_name",
"value":"new_slot_value"
},{
"name":"new_slot_name",
"value":"new_slot_value"
}
],
"msg_body": [{
"data":{
"content": "test text message"
},
"type":"text"
}]
}
Mock Slot Value
If the interface required by the current block has not been developed yet, we can set the interface mock value to facilitate the testing of the subsequent dialogue flow.
For example, in the dialog flow of booking a flight ticket, the bot needs to call a third-party interface to obtain flight information, mainly including flight number and departure time. For smooth testing, we can manually enter flight information in the format shown in the picture below. In this way, when the dialog passes through this block, the bot will use the mock value we filled in to fill the slot, and then successfully enter the subsequent flow.
Routes
Since the webhook block involves third-party interface calls, the interface call may succeed, fail, and return empty results. We can configure a separate branch route for each situation.