Creating your first Chatbot
Version: 4.3.x
Steps to create a Chatbot in EDDI
Prerequisites: Up and Running instance of EDDI (See: Getting started)
General
In order to build a chatbot with EDDI, you will have to create a few configuration files and POST them to the corresponding REST APIs.
A chatbot consists of the following elements:
- A (Regular-) Dictionary to define the inputs from the users as well its meanings resp. categories (called Expressions in EDDI).
- Behavior Rules creating Actions based on decision making with predefined as well as custom conditions.
- Output to answer the users request based on the results from the behavior rule execution.
- Package to align the LifecycleTasks (such as the parser, behavior evaluation, output generation, ...)
- A Bot to align different Packages and Channels.
Follow these steps to create the configuation files you will need:
1. Creating a Regular Dictionary
See also Semantic Parser
Create regular dictionaries in order to store custom words and phrases. A dictionary is there to map user input to expressions, which are later used in Behavior Rules.
a. POST to /regulardictionarystore/regulardictionaries
with an json in the body like this:
e.g. as CURL
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ "language" : "en", \ "words" : [ \ { \ "word" : "hello", \ "exp" : "greeting(hello)", \ "frequency" : 0 \ }, \ { \ "word" : "hi", \ "exp" : "greeting(hi)", \ "frequency" : 0 \ }, \ { \ "word" : "bye", \ "exp" : "goodbye(bye)", \ "frequency" : 0 \ }, \ { \ "word" : "thanks", \ "exp" : "thanks(thanks)", \ "frequency" : 0 \ } \ ], \ "phrases" : [ \ { \ "phrase" : "good afternoon", \ "exp" : "greeting(good_afternoon)" \ }, \ { \ "phrase" : "how are you", \ "exp" : "how_are_you" \ } \ ] \ }' 'http://localhost:7070/regulardictionarystore/regulardictionaries'
Parameters, Dictionary
See also the API documentation at http://localhost:7070/view#!/configurations/createRegularDictionary
Parameter | |
---|---|
langugae | String, mandatory |
words | Array of Word |
phrases | Array of Phrase |
Word.word | String, required. Single word, no spaces. |
Word.exp | String, required. "greeting(hello)": "greeting" is the category of this expression and "hello" is an entity. |
Word.frequency | int, required. Used for a randomizer |
Phrase.phrase | String, required. Spaces allowed |
Phrase.exp | String, required. "greeting(hello)": "greeting" is the category of this expression and "hello" is an entity. |
b. The API returns with HTTP code 201 an URI in the location header referencing the newly created dictionary
with format eddi://ai.labs.regulardictionary/regulardictionarystore/regulardictionaries/<UNIQUE_DICTIONARY_ID>?version=<DICTIONARY_VERSION>
e.g. eddi://ai.labs.regulardictionary/regulardictionarystore/regulardictionaries/5a26d25817312628b46119f9?version=1
Structure of Identifiers
The returned URI is a reference for this specific resource. This recourse will be referenced in the bot definition.
Part of URI | Meaning |
---|---|
eddi:// | This URI is related to a resource with in EDDI |
ai.labs.regulardictionary | Type of resource |
/regulardictionarystore/regulardictionaries | API path |
<UNIQUE_DICTIONARY_ID> | ID of the resources |
<DICTIONARY_VERSION> | Version of this resource |
2. Creating Behavior Rules
See also Behavior Rules
Next, create a behavior rule resource to configure the decision making
a. Make a POST to /behaviorstore/behaviorsets
With an json in the body like this:
Parameters, Behavior Rules
See also the API documentation at http://localhost:7070/view#!/configurations/createBehaviorRuleSet
Parameter | |
---|---|
behaviorGroups | Array of BehaviourGroups |
BehaviourGroup.name | String, e.g. "Smalltalk" |
BehaviourGroup.behaviorRules | Array of BehaviorRule |
BehaviorRule.name | String, e.g. "Greeting" |
BehaviorRule.actions | Array of String, e.g. "greet" or "CONVERSATION_END" |
BehaviorRule.children | Array of RuleChild |
RuleChild.type | String, allowed values:
|
RuleChild.values | HashMap, allowed values:
|
Negation.children | Array of NegationChild |
NegationChild.type | String e.g. "occurrence" |
NegationChild.values | HashMap, allowed values:
|
b. You should again get a return code of 201 with an URI in the location header referencing the newly created behavior rules
eddi://ai.labs.behavior/behaviorstore/behaviorsets/<UNIQUE_BEHAVIOR_ID>?version=<BEHAVIOR_VERSION>
e.g. eddi://ai.labs.behavior/behaviorstore/behaviorsets/5a26d8fd17312628b46119fb?version=1
3. Creating Output
See also Output Configuration.
You have guessed correctly, another POST to /outputstore/outputsets create the bot's Output.
With an JSON in the body like this:
Parameters, Output
See also the API documentation at http://localhost:7070/view#!/configurations/createOutputSet
Parameter | |
---|---|
outputset | Array of Output |
Output.action | String, e.g. "welcome" |
Output.timesOccurred | Integer, e.g. 0 or 1 |
Output.outputs | Array of OutputValue |
OutputValue.type | String, e.g. "text" |
OutputValue.valueAlternatives | Array of String, e.g. ["Welcome!", "Hello!"] |
Output.quickReplies | Array of QuickReply |
QuickReply.value | String, e.g. "Hi"" |
QuickReply.expressions | String, e.g. "greeting(hi)" |
b. You should again get a return code of 201 with an URI in the location header referencing the newly created output
eddi://ai.labs.output/outputstore/outputsets/<UNIQUE_OUTPUTSET_ID>?version=<OUTPUTSET_VERSION>
e.g. eddi://ai.labs.output/outputstore/outputsets/5a26d97417312628b46119fc?version=1
4. Creating the Package
Now we will align the just created LifecycleTasks in the Package. Make a POST to /packagestore/packages
with a json in the body like this:
Parameters, Package
See also the API documentation at http://localhost:7070/view#!/configurations/createPackage
Parameter | |
---|---|
packageextensions | Array of PackageExtension |
PackageExtension.type | possible values, see box "Extension Types" below |
PackageExtension.extensions | Array of Object, optional. |
PackageExtension.config | Config object, Required, but can be empty. |
Extension | Config |
---|---|
eddi://ai.labs.normalizer | To normalize the text, e.g. throw away not allowed characters or convert umlauts. Object "config" has the following parameters:
|
eddi://ai.labs.parser | Dictionaries and/or corrections Object "extensions" can contain "dictionaries" (Array of Dictionary) and/or "corrections" (Array of Correction) Object "Dictionary" has params "type" and "config" (optional) Dictionary.type can reference Regular-Dictionaries ""eddi://ai.labs.parser.dictionaries.regular" (needs param "config.uri") or be one of the EDDI out of the box types:
Object "Correction" has params "type" and "config" (optional)
|
eddi://ai.labs.behavior | Object Config contains param uri with Link to behavior set, e.g. eddi://ai.labs.behavior/behaviorstore/behaviorsets/5a26d8fd17312628b46119fb?version=1 |
eddi://ai.labs.output | Object Config contains param uri with Link to output set, e.g. eddi://ai.labs.output/outputstore/outputsets/5a26d97417312628b46119fc?version=1 |
b. You should again get a return code of 201 with an URI in the location header referencing the newly created package
format eddi://ai.labs.package/packagestore/packages/<UNIQUE_PACKAGE_ID>?version=<PACKAGE_VERSION>
e.g. eddi://ai.labs.package/packagestore/packages/5a2ae60f17312624f8b8a445?version=1
5. Creating a Bot
Make a POST to /botstore/bots
with a JSON like this:
Parameters, Bot
See also the API documentation at http://localhost:7070/view#!/configurations/createBot
Parameter | |
---|---|
packages | Array of String, reference to the package |
channels | Array of Channel, optional |
Channel.type | String, e.g. "eddi://ai.labs.channel.facebook" |
Channel.config | Config Object. For "Facebook" this object has the params "appSecret" (String), "verificationToken" (String), "pageAccessToken" (String) |
b. You should again get a return code of 201 with an URI in the location header referencing the newly created bot
format eddi://ai.labs.bot/botstore/bots/<UNIQUE_BOT_ID>?version=<BOT_VERSION>
e.g. eddi://ai.labs.bot/botstore/bots/5a2ae68a17312624f8b8a446?version=1
6. Launching the Bot
Finally, we are ready to let the bot fly. From here on, you have the possibility to let an UI do it for you or you do it step by step.
The UI that automates these steps can be reached here: /chat/unrestricted/<UNIQUE_BOT_ID>
Otherwise via REST:
- Deploy the Bot
Make a POST to /administration/unrestricted/deploy/<UNIQUE_BOT_ID>?version=<BOT_VERSION>
You will receive a 202 http code- Since deployment could take awhile it has been made asynchronous
- Make a Get to /administration/unrestricted/deploymentstatus/<UNIQUE_BOT_ID>?version=<BOT_VERSION> to find out when it is ready to go
- NOT_FOUND, IN_PROGRESS, ERROR and READY is what you can expect to be returned in the body
- As soon as the Bot is deployed and READY, make a POST to /bots/unrestricted/<UNIQUE_BOT_ID>
- You will receive a 201 with the URI for the newly created Conversation, like this:
- e.g.
eddi://ai.labs.conversation/conversationstore/conversations/<UNIQUE_CONVERSATION_ID>
- e.g.
- You will receive a 201 with the URI for the newly created Conversation, like this:
- Now it's time to start talking to our Bot
- Make a POST to /bots/unrestricted/<UNIQUE_BOT_ID>/<UNIQUE_CONVERSATION_ID>
- Option 1 is to hand over the input text as contentType text/plain
- Include the User Input in the body as text/plain (e.g. Hello)
- Option 2 is to hand over the input as contentType application/json, which also allows you to handover context information that you can use with the eddi configurations
Include the User Input in the body as application/json (e.g. Hello)
{ "input": "some user input" }
- you have two query params you can use to config the returned output
- returnDetailed - default is false - will return all sub results of the entire conversation steps, otherwise only public ones such as input, action, output & quickreplies
- returnCurrentStepOnly - default is true - will return only the latest conversation step that has just been processed, otherwise returns all conversation steps since the beginning of this conversation
- returnDetailed - default is false - will return all sub results of the entire conversation steps, otherwise only public ones such as input, action, output & quickreplies
- Option 1 is to hand over the input text as contentType text/plain
- The output from the bot will be returned as json
- If you are interested in fetching the conversationmemory at any given time, make a Get to /bots/unrestricted/<UNIQUE_BOT_ID>/<UNIQUE_CONVERSATION_ID>?returnDetailed=true (the query param is optional, default is false)
- Make a POST to /bots/unrestricted/<UNIQUE_BOT_ID>/<UNIQUE_CONVERSATION_ID>
If you made it till here, CONGRATULATIONS, you have created your first Chatbot with E.D.D.I
By the way you can use the attached postman collection below to do all of the steps mentioned above by clicking send on each request in postman.
Additional info :
Related articles