Discussion: Bot orchestration
See original GitHub issueHello!
For the version 5 we are working on making a chatbot orchestration. You can see an explanation and example in this comment: https://github.com/axa-group/nlp.js/issues/713#issuecomment-724072580
You can see there the commands that are already implemented, but we want to start a dialog to get feedback about which commands can be implemented.
Also, we developed a connector for building bots using CDD (Conversation Driven Development), you can see an example here: https://github.com/axa-group/nlp.js/blob/master/packages/bot/test/bot.test.js#L54 This Unit Tests is able to run the bot and test it using an scenario described in the file scenario01.dlt, with this content:
user> hello
bot> What's your name?
user> John
bot> (Converting name to uppercases...)
bot> Hello JOHN
bot> This is the help
bot> This is the second help
bot> Bye user
So, feel free to comment what features you wish related with conversation orchestration.
Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
No, not on an onIntent because onIntent is part of the NLP, not part of the bot orchestration. But you can do it on a “call”, as explained in this same thread, is used to build actions by yourself.
But ok, step by step.
Ok, now we have the dialog card, that will call the action sendCard, that sends the card. But, how to call this dialog from an intent?
Create an intent where the answer is ‘/dialogCard’
Run the bot, trigger the intent.
Hello, a little update of last version 4.16, and what it includes:
You have an example here: https://github.com/jesus-seijas-sp/nlpjs-examples/blob/master/04.bot
Comments If a line starts with # then is a comment. Example
Import another .dlg If a line starts with import then will import other .dlgs. You can provide several separated by space:
language If a line starts with language it sets a locale for the code until another language command is found.
intents
You can add new intents using dlg. They will be added to the language of the last language command For each intent you can define the utterances, tests and answers
entity In the same way that you can define intents, you can define entities. There are two different kind of entities that you can define: enum and regex.
This code will create two entities: hero and email. Email is a regex entity. Hero is an enum entity with three options: spiderman, ironman and thor. Spiderman is identified when the text “spiderman” or “spider-man” is found.
dialog This will create a new dialog with a pipeline of commands. Example:
say This is the command for the chatbot to say something to the user.
ask This wait for input of the user and store it into a variable. Important: this will not say anything to the user, just wait the input and store it. If you want to say something to the user, use say.
This will store the input from the user in the name variable
run Executes another dialog by name. The dialog execution is an stack that stores also the last position of each dialog on the stack. Example:
nlp This command execute the input from user to the nlp and retrieve the answer. Important thing here: the answre from nlp can be a message to the user or starts by /. If the answer starts by / then it means that is to execute a dialog, so it acts as “run /dialogname”. In the example if you go to the corpus you’ll find this:
https://github.com/jesus-seijas-sp/nlpjs-examples/blob/master/04.bot/corpus.dlg#L502
That means that when someone says ‘Hello’ to the bot, the dialog ‘/hellodialog’ is executed:
inc It will increment a variable by it’s name. You can provide the increment or not, by default is 1. If the variable does not exists, then initialize it to 0 before inc.
dec It will decrement a variable by it’s name. You can provide the decrement or not, by default is 1. If the variable does not exists, then initialize it to 0 before dec.
set This will set a value to a variable. You can provide an expression:
conditions You can add conditions before each command so the command will be execute if the condition is solved to truthy. Just add the condition between square brackets:
The [!user_name] run greet means that the dialog greet will be executed only if the variable user_name does not exists. When the user_name is ADMIN then the user will receive the message “You unblocked admin mode” otherwise the user will receive “Hello {{ user_name }}”
String templating When you see “Hello {{ user_name }}” that means that the part {{ user_name }} will be replaced with the variable user_name from the context.
call This is used to call functions so you can code by yourself actions for the chatbot. In the example you’ll find:
That means that the bot will try to find the function uppers and call it with parameter “user_name”. Important: user_name will not be replaced with the user name from context, user_name will be provided exactly as is, an string with value “user_name”. The function uppers has this code:
The way to register an action is calling bot.registerAction with the name of the action and the function to be executed:
The signature of each action is:
So the action will receive the session object, the context object and the parameters.