Last active
August 18, 2022 09:45
-
-
Save savelee/a7d42b91a8ab21094505f396e4525c7b to your computer and use it in GitHub Desktop.
Actions on Google starter template (firebase)
This file contains 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
'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); |
This file contains 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
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")); | |
} |
This file contains 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
conv.ask(new Carousel({ | |
items: { | |
[foo[0].title] : { | |
title: foo[0].title, | |
image: new Image({ | |
url: foo[0].img, | |
alt: foo[0].title | |
}) | |
}, | |
[foo[1].title]: { | |
title: "foo[1].title", | |
image: new Image({ | |
url: foo[1].img, | |
alt: foo[1].title | |
}) | |
} | |
} | |
}); |
This file contains 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
// 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', | |
}), | |
}, | |
}, | |
})); |
This file contains 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
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', | |
}), | |
})); |
This file contains 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
{ | |
"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" | |
} | |
} |
This file contains 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
conv.ask( | |
new Suggestions('Show me more.') | |
) |
This file contains 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
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