Quick Start
On this page we'll get you setup using the SDK to provide a simple "Hello World" reply to a users message.
Last updated
On this page we'll get you setup using the SDK to provide a simple "Hello World" reply to a users message.
Last updated
In this guide we are going to setup a simple web server that can respond to requests. This web server will be triggered using the "webhook" capability within logicdialog. There are just a few steps we'll need to take to get you all setup. These are as follows :
Setting the Webhook URL settings
Building some content that will trigger the webhook
Setting up a project and creating an instance of the Webhook Client
Adding functionality to the project to handle specific types of request
These steps are all described below.
In this example we are going to use ngrok
to provide an internet accessible hostname. You will need to first. Once installed open a command terminal and type
In this case the <server port to expose>
is going to be 8080
.
The command will start and provide to URLs, one on http and the other on https. Make a note of the https
URL as you will need this shortly.
Once you have the URL we'll need to add this to the settings in IA. To do this :
Login to logicdialog
Go to Settings -> Webhook
Set Endpoint to the forwarding URI from ngrok
Please make a note of the JWT secret that is shown on the Webhook settings page. We'll use this to authenticate our requests later.
Using Visual Bot Builder in logicdialog, add new Choice using plus buttons to the far left or right of the existing choices, or add to existing choice by using the plus button on said choice
Choose New Block and then Function Block
Give block a name, and pick module if applicable
If function has not been implemented, leave Todo field ticked, and add Temporary Text, usually a description of function implementation, and add button to simulate response. If you want your webhook to receive an event when this block is hit by a user, "Todo" must be unchecked
Pick Form from dropdown if applicable
Pick Handler Name, note this as it is used when adding handlers to the WebhookClient
We will also need to...
In logicdialog go to the Forms page
Click add new form, and give form a descriptive title
Add new question, or pick one from the question bank
Give descriptive title to question
Write question text, to be displayed when question is asked
Pick input type given to the user, followed by data type
A question can also be added to the question bank from the Question Bank tab
The best way to interact with our API is to use one of our official libraries:
The webhook from IA will make an HTTP request to a webserver containing your application logic. This could be a number of things, including a serverless function however in this example we are going to use express
to host our API. We can setup express
using the following simple bits of code.
This example will allow us to POST
data to the /
endpoint running on port 8080
. First we create an instance of the WebhookClient
which will allow us to handle the request and return various values back to the user. You'll notice on line 13
we construct a handler
which will handle the division-handler
requests. By adding this handler we can build an application that can handle different requests from different parts of the application, each one using a different name that is set in IA on a block by block level. On line 36
the webhook client will handle the request - specifically looking for a handler that matches the incoming requests handle name.
A webhook handler is a simple function that will be called any time a block is triggered from IA. Its passed the webhookReq
object which represents the information in the conversation, and a responseBuilder
that helps you construct a reply to the user.
The following example shows a simple case where one number is divided by another, and an error is thrown if this combination of numbers provides a divide by zero error. A plain text message will be sent back to the user containing the answer.
For more information please see the following pages :