Creating your first chatbot
To create your first chatbot, we’ll use Google’s new Dialogflow toolset. It harnesses powerful machine learning as well as speech-to-text. It can be incorporated right into your website as a widget or customised to your needs.
Cr eate an account
Go to dialogflow.com and create your account. Sign in and agree to the permissions to enable Dialogflow to have access to your account.
Cr eate an agent
Dialogflow uses the term ‘agent’ to represent instances of your AI. Think of the agent as the virtual intelligence you are creating. You could have many agents working for you, each with its own personality and purpose.
Click on the ‘Create Agent’ button and enter a name for your agent: ‘HAL 9000’.
Cr eate an intent
First, you need to create an Intent. We are defining the ‘intention’ of the user’s inputs. Click ‘Create Intent’ and name it ‘open doors’. Press ‘Save’.
Train the AI for this intent
Train the AI for this intent by providing phrases that a user might use. The NLP AI will use these and derived variations to train the agent. Add the following training phrases in the ‘Training phrases’ window and add as many of your own as you like: ‘Open the Pod bay doors, Hal.’ ‘Open the doors.’ ‘Let me in, Hal!’
Add respons es
Next, you need to add some responses that the agent will respond with. You enter these in the ‘Responses’ window. Try out some like this: ‘I’m afraid I can’t do that, Dave.’’ ‘I can’t do that right now.’ Then press ‘Add Responses’ and ‘Save’ up at the top again. You’ll see notifications that the agent is being trained and then it is ready.
Test out the chatbot
On the right-hand side of the screen is a testing tool. The chatbot will use Google’s speech-to-text service to translate your voice into text if you try that out. You should see the results of your request and the response the AI agent selected. Very cool!
Cr eate and use an ‘e entity
Entities are concepts that can be defined and reused in the agent’s responses as variables.
Let’s train the AI to understand when a user is expressing an emotion then use that in its response to the user.
On the left-hand menu, click ‘Entities’. Type ‘emotion’ for the name of your new entity. Keep ‘Define synonyms’ checked.
Click in the table below and type ‘angry’ as the first emotion. Then click to the right of that and add synonyms such as ‘mad’, ‘upset’, and so on.
Then add another entry for ‘scared’ and use synonyms ‘afraid,’ ‘terrified’, etc., that you like. Press ‘Save’ when done.
This has now trained the Agent to understand that ‘angry’ and ‘scared’ are emotions a user may communicate. All those synonyms are variations that might occur. The AI will generate some as well.
Cr eate a new intent
Now we are going to create a new intent to use the ‘emotion’ entity we have created. Call this intent ‘emotions’ and click ‘Save’.
Next add new training phrases such as ‘you’re scaring me’, ‘you’re making me mad’, and ‘I’m very angry,’ using variations of angry and scared keywords. This will train the agent to understand the various ways that a user may phrase this emotional statement.
You’ll notice the system highlights the scared and angry words for you. It’s already flagging these as entities. It has also added an entry into the ‘Actions and parameters’ window. This enables you to use these entities in your responses, too.
Add a respons e using the new ‘emotion’ entity
In the Responses window, add new responses that use this new entity. Note the ‘$’ to denote the ‘$emotion’ Entity. Try adding these responses: ‘I am sorry you are feeling $emotion, Dave.’ ‘Feeling $emotion is a human response, Dave.’
The technology creates fantastic opportunities but it also comes with a need for responsible, ethical use
Click ‘Add Responses’ and press the ‘Save’ button at the top of the screen to save the entire Intent.
Test your chatbot again
Try saying or typing the following phrases in the testing tool. ‘You’re making me very angry Hal.’ “You’re freaking me out.” Notice how it responded using ‘scared’ with the second one? It used our synonym, ‘freaked out’ to know that we meant scared. Very cool.
Feel free to play around with this as well as add some more intents and responses that you like and then we’ll add this to a web page.
Activate web integration
To add it to your web page, click ‘Integrations’ on the left-hand menu. Then click on the ‘Web Demo’ box to turn that option on.
A pop-up will appear that shows you a direct link so you can use to test your integration out right away. It will also display a code snippet that you can use to drop the widget into your own web site. Copy that snippet to the clipboard so you can paste it into your site.
Cr eate a basic web page and add the sn ippet
Create a basic HMTL page and include that code snippet next. Try out the following code and upload it to your server or run it on your local server. Replace the snippet below with the one you copied from your Dialogflow agent: <! DOCTYPE html> <html> <head> < title>NET - AI Chatbot</ title> </ head> <body> <iframe allow=”microphone;” width=” 350” height=”430” src=” https:// console. dialogflow. com/api- client/demo/ embedded/ bbd27d04-5546- 4b62- 85a5c373575a33aa”> </ iframe> </ body> </ html> Parting thoughts Artificial Intelligence (AI) enables us to create new ways of looking at existing problems, from rethinking environmental strategies to how we learn. Your projects – whether apps, web sites or games – can leverage AI to make them more engaging, easier to use and have more valuable results. The technology creates fantastic opportunities but it also comes with a need for responsible, ethical use. Seek ways to enhance experiences and make life better as you learn and grow.
Above Train the AI for an intent by providing phrases that a user might use Above right Clicking on Web Demo will display a code snippet you can use to drop the widget into your own website