Search code examples
node.jswebhooksactions-on-googleapi-ai

Webhook generated list fetch option selected by user


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


Solution

  • 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"
            }
          ],
        ...