Reputation: 285
I'm trying to return a MediaResponse
object an array of MediaObjects with the actions-on-google Node SDK v2., according to this documentation.
On my phone I just get a generic "Not responding right now" error with nothing specific showing in the console, but running on the simulator I see this error:
UnparseableJsonResponse API Version 2:
Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "(expected_inputs[0].input_prompt.rich_initial_prompt.items[1].media_response.media_objects[0]) media_objects: Cannot find field.".
Here's the code I'm trying to run:
return conv.ask('<speak>some text</speak>')
.add(new MediaResponse({
objects: [
new MediaObject({
url: '{url}',
name: '{title}'
})
],
type: 'AUDIO'
})
)
It works if I just send the MediaObject
back without wrapping it in the MediaResponse, but I want to be able to pass multiple MediaObjects in one response.
Upvotes: 0
Views: 43
Reputation: 11970
I'm not quite sure where your code snippet comes from. The documentation suggests the right way to provide a media response is:
if (!conv.surface.capabilities.has('actions.capability.MEDIA_RESPONSE_AUDIO'))
{
conv.ask('Sorry, this device does not support audio playback.');
return;
}
conv.ask(new MediaObject({
name: 'Jazz in Paris',
url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
description: 'A funky Jazz tune',
icon: new Image({
url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
alt: 'Album cover of an ccean view',
}),
}));
As was pointed out, only one media object can be returned at any given time. You can't provide an array of objects of any size greater than 1.
Upvotes: 2
Reputation: 336
As seen on the Actions On Google documentation:
A media response supports a single media object.
So you can't use multiple media responses while developing Actions. It makes sense considering if the user doesn't have a screen, how would they know how many media responses have returned or how would they choose which one to play?
If you want to play multiple sounds or layer sound effects, you can try using SSML. You would obviously have a time and size limit (120 seconds maximum duration, 5 megabyte file size limit) But it's more flexible when it comes to playback options.
Here's a great article on using SSML to build complex sound compositions on AoG platform by Leon Nicholls.
EDIT: The reason it's not working with one media object might be the lack of suggestion chips. As stated in the Actions On Google documentation
Your Action must include suggestion chips if the response is not a final response.
Basically, you need to add suggestion chips to your response if you're not going to end the conversation.
Another reason might be the protocol error. Again, from the documentation:
The media file for playback must be specified as an HTTPS URL.
If you're using an HTTP url for your mp3 file, it won't play.
Upvotes: 0