WebhookClient
The WebhookClient is the entrypoint into the SDK. Here we can setup handlers that will respond to various events from the bot.
A WebhookClient
is instantiated using the JWT Secret found in logicdialog. This is used to call the handler function.
There are two main methods on the Webhook client - handleRequest
and addHandler
handleRequest
The handleRequest
function is called from within a code that has been setup to handle HTTP requests made to your application. This might be part of an express
route, or some other process. The function is passed two arguments. The first of these arguments is the body of the HTTP request which has originated from logicdialog. The second argument provides the authorization token used on the incoming request. This token is used to verify the payload that has been sent has not been modified in transit.
Examples of these function calls are provided below.
addHandler
The addHandler
function allows you to specify a function that can be run to process the data coming in from logicdialog. Much like event subscriptions, this handler is associated with a specific name and as such you can add multiple handlers to a webhook client so that they can handle different types of events from your bot.
The handler that you create is an asynchronous function that accepts two parameters - a WebhookRequest
object and a link to a ResponseBuilder
.
A new WebhookHandler
is initiated as follows :
Once you have created a handler, you can add it to your webhook client using the addHandler
method.
In the example above, only forms in logicdialog that have a handler specified as division-handler
will trigger the function.
Inside the function you can find the parameters that have been set in the conversation within the webhookReq
object. Each form will differ depending on the number and type of questions that are asked to the user however the following example shows how you might access two values of a form.
The formValues
in the example are structured as the following interface:
For more information about constructing a reply to the user, please see the ResponseBuilder
section.
Last updated