Search code examples
actions-on-googleactions-builder

In a Quiz, how can i instead of "Say A, B or C" let the user use one of the three response words?


VIA Actions Console, not Dialogflow!
After several days I finally finished to create a Quiz that works like this.
Google Mini says: "What is the capital of France? A) Rome, B) Berlin or C) Paris ?"

In my scene i have two conditions.

scene.slots.status == "FINAL" && intent.params.choosenABC.original == session.params.antwort

AND

!(scene.slots.status == "FINAL" && intent.params.choosenABC.original == session.params.antwort)

So here, these conditions check whether the user says the correct letter coming from the session parameter "antwort". Everything works smooth as long as the user says "A", "B" or "C".

But how can i compare a condition to what the user says?
In the above example i want the user to be able to say "Rome" or "Berlin" or "Paris" and the condition to check these entries.

Thanks in advance!


Solution

  • You have a number of questions packed in there, so let's look at each.

    Does input.params.original exist?

    In short, yes. You can see the documentation of the request Intent object and you'll see that there is intent.params.*name*.original. Your question seems to suggest this would work as well.

    There is also intent.params.*name*.resolved which contains the value after you take type aliases into account.

    I found some variables on a Dialogflow forum...

    Those only work if you're using Dialogflow and don't make any sense when you're looking at Action Builder.

    How to match

    You don't show the possible value of session.params.antwort or how you're setting antwort. But it sounds like it makes sense that you're setting this in a handler. So one thing you could do is to set antwort to the city name (or whatever the full word answer is) and set letter to the letter with the valid reply. Then test both against original to see if there is a match.

    But, to be honest, that starts getting somewhat messy.

    You also don't indicate how the Intent is setup, or if you're using an Entity Type to capture the answer. One great way to handle this, however, is to create a Type that can represent the answers, and use a runtime type override to set what the possible values and aliases for that value are. Then, you can control exactly what the valid value you will use to compare with will be.

    For example, if you create a type named "Answer", then in your fulfillment when you ask the question you can set the possible values for this with something like

    conv.session.typeOverrides = [{
        name: 'Answer',
        mode: 'TYPE_REPLACE',
        synonym: {
          entries: [
            {
              name: 'A',
              synonyms: ['A', 'Rome']
            },
            {
              name: 'B',
              synonyms: ['B', 'Berlin']
           },
           {
              name: 'C',
              synonyms: ['C', 'Paris']
           }
        ]
      }
    }];
    

    If you then have an Intent with a parameter of type Answer with the name answer, then you can test if intent.parameter.answer.resolved contains the expected letter.

    Adding a visual interface

    Using runtime type overrides are particularly useful if you also decide to add support for a visual selection response such as a list. The visual response builds on the runtime type override to add visual aliases that users can select on appropriate devices. When you get the reply, however, it is treated as if they said the entry name.