ibm-watsonwatson-conversation

How to make Watson capture a sequence of numbers (input.text.extract)


In my example, I ask for a personal documentation number, the number has 11 digits, and I need that in case the user type the 11 numbers correctly the watson continue with the conversation, and if not, the watson will inform a message defined by me. How to do this?

My case: Watson says: All right, I'll check. What is your protocol number?

I says: Ex: 35158811233

Watson says: Would you like to finish the service?

Watson dont reconigze the number and my conversation flows to the finish. Does someone know how to solve this, please?

Watson understands:

  "intents": [
    {
      "intent": "goodbye",
      "confidence": 0.24506947419646477
    }
  ],
  "entities": [],
  "input": {
    "text": "35158811233"
  },
  "output": {
    "log_messages": [],
    "text": [
      "Would you like to finish the service? \n \n <button id=\"button-yes\" onclick=\"yesBye();\">Yes</button> <button id=\"button-no\" onclick=\"noBye();\">No</button>"
    ],

Solution

  • To match numbers with Watson conversation service you can either use the entity sys-number that can be turned on in the entities tab - but this will match all the numbers and yours is a specific one.

    For this use case you can add additional check of the textual user input. The Watson conversation supports regexps checks. If you create a condition of dialog node in this way: input.text.matches('^[^\d]*[\d]{11}[^\d]*$') then this node will match only if the input.text which is an accessor to the exact text String that was submitted by the user will match the regular expression (regexp) defined as ^[^\d]*[\d]{11}[^\d]*$.

    This particular expression will match only if there is 11 digits number in the input and no other digits elsewhere, but additional text in front and after the number is allowed.

    Now to capture this number to a variable you can add the following to the context of the dialog node that is matching this number:

    "context": {
        "number": "<?input.text.extract('^[^\\d]*[\\d]{11}[^\\d]*$',0)?>"
    }
    

    Note that there is different escaping of \\don the context due to JSON nature of the context field.

    In the output text of a dialog node you can then write something like "Ok, number $number was matched." to display the number in the chat window.

    One more thing - great place with info about regexps where you can also try various type of regular expressions and what they match is Regex 101 web page.