Search code examples
javaaws-lambdadialogflow-esactions-on-google

Google action does not send actions.intent.MEDIA_STATUS


this is my first question on Stack Overflow so if I am messing up in any way please let me know!

I am building a google action that will be able to play podcasts, and I want to play a closing audio clip when the podcast finishes. as far as I can tell from the documentation (https://developers.google.com/actions/assistant/responses#media_responses), at the end of audio playback, the device should send a request containing an actions.intent.MEDIA_STATUS intent. Then i would like to respond to this with the closing audio, but i never get the request.

As for what i have set up so far: I use dialogflow to set up the conversation and then send requests to an AWS Lambda where i have some java code set up to send back the podcast url. I have that part of the media response working - it can play, pause, skip ahead and go back. So far to get the next audio track, i have done the following:

  1. create an intent in Dialogflow (i called this AudioCompleteIntent)
  2. Add actions_intent_MEDIA_STATUS to the "Events" section of the intent (as shown in Handle audio play completion callback in dialogflow (Media responses))
  3. add a dummy training phrase. Not sure if this is necessary, but it was the only way i could get the AudioCompleteIntent to integrate with google actions in the "Actions" section. It would not show up otherwise. I thought that having the intent in the "Actions" section would be necessary for the device to send the request, but maybe it is only for user-initiated intents.
  4. In fulfillment, I have selected "Enable webhook call for this intent" so that i can send the request to the AWS Lambda function. The Lambda function has been logging all requests to the logs

I have attached a screenshot of my intent in Dialogflow. the training phrases still don't always sync with actions but the intent that initializes the conversation seems to work regardless of whether the dialogflow intent shows up in the google actions console AudioCompleteIntent Screenshot

The problem is, I don't see any requests from the device with an actions.intent.MEDIA_STATUS intent. After the podcast finishes playing on its own (not when the user stops it), I am expecting the device to send an actions.intent.MEDIA_STATUS intent to Dialogflow, and then dialogflow will handle this by sending the AudioCompleteIntent to the aws lambda function. I see neither my AudioCompleteIntent request or any sort of actions.intent.MEDIA_STATUS intent in the dialogflow "history" section nor in the aws logs. Both dialogflow/AWS show records of the conversation that starts the podcast though - just nothing at the end of the podcast.

I have been testing with my pixel (pixel 1 from like 2016) phone's google assistant. Apparently, according to Google action MediaResponse not working on some devices there was a bug where some devices would not send the request, but that question is almost a year old so i'm thinking that has been addressed and i have something screwed up on my end. I don't have enough reputation to comment on that post and inquire about a resolution either so I figured i'd ask about my set-up


Solution

  • I ended up getting it to work. The main piece that I was missing was that I needed to have "expectUserResponse" set to True and supply suggestion chips. The example in the current documentation (as of feb 2019) will not play due to to lack of suggestion chips. I removed "expectUserResponse": true from the example and got it to play, but it did not send a actions.intent.MEDIA_STATUS response. Re-introducing "expectUserResponse": true and adding suggestion chips did the trick though

    I cannot include the actual response I sent but here is an edited version of a code sample in the documentation. Specifically, i added suggestion chips to the example under the "Sample Code" section in the DIALOGFLOW JSON tab provided at https://developers.google.com/actions/assistant/responses#media_responses :

    {
      "payload": {
        "google": {
          "expectUserResponse": true,
          "richResponse": {
            "items": [
              {
                "mediaResponse": {
                  "mediaType": "AUDIO",
                  "mediaObjects": [
                    {
                      "contentUrl": "https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3",
                      "description": "A funky Jazz tune",
                      "icon": {
                        "url": "https://storage.googleapis.com/automotive-media/album_art.jpg",
                        "accessibilityText": "Ocean view"
                      },
                      "name": "Jazz in Paris"
                    }
                  ]
                }
              }
            ],
            "suggestions": [
              {
                "title": "pause"
              },
              {
                "title": "start over"
              }
            ]
          },
          "userStorage": "{\"data\":{}}"
        }
      },
      "outputContexts": [
        {
          "name": "/contexts/_actions_on_google",
          "lifespanCount": 99,
          "parameters": {
            "data": "{}"
          }
        }
      ]
    }
    

    thanks to BoneGoat in https://github.com/actions-on-google/actions-on-google-nodejs/issues/247#issuecomment-439617878 for bringing up the importance of looking for a user response on the node.js side of things. hopefully this question will help other Java developers!