1
votes

We have an application that has multiple choice options that then route to other tasks. Currently, we are using samples, but in places where we want strict matching, wrong answers are being selected rather than repeating the question event though the confidence is low. e.g. Samples/Acceptable options: "Option 1","Option 2","Option 3","Option 4"; User answer: "Option 6" which ends up matching "Option 3" instead of re-asking the question. It would be nice to be able to set strict confidence on Samples. Is there a simple way to do this outside of using Functions?

We're programmatically generating schemas and wonder if there is a scalable way to generate functions to meet these needs. Programmatically generating Javascript functions sounds like a nightmare.

1

1 Answers

0
votes

Twilio developer evangelist here.

Sounds like you need to use Collect for this, with a validate property that ensures the answer is among your list of answers.

For example, this would ask for an option between 1 and 4 and only accept the answers "Option 1", "Option 2", "Option 3" or "Option 4":

{
  "actions": [
    {
      "collect": {
        "name": "collect_options",
        "questions": [
          {
            "question": "Please choose an option from 1 to 4",
            "name": "option",
            "validate": {
              "allowed_values": {
                "list": [
                  "Option 1",
                  "Option 2",
                  "Option 3",
                  "Option 4"
                ]
              },
              "on_failure": {
                "messages": [
                  {
                    "say": "Sorry, that's not a valid option."
                  }
                ],
                "repeat_question": true
              },
              "on_success": {
                "say": "Good choice!"
              },
              "max_attempts": {
                "redirect": "task://having-trouble",
                "num_attempts": 3
              }
            }
          }
        ],
        "on_complete": {
          "redirect": "https://example.com/collect"
        }
      }
    }
  ]
}

Let me know if that helps at all.