Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Add comments to codelabs' code
Browse files Browse the repository at this point in the history
Bug: 78358585, 77919776, 78607624
Change-Id: I12f323076e0062c116acbf7f4cf891f16a2be339
  • Loading branch information
lucaswadedavis authored and smishra2 committed Apr 30, 2018
1 parent 23fc0cf commit f5f0996
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 90 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
File renamed without changes.
File renamed without changes.
Expand Up @@ -13,14 +13,22 @@

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
// Respond with the user's lucky number and end the conversation.
conv.close('Your lucky number is ' + luckyNumber);
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Expand Up @@ -13,8 +13,8 @@
},
"dependencies": {
"actions-on-google": "^2.0.0",
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.2"
},
"devDependencies": {
"eslint": "^4.19.0",
Expand Down
File renamed without changes.
File renamed without changes.
107 changes: 107 additions & 0 deletions level2-complete/functions/index.js
@@ -0,0 +1,107 @@
// Copyright 2018, Google, Inc.
// Licensed under the Apache License, Version 2.0 (the 'License');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// Import the Dialogflow module and response creation dependencies
// from the Actions on Google client library.
const {
dialogflow,
BasicCard,
Permission,
} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

// Define a mapping of fake color strings to basic card objects.
const colorMap = {
'indigo taco': new BasicCard({
title: 'Indigo Taco',
image: {
url: 'https://storage.googleapis.com/material-design/publish/material_v_12/assets/0BxFyKV4eeNjDN1JRbF9ZMHZsa1k/style-color-uiapplication-palette1.png',
accessibilityText: 'Indigo Taco Color',
},
display: 'WHITE',
}),
'pink unicorn': new BasicCard({
title: 'Pink Unicorn',
image: {
url: 'https://storage.googleapis.com/material-design/publish/material_v_12/assets/0BxFyKV4eeNjDbFVfTXpoaEE5Vzg/style-color-uiapplication-palette2.png',
accessibilityText: 'Pink Unicorn Color',
},
display: 'WHITE',
}),
'blue grey coffee': new BasicCard({
title: 'Blue Grey Coffee',
image: {
url: 'https://storage.googleapis.com/material-design/publish/material_v_12/assets/0BxFyKV4eeNjDZUdpeURtaTUwLUk/style-color-colorsystem-gray-secondary-161116.png',
accessibilityText: 'Blue Grey Coffee Color',
},
display: 'WHITE',
}),
};

// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
// Asks the user's permission to know their name, for personalization.
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME',
}));
});

// Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
// agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
if (!permissionGranted) {
// If the user denied our request, go ahead with the conversation.
conv.ask(`OK, no worries. What's your favorite color?`);
} else {
// If the user accepted our request, store their name in
// the 'conv.data' object for the duration of the conversation.
conv.data.userName = conv.user.name.display;
conv.ask(`Thanks, ${conv.data.userName}. What's your favorite color?`);
}
});

// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
const audioSound = 'https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.ogg';
if (conv.data.userName) {
// If we collected user name previously, address them by name and use SSML
// to embed an audio snippet in the response.
conv.ask(`<speak>${conv.data.userName}, your lucky number is ` +
`${luckyNumber}<audio src="${audioSound}"></audio>.` +
`Would you like to hear some fake colors?</speak>`);
} else {
conv.ask(`<speak>Your lucky number is ${luckyNumber}` +
`<audio src="${audioSound}"></audio>.` +
`Would you like to hear some fake colors?</speak>`);
}
});

// Handle the Dialogflow intent named 'favorite fake color'.
// The intent collects a parameter named 'fakeColor'.
app.intent('favorite fake color', (conv, {fakeColor}) => {
// Present user with the corresponding basic card and end the conversation.
conv.close(`Here's the color`, colorMap[fakeColor]);
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Expand Up @@ -13,8 +13,8 @@
},
"dependencies": {
"actions-on-google": "^2.0.0",
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.2"
},
"devDependencies": {
"eslint": "^4.19.0",
Expand Down
86 changes: 0 additions & 86 deletions levelTwo/functions/index.js

This file was deleted.

0 comments on commit f5f0996

Please sign in to comment.