Create a chatbot
To create a new chatbot log in to the web interface, go to the Answers module, and hit new chatbot.
Start by giving your chatbot a unique name which you can search for later in the Answers dashboard, then select the communication channel. You will only be able to select channels you have enabled in system settings.
Sender selection is not mandatory, however, you will only be able to select from available senders filtered by your selected channel.
Channel elements' availability depends on your selected channel as some channels are more extensive when it comes to supported message types.
For this guide, you will be creating a simple keyword-driven chatbot. Keyword-driven chatbots are equally as powerful as AI-driven bots, however, the customer journey solely relies on response association to keywords, attribute storing, and conditions.
This tutorial is broken up into two main parts. The parameters behind the chatbot's logic, and the physical composition of the chatbot customer journey which end users will experience.
Let's build a simple weather app. Log in to the web interface and head to the Answers dashboard. Once there click Create chatbot to begin. Only users with create permissions can create chatbots.
- Give your chatbot a name (recommended unique), and select the channel you will be using. Define the sender account (optional at this stage), and set the chatbot language. Hit Create chatbot.
- Now you should be in the chatbot editor in Dialogs. Go to the Settings tab if you need to make any immediate edits to the information provided in the previous step. Here you can also add your escape phrases and chatbot timeout logic.
- First, we need to add some keywords for the chatbot to recognize. Go to the Keywords tab. Here, you're going to add all the words which are going to allow your chatbot to understand where to route users in the conversation based on their responses. We are adding keywords now so that we can use them later when building the customer journey.
Make sure to provide as many synonyms as possible for your keywords so that your chatbot doesn't get stuck with what to do.
- Now go to the Attributes tab. Here, you are going to create the custom objects needed to capture and store the specific information we need for this example. As we are expecting various API responses for this chatbot, let's create those attributes to store those responses.
Set the value type depending on what format you are expecting to receive your response in (JSON, XML, etc.)
- Intents are used in AI-powered chatbots running on training phrases enabling the chatbot to work beyond just keyword recognition. Make sure to check out the section on intent-driven chatbots for more information and guides on how to build these types of chatbots.
Now it's time to put your chatbot together! Go back to the Dialogs tab and get ready to build the customer journey.
- The main steps in the customer journey when conversing with chatbots is broken up into dialogs. By default, you will be in the Default dialog, which we will use for a greeting message, and quickly find out what the user wants to know.
Pull the Text element into the editor and add a greeting. Add the Reply button element underneath and present users with a few options to choose from based on your keywords. Set the Postback value to match the relevant keyword.
- Let's create the global dialog structure for this chatbot. Use the +Add dialog option and add dialogs as required for separate topics of conversation. These should correspond to your keywords.
You do not need to populate these dialogs with any channel elements yet. We will come back to this later.
If your dialogs are largely made up of the same content and/or logic, build a base dialog first then use the duplicate option
- Let's add an "end" dialog so that we can redirect users to it when they're finished with their query. Add a new dialog and use the Text element to add a goodbye message. Place the conditions element underneath and add a condition. Set the condition to lastReceivedMessage to is not null.
Place the To dialog element under the condition and select a dialog. Place the Close session element under Else.
- Now go back to the Default dialog and add the User Input element. Select your keywords related to the options you added above. When a user selects an option from your reply button, the chatbot will take that response and route it to the appropriate dialog.
Drag the To dialog element under each user input option and set it to the corresponding dialog matched with the keyword.
Make sure to add a fallback action for the User Input element so that the chatbot knows how to handle unrecognized inputs from the user. Select a dialog to fall back to, or alternatively create a dedicated fallback dialog.
- Your additional dialogs can now be set up and configured as requested as per their dedicated function. For this example, the Forecast dialog makes a call to a weather app via API and saves the response to the dedicated attribute.
Configure the response settings on how to store data from the response, either from headers or from the body. Then add in the desired channel element which will display the response in a readable format to users.
Make sure to route users on to the next steps in the customer journey, for example, back to the main menu, or to the "end" dialog.
There are several ways you can protect your chatbots and the content they capture for use cases which are likely to be dealing with more sensitive information.
Use any or all of the secured chatbot options to add extra layers of security to specific attributes, dialogs, or even entire chatbots.
For this example, we're going to set up authorization for a simple use case using an attribute containing authorization criteria which will be verified against an external database.
- Set up the default dialog as required to route users to the correct dialog where they will initiate authorization. In a new dialog, set up the customer journey so that you will request from them to enter their means of identification (e.g. a customer ID, and email address).
For this, you will need to create a new attribute in the attributes tab where you will store this input. You'll then use this later when calling to your database to match ID records. You'll also need to create another attribute to store the response against.
Make sure this attribute scope is set to Global as you will need it across other dialogs.
- In the chatbot editor, add the authentication dialog using the +Add Authentication Dialog option in the left Dialogs pane and rename the dialog if required.
Upon adding, your authentication dialog will be named Authentication and will already contain the Authenticate element. In the next steps, you'll need to connect this dialog to your customer database, make sure to have the relevant API information available.
- Now create a new dialog where you will ask the user to provide their customer ID. For this use the Attribute channel element and store the response to the newly create customer_id attribute.
Drag the To Dialog element into the editor. Once you have set up an authenticated dialog in step 6, you can set this to the required dialog.
- Now it's time to set up authentication logic. Start by configuring authentication timeout settings by providing a minute value for timeout, alternatively mark authentication to never timeout.
The timeout timer will start from the time the user authenticates. The system will check to see if the user is authenticated when users enter any dialogs secured with authentication. If the timeout has lapsed they will be required to re-authenticate. No progress is lost in the process when users are required to reauthenticate.
Authentication status is saved against the _authenticated_ attribute in the system as a boolean value.
- Connect to your customer database. Drag the API element into the dialog editor and drop it above the Authentication element. You'll be making a call to your database where customer data is stored to be matched against the user's provided credentials.
Set up a header to include an authorization content type and set the value to your customer_id attribute. In this part of the journey, the system will set off a GET request and ask your database if that customer ID matches the customer ID stored in the database, either retuning a fail or success status code.
Add a condition to your dialog to handle success and fail codes. If the status code is a success i.e. 200, it should lead to the Authentication channel element. If the status code indicates a fail it should lead to a dialog which should guide the user on what to do next (e.g. try again, speak to a human, end chat etc.).
- Now authentication is set up you can start securing the dialogs you need with authentication. Note that your default dialog can not use authentication, so you will need to use the To dialog element to take the user to another authenticated dialog.
Under any new dialogs, simply use the lock icon to enable authentication
In doing so, whenever a user lands on a locked dialog, the system will route them to the authentication dialog to either take them through authentication or to check authenticated attribute status.
- If your chatbot is intent-driven you do not need to use the To dialog element as intents work on auto-routing users through the customer journey.
Warning: if at any point you unlock a dialog, you are automatically removing the authentication step