Skip to content

Instantly share code, notes, and snippets.

@savelee
Last active August 18, 2022 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save savelee/a7d42b91a8ab21094505f396e4525c7b to your computer and use it in GitHub Desktop.
Save savelee/a7d42b91a8ab21094505f396e4525c7b to your computer and use it in GitHub Desktop.
Actions on Google starter template (firebase)
'use strict';
const functions = require('firebase-functions');
const {
dialogflow,
Suggestions,
Image,
BasicCard,
MediaObject,
List,
Table,
Button,
Carousel,
} = require('actions-on-google');
const app = dialogflow({
debug: true
});
//Route intents
app.intent('intent-name', myFunction);
app.intent('another-intent-name', myFunction2);
function myFunction(){ }
function myFunction2(){ }
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
conv.ask(new BasicCard({
text: foo[0].description,
title: foo[0].name,
subtitle: 'Description',
buttons: new Button({
title: 'This is a button',
url: 'https://assistant.google.com/',
}),
image: new Image({
url: foo[0].img,
accessibilityText: foo[0].name,
}),
display: 'CROPPED',
})
);
if (!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
//there is no screen
conv.ask("What do you prefer? Videogames or Movies?");
} else {
conv.ask("What do you prefer?");
//use suggestion chips to steer the conversation
conv.ask(new Suggestions("Videogames"));
conv.ask(new Suggestions("Movies"));
}
// Create a list
conv.ask(new List({
title: 'List Title',
items: {
// Add the first item to the list
[SELECTION_KEY_ONE]: {
synonyms: [
'synonym of title 1',
'synonym of title 2',
'synonym of title 3',
],
title: 'Title of First List Item',
description: 'This is a description of a list item.',
image: new Image({
url: IMG_URL_AOG,
alt: 'Image alternate text',
}),
},
// Add the second item to the list
[SELECTION_KEY_GOOGLE_HOME]: {
synonyms: [
'Google Home Assistant',
'Assistant on the Google Home',
],
title: 'Google Home',
description: 'Google Home is a voice-activated speaker powered by ' +
'the Google Assistant.',
image: new Image({
url: IMG_URL_GOOGLE_HOME,
alt: 'Google Home',
}),
},
// Add the third item to the list
[SELECTION_KEY_GOOGLE_PIXEL]: {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: 'Google Pixel',
description: 'Pixel. Phone by Google.',
image: new Image({
url: IMG_URL_GOOGLE_PIXEL,
alt: 'Google Pixel',
}),
},
},
}));
conv.ask(new MediaObject({
name: 'Jazz in Paris',
url: 'http://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
description: 'A funky Jazz tune',
icon: new Image({
url: 'http://storage.googleapis.com/automotive-media/album_art.jpg',
alt: 'Media icon',
}),
}));
{
"name": "fullfillmentapp",
"description": "My fulfillment",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Lee Boonstra",
"engines": {
"node": "~6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.3.0",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7"
}
}
conv.ask(
new Suggestions('Show me more.')
)
conv.ask(new Table({
dividers: true,
columns: ['header 1', 'header 2', 'header 3'],
rows: [
['row 1 item 1', 'row 1 item 2', 'row 1 item 3'],
['row 2 item 1', 'row 2 item 2', 'row 2 item 3'],
],
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment