4

I'm pretty new in API.AI and Google Actions. I have a list of items which is generated by a fulfillment. I want to fetch the option selected by user. I've tried reading the documentation but I can't seem to understand it.

https://developers.google.com/actions/assistant/responses#handling_a_selected_item

I also tried setting follow up intents but it wont work. It always ends up giving fallback responses.

I'm trying to search a product or something and the result is displayed using list selector format. I want to fetch the option I selected. This a search_product intent and I have a follow up intent choose_product

enter image description here

enter image description here

enter image description here

lemonade
  • 43
  • 3

4 Answers4

2

You have two options to get information on a Actions on Google list/carousel selection event in API.AI:

  1. Use API.AI's actions_intent_OPTION event

As Prisoner already mentioned, you can create an intent with actions_intent_OPTION. This intent will match queries that include a list/carousel selection as documented here.

  1. Use a webhook

API.AI will pass the list/carousel selection to your webhook which can be retrieved by either:

A) using Google's Action on Google Node.js client library using the app.getContextArgument() method.

B) Use the originalRequest JSON attirbute in the body of the reques to your webhook to retrieve list/carousel selection events. The structure of a list/carousel selection event webhook request will look something like this:

{
  "originalRequest": {
    "data": {
      "inputs": [
        {
          "rawInputs": [
            {
              "query": "Today's Word",
              "inputType": "VOICE"
            }
          ],
          "arguments": [
            {
              "textValue": "Today's Word",
              "name": "OPTION"
            }
          ],
          "intent": "actions.intent.OPTION"
        }
      ],
    ...
mattcarrollcode
  • 3,429
  • 16
  • 16
  • On your point (2), using a webhook doesn't inherently solve the problem, since API.AI still has to match it to an Intent first. You can set your fallback intents to use a webhook, but somewhere you need to handle the logic and determine if it came in from a list (and, if so, which list). – Prisoner Jul 19 '17 at 01:27
1

This is a sideways answer to your question - but if you're new to Actions, then it may be that you're not really understanding the best approaches to designing your own Actions.

Instead of focusing on the more advanced response types (such as lists), focus instead on the conversation you want to have with your user. Don't try to limit their responses - expand on what you think you can accept. Focus on the basic conversational elements and your basic conversational responses.

Once you have implemented a good conversation, then you can go back and add elements which help that conversation. The list should be a suggestion of what the user can do, not a limit of what they must do.

With conversational interfaces, we must think outside the dialog box.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • 2
    well actually the list is really important since it shows the result that matches what the user is searching for. Regarding the basic responses, I don't have any problem with that. I just wanna know how to fetch the option selected from a list/carousel selector. – lemonade Jul 18 '17 at 02:40
1

Include 'actions_intent_OPTION' in the event section of the intent that you are trying to trigger when an item is selected from list/carousel (both work). Then use this code in the function that you will trigger in your webhook instead of getContextArguments() or getItemSelected():

const param = assistant.getArgument('OPTION');

OR app.getArgument('OPTION');

depending on what you named your ApiAiApp (i.e.):

let Assistant = require('actions-on-google').ApiAiAssistant;

const assistant = new Assistant({request: req, response: response});

Then, proceed with how it's done in the rest of the example in the documentation for list/carousel helpers. I don't know exactly why this works, but this method apparently retrieves the actions_intent_OPTION parameter from the JSON request.

gnuhc
  • 105
  • 7
  • This is just *one* line tossed in as an answer. No decent formatting, no explanation. Could you please elaborate how and why this solves the issue? – Paul Kertscher Aug 23 '17 at 04:49
  • I've tried all the other methods such as using getContextArgument() or getItemSelected(), but they weren't working for me like it says on the documentation. I fiddled around with other methods to access arguments and tried 'assistant.getArgument('OPTION')' while adding the event: 'actions_intent_OPTION' to the event part of the intent that will be triggered when an item is selected from list or carousel. It worked for me, but I don't understand exactly why this way works, which deviates from what is said in the documentation. – gnuhc Aug 27 '17 at 23:01
-1

I think the issue is that responses that are generated by clicking on a list (as opposed to being spoken) end up with an event of actions_intent_OPTION, so API.AI requires you to do one of two things:

  1. Either create an Intent with this Event (and other contexts, if you wish, to help determine which list is being handled) like this:

enter image description here

  1. Or create a Fallback Intent with the specific Context you want (ie - not your Default Fallback Intent).

The latter seems like the best approach since it will also cover voice responses.

(Or do both, I guess.)

Prisoner
  • 49,922
  • 7
  • 53
  • 105