variablesbotswatsonwatson-conversationwatson-assistant

Store free text as variable in IBM Watson Assistant


i want to know if theres a way for IBM Watson assistant to store free text or direct input from the user as a variable. I know you can do it with number with the code below here:

"context" : {
    "number_extract" : "<? input.text.extract('[\\d]+',0) ?>"
}

But this only works with numbers. what do you do when you want to store a free text for e.g. a name as a variable?The same code doesn't work for any other text but number so i assume there must be a code which works for text or free text. I would really appreciate your help. Thank you.


Solution

  • The input can be simply accessed using input.text. See this part of the documentation.

    In your sample, an additional extract function is applied to the input string. The parameter to the extract function is a regex string (regular expression search string). In your sample, it searches for the first number. You can also search for other components, our transform the string. See the docs for other functions you can apply.

    I have also collected samples for working with context variables in this GitHub repository.