Created
February 5, 2019 16:45
-
-
Save Fleker/85bae91407e1b93c7b4a60b56d817f2d to your computer and use it in GitHub Desktop.
Using Cloud Storage for Firebase for hosting rich media in your Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
admin.initializeApp(functions.config().firebase); | |
const bucket = admin.storage().bucket(); | |
const bucketAccessConfig = { | |
action: 'read', | |
expires: Date.now() + 1000 * 60 * 60 | |
}; | |
const {dialogflow, Image, MediaObject} = require('actions-on-google'); | |
const app = new dialogflow(); | |
app.intent('media response', async conv => { | |
const mediaFileRef = bucket.file('audio/long-audio.mp3'); | |
const [mediaUrl] = await mediaFileRef.getSignedUrl(bucketAccessConfig); | |
const iconFileRef = bucket.file('icons/long-audio-icon.png'); | |
const [iconUrl] = await iconFileRef.getSignedUrl(bucketAccessConfig); | |
conv.ask('Here is a media response'); | |
conv.ask(new MediaObject({ | |
name: 'My Media Object', | |
url: mediaUrl, | |
description: 'A funky beat', | |
icon: new Image({ | |
url: iconUrl, | |
alt: 'Media icon' | |
}); | |
})); | |
}); | |
exports.fulfillment = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment