DevFest Florida
19 Jan 2019
(mostly)
Software developer / Consultant
Google Developer Expert for Assistant, IoT, Wearables, Identity
http://spiders.com/
http://prisoner.com/
http://prisoner.com/ubi/
A conversation
between you and Google that helps you get things done
in your world.
Actions on Google is the API
that lets you engage in conversations
with other services
through the Google Assistant.
Can you express it as a conversation?
Beware of picking up hitchhiking personalities.
// Import the Dialogflow service function
const {dialogflow} = require('actions-on-google');
const action = dialogflow();
const functions = require('firebase-functions');
exports.webhook = functions.https.onRequest(action);
action.intent('favorite color', conv => {
let color = conv.parameters.color;
conv.ask( `My favorite color is ${color}, too. What would you like to do now?` );
});
const {dialogflow} = require('actions-on-google');
// Add a request-promise module
const rp = require('request-promise-native');
const action = dialogflow();
const functions = require('firebase-functions');
exports.webhook = functions.https.onRequest(action);
action.intent('favorite color', conv => {
let color = conv.parameters.color;
// Options to make the request
let options = {
uri: 'http://www.colourlovers.com/api/colors',
qs: {
keywords: color,
format: "json"
},
json: true
};
// Make the request
return rp(options)
.then( data => {
// Handle the result
conv.ask( `<speak>Did you know that ${data[0].title} has a hex value of`+
` <say-as interpret-as="characters">${data[0].hex}</say-as>.`+
` What would you like to do now?</speak>` );
});
});
const {dialogflow} = require('actions-on-google');
const action = dialogflow();
const functions = require('firebase-functions');
exports.webhook = functions.https.onRequest(action);
function getCredentials( id ){
// Get the user's OAuth credentials from firebase
// Return a Promise
}
function saveUserColor( credentials, name ){
// Use the Google Drive API to create a file using the user's credentials
// Return a Promise
}
action.intent('favorite color', conv => {
let color = conv.parameters.color;
const payload = conv.user.profile.payload;
const id = payload.sub; // OAuth Connect "sub" claim
return getCredentials( id )
.then( credentials => saveUserColor( credentials, color ) )
.then( () => {
conv.ask( `Ok, I've created a file named ${color}. What now?` );
});
});
https://multivocal.info/
const Multivocal = require('multivocal');
exports.webhook = Multivocal.processFirebaseWebhook;
const config = {
Local: {
"en": {
Response: {
"Intent.favorite color": [
"My favorite colour is {{Parameter/color}}, too.",
"I agree, {{Parameter/color}} is rather nice."
]
},
Suffix: {
"Default": [
"What would you like to do now?"
]
}
},
"en-US": {
Response: {
"Intent.favorite color": [
"My favorite color is {{Parameter/color}}, too.",
"I agree, {{Parameter/color}} is very nice."
]
}
}
}
};
new Multivocal.Config.Simple(config);
https://spiders.com/
https://prisoner.com/ubi/
https://actions.google.com/design
https://developers.google.com/actions
Stack Overflow: actions-on-google
https://multivocal.info/