Search code examples
ibm-watsonwatson-conversation

How do i extract the original date value passed from the user input


Context: The Watson Conversation bot has a node that gets triggered by three input entities from the user, this works fine, but i want the reply from the bot to be

"Checking if you have a lecture tomorrow. Give me a moment"

then there's a query in the background building up the answer that gets replied later to the user.

the strong word tomorrow is an @sys-date entity, but i want it to reply to the user what he/she said instead of the date, because the bot can check no both weeks months ect, all valid date formats, and the reply would look much better if i could use the original text from the user.

This kind of origin retrieval will be used for other entities aswell when i get it working.


Solution

  • You can use the context variable in the case, and if you want to get specific data, you can use regex to extract the user input:

    Example all user input

    "date": "<? input.text?>"
    

    or for exactly what the user input, ex: "this week"

     "date": "<[email protected]?>"
    

    Etc..

    Use the variable with the .literal, see my complete example:

            {
      "context": {
        "date": "<[email protected]?>"
      },
      "output": {
        "text": {
          "values": [
            "Checking if you have a lecture $date. Give me a moment."
          ],
          "selection_policy": "sequential"
        }
      }
    }
    

    Documentation examples : enter image description here