Reputation: 29
I would like avoid asking a users name if it has already been entered earlier in the conversation. How do I set a condition to check if context variable 'sys-person' is empty/null?
Upvotes: 0
Views: 411
Reputation: 76
As suggested by Sayuri, create a context variable for user name and check for this context variable in dialog,
In dialog you can use,
if $nameHere:
then:
your response
If this is mandatory variable then using slots would also be choice, which can check and ask for user name in single node
Upvotes: 0
Reputation: 5330
Watson Conversation has Context variables to you save what you need in your Dialog flow.
The dialog is stateless, meaning that it does not retain information from one interchange with the user to the next. Your application is responsible for maintaining any continuing information that it needs. However, the application can pass information to the dialog, and the dialog can update this information and pass it back to the application. It does so by using
context variables
.A
context variable
is a variable that you define in a node, and optionally specify a default value for. Other nodes or application logic can subsequently set or change the value of thecontext
variable
(like: context.variableName = "Jon").You can condition against
context
variable
values by referencing a context variable from a dialog node condition to determine whether to execute a node. And you can reference acontext variable
from dialog node response conditions to show different reponses depending on a value provided by an external service or by the user.
So, you can simple save the name in one context variable, like:
{
"context": {
"nameHere": "<? @sys-person ?>"
},
"output": {
"text": {
"values": [
"Your name is $nameHere."
],
"selection_policy": "sequential"
}
}
}
And you can access this context variable using $nameHere
. In my JSON example [Advanced JSON] I show one form to you check it.
Upvotes: 2