Search code examples
ibm-cloudibm-watsonwatson-conversation

IBM Watson Conversation: How to dynamically create context variables?


In IBM Watson Conversation, context variables can be used to carry information. A value can be derived from the evaluation of expressions as shown:

"context": {
    "mycity": "<? entities['city'].value ?>"
  }

What I tried is to dynamically compose the variable name:

"context": {
    "my<? @animals ?>": "my new value"
  }

However, the expression in the variable name is not evaluated. How can I define a variable name based on available data such as intents, entities or other context variables?


Solution

  • One solution seems to be to do it in the application:

    • Receive response object including all the metadata.
    • Extract necessary data
    • Compose context object to be passed back into Watson Conversation for next message processing. Create new variables as part of this preparation.
    • Call message API with context object which includes new variable.
    • New variable is available during Watson Conversation-internal processing.