I'm trying to get a simple audio stream playing in a Google Action cloud function. It won't deploy as it says there are errors in the code, but it's not saying where. Here's my code (note the alternatives in *** comments - confusing as I'm not sure which I should be using, having seen both!
const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
const { MediaObject, SimpleResponse } = require('actions-on-google');
const app = actionssdk() // *** or 'const app = conversation()' ?
app.handle("playStream", conv => { // *** or 'app.intent(...' ?
conv.ask(new SimpleResponse("Playing stream"));
conv.ask(new MediaObject({
name: 'My stream',
url: 'https://stream.redacted.url',
description: 'The stream',
icon: new Image({
url: 'https://image.redacted.url', alt: 'Media icon',
}),
}));
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
You seem to be using a mix of actions-on-google
and @assistant/conversation
libraries. You should only be using one or the other, depending on what platform you are using.
If you are using the original Actions SDK, you should use actions-on-google
. If you are using the new Actions SDK or Actions Builder, you should use @assistant/conversation
.
The distinctions are different but will result in problems. actionssdk
has an intent
method but not a handle
method, and vice versa for conversation
. This can result in a syntax error. Also make sure you've imported everything, including Image
.
const functions = require('firebase-functions')
const {
conversation,
Media,
Image,
} = require('@assistant/conversation')
const app = conversation()
app.handle("playStream", conv => {
conv.add("Playing stream");
conv.add(new Media({
mediaObjects: [{
name: 'Media name',
description: 'Media description',
url: 'https://actions.google.com/sounds/v1/cartoon/cartoon_boing.ogg',
image: {
large: new Image({
url: 'https://image.redacted.url',
alt: 'Media icon',
}),
}
}],
mediaType: 'AUDIO',
optionalMediaControls: ['PAUSED', 'STOPPED']
}));
})
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app)
If this still doesn't work, you should add what errors you're seeing in trying to deploy.