This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: 78358585, 77919776, 78607624 Change-Id: I12f323076e0062c116acbf7f4cf891f16a2be339
- Loading branch information
1 parent
23fc0cf
commit f5f0996
Showing
12 changed files
with
121 additions
and
90 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
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
This file was deleted.
Oops, something went wrong.