diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5171c54
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+node_modules
+npm-debug.log
\ No newline at end of file
diff --git a/levelOne/codelab-level-one.zip b/level1-complete/codelab-level-one.zip
similarity index 100%
rename from levelOne/codelab-level-one.zip
rename to level1-complete/codelab-level-one.zip
diff --git a/levelOne/firebase.json b/level1-complete/firebase.json
similarity index 100%
rename from levelOne/firebase.json
rename to level1-complete/firebase.json
diff --git a/levelOne/functions/.eslintrc.json b/level1-complete/functions/.eslintrc.json
similarity index 100%
rename from levelOne/functions/.eslintrc.json
rename to level1-complete/functions/.eslintrc.json
diff --git a/levelOne/functions/index.js b/level1-complete/functions/index.js
similarity index 69%
rename from levelOne/functions/index.js
rename to level1-complete/functions/index.js
index 9a34e56..3af171c 100644
--- a/levelOne/functions/index.js
+++ b/level1-complete/functions/index.js
@@ -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);
diff --git a/levelOne/functions/package.json b/level1-complete/functions/package.json
similarity index 88%
rename from levelOne/functions/package.json
rename to level1-complete/functions/package.json
index 74c493f..1eb1097 100644
--- a/levelOne/functions/package.json
+++ b/level1-complete/functions/package.json
@@ -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",
diff --git a/levelTwo/codelab-level-two.zip b/level2-complete/codelab-level-two.zip
similarity index 100%
rename from levelTwo/codelab-level-two.zip
rename to level2-complete/codelab-level-two.zip
diff --git a/levelTwo/firebase.json b/level2-complete/firebase.json
similarity index 100%
rename from levelTwo/firebase.json
rename to level2-complete/firebase.json
diff --git a/levelTwo/functions/.eslintrc.json b/level2-complete/functions/.eslintrc.json
similarity index 100%
rename from levelTwo/functions/.eslintrc.json
rename to level2-complete/functions/.eslintrc.json
diff --git a/level2-complete/functions/index.js b/level2-complete/functions/index.js
new file mode 100644
index 0000000..3f7d0e7
--- /dev/null
+++ b/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(`${conv.data.userName}, your lucky number is ` +
+ `${luckyNumber}.` +
+ `Would you like to hear some fake colors?`);
+ } else {
+ conv.ask(`Your lucky number is ${luckyNumber}` +
+ `.` +
+ `Would you like to hear some fake colors?`);
+ }
+});
+
+// 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);
diff --git a/levelTwo/functions/package.json b/level2-complete/functions/package.json
similarity index 88%
rename from levelTwo/functions/package.json
rename to level2-complete/functions/package.json
index 08615e3..d6ed390 100644
--- a/levelTwo/functions/package.json
+++ b/level2-complete/functions/package.json
@@ -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",
diff --git a/levelTwo/functions/index.js b/levelTwo/functions/index.js
deleted file mode 100644
index 88fa90c..0000000
--- a/levelTwo/functions/index.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// 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';
-
-const {
- dialogflow,
- BasicCard,
- Permission
-} = require('actions-on-google');
-const functions = require('firebase-functions');
-
-const app = dialogflow({ debug: true });
-
-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',
-}),
-};
-
-app.intent('Default Welcome Intent', (conv) => {
- conv.ask(new Permission({
- context: 'Hi there, to get to know you better',
- permissions: 'NAME',
- }));
-});
-
-app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
- if (!permissionGranted) {
- conv.ask(`OK, no worries. What's your favorite color?`);
- } else {
- conv.data.userName = conv.user.name.display;
- conv.ask(`Thanks, ${conv.data.userName}. What's your favorite 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) {
- conv.ask(`${conv.data.userName}, your lucky number is ` +
- `${luckyNumber}.` +
- `Would you like to hear some fake colors?`);
- } else {
- conv.ask(`Your lucky number is ${luckyNumber}` +
- `.` +
- `Would you like to hear some fake colors?`);
- }
-});
-
-app.intent('favorite fake color', (conv, { fakeColor }) => {
- conv.close(`Here's the color`, colorMap[fakeColor]);
-});
-
-exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);