Google Actions Simulator Were Sorry
Spelling Practice Game using Google Assistant and Cloud Firestore
1. Overview
The Google Assistant developer platform lets you create software to extend the functionality of Google Assistant, a virtual personal assistant, beyond more than 1 billion devices, including smart speakers, phones, cars, TVs, headphones, and more than. Users appoint the Banana in conversation to get things done, such equally buying groceries or booking a ride. As a programmer, yous can use the Assistant developer platform to easily create and manage delightful and constructive conversational experiences betwixt users and your ain 3rd-political party fulfillment service.
This codelab covers intermediate-level concepts for developing with Google Assistant, Deject Functions, and Cloud Firestore. In this codelab, yous'll build a game chosen "Spelling Practice" that uses Google Banana to ask users to spell words.
What you'll build
In this codelab, you'll build a sophisticated game with the post-obit functionality:
- Receives spelling responses from the user and, depending on the value, modifies the conversational prompts
- Responds with hints related to spelling the word, similar its definition or repeating the word
- Creates a game loop so a user tin interact with the Assistant over again later on spelling the word
Before you start building, yous can interact with the alive Activity on your Google Banana-enabled device by saying "Hey Google, talk to Spelling Do". The default path through this Action for a returning user looks like the following interaction:
When you've finished this codelab, your completed Action volition have the following conversational flow:
What you'll larn
- How to interact with Deject Firestore
- How to apply slots to gather data from the user
- How to procedure a user's input and render a response
- How to use conditions to add logic to a scene
- How to add a game loop
What you'll demand
The prerequisites for this codelab include the following:
- A web browser, such equally Google Chrome
- An IDE to write Cloud Functions.
- A payment method. This codelab utilizes Cloud Functions for Firebase which requires your project to be on the Firebase Blaze pricing programme ( Acquire more).
- A concluding to run shell commands
- Node.js 10 or later
ii. Get the functions code
Clone the GitHub repository from the control line:
$ git clone https://github.com/FirebaseExtended/codelab-actions-firestore
3. Create a Firebase project and Prepare your app
Create a Firebase project
- Sign in to Firebase.
- In the Firebase console, click Add together Project (or Create a project), then name your Firebase projection
Spelling-Practise
.
- Click through the projection cosmos options. Accept the Firebase terms if prompted. Skip setting upwards Google Analytics, because you won't be using Analytics for this app.
To learn more almost Firebase projects, encounter Sympathise Firebase projects.
Upgrade to the Blaze pricing program
In order to use Cloud Functions for Firebase, you'll need to upgrade your Firebase project to the Blaze pricing plan, which means you lot'll attach a Google Cloud Billing account to your project. This requires yous to provide a credit card or other payment method.
All Firebase projects, including those on the Blaze plan, nevertheless take access to the no-cost usage quotas for Deject Functions. The steps outlined in this codelab will fall within the no-cost usage limits. Nonetheless, yous volition see minor charges ( virtually $0.03) from Cloud Storage, which is used to host your Cloud Functions build images.
4. Install the Firebase CLI
The Firebase CLI (command line interface) enables you to deploy your Deject Functions.
There are several options for installing the Firebase CLI depending on your operating system and use instance. The following steps describe the most common selection if you're also using Cloud Functions.
- Make sure yous've installed npm which typically comes with Node.js.
- Install or upgrade the CLI by running the following npm command:
$ npm -g install firebase-tools
- Verify that the CLI has been installed correctly past running:
$ firebase --version
Make sure the version of the Firebase CLI is 9.0.0 or later so that it has all the latest features required for Cloud Functions. If not, run npm install -yard firebase-tools to upgrade as shown above.
- Authorize the Firebase CLI by running:
$ firebase login
- From the spelling-functions-get-go directory, set upwardly the Firebase CLI to utilize your Firebase project. Run the following command, select your Project ID, then follow the instructions. When prompted, you can choose any Allonym, such as
codelab
for instance.
$ firebase apply --add
v. The functions directory
Now you lot'll add functionality using the Firebase SDK for Deject Functions to build the backend for the game, Spelling Practice.
Cloud Functions allows you to have code that runs in the cloud without having to gear up upward a server. This codelab will prove you how to build functions that react to Firebase Hallmark, Cloud Storage, and Firebase Realtime Database events. Let'due south start with Hallmark.
When using the Firebase SDK for Cloud Functions, your functions code will live nether the functions
directory (by default). To brand it easier for yous, we've already created the functions/alphabetize.js
file where your code will get. Experience free to inspect the functions
directory earlier moving forward.
$ cd functions $ ls
Your functions code is likewise a Node.js app, and therefore needs a parcel.json
that gives some information about your app and lists dependencies.
If yous aren't familiar with Node.js, it will aid to larn more about it earlier continuing the codelab.
The package.json
file already lists ii required dependencies: the Firebase SDK for Deject Functions and the Firebase Admin SDK. To install them locally, run npm install
from the functions
directory:
$ npm install
Allow'southward now have a look at the index.js
file:
index.js
/** * Copyright 2021 Google Inc. All Rights Reserved. * ... */ // TODO(DEVELOPER): Import the Deject Functions for Firebase and Firebase Admin modules hither. Also import the Actions SDK here. // TODO(DEVELOPER): Write the getWordDetailsFromDictionaryAPI role here. // TODO(Programmer): Write the createSpellingPracticeWord function hither. // TODO(Developer): Write the app Handle getSpellingWordList office here. // TODO(Programmer): Write the app Handle getSpellingWord function here. // TODO(DEVELOPER): Write the app Handle repeatSpellingWord office hither. // TODO(Programmer): Write the app Handle definitionOfSpellingWord function hither. // TODO(DEVELOPER): Write the app Handle verifySpellingWord function here.
You'll kickoff import the required modules, and then write iv functions in place of the TODOs. Go along to the next step of the codelab to import the modules.
vi. Import the required modules
This codelab requires iii modules.
- The
firebase-functions
module allows u.s. to write the triggers for our Cloud Functions - The
firebase-admin
module allows the states to use the Firebase platform on a server with admin admission, for instance to write to the Cloud Firestore. - The Actions SDK Node.js Fulfillment Library fulfills Deportment SDK handlers for the Google Assistant.
- Install the Actions SDK past running the following npm command:
$ npm install @banana/conversation
- In the
index.js
file, replace the commencement TODO with the following.
These changes import each of the required modules.
Likewise, the Firebase Admin SDK can be configured automatically when deployed on a Deject Functions environment or other Google Cloud container. This is what'due south happening when we call admin.initializeApp();
in the changes beneath.
alphabetize.js
/** * Copyright 2021 Google Inc. All Rights Reserved. * ... */ // Import the Actions SDK const {conversation} = require('@banana/chat'); const https = require('https'); const app = conversation(); const cors = require('cors')({origin: true}); // Import the Firebase SDK for Deject Functions. const functions = require('firebase-functions'); // Import and initialize the Firebase Admin SDK. const admin = crave('firebase-admin'); admin.initializeApp(); // To admission Cloud Firestore const db = admin.firestore(); // TODO(Developer): Write the getWordDetailsFromDictionaryAPI role here. // TODO(DEVELOPER): Write the createSpellingPracticeWord office here. // TODO(DEVELOPER): Write the shuffleWordList role here. // TODO(DEVELOPER): Write the app Handle getSpellingWordList function here. // TODO(DEVELOPER): Write the app Handle getSpellingWord role here. // TODO(DEVELOPER): Write the app Handle repeatSpellingWord function here. // TODO(Developer): Write the app Handle definitionOfSpellingWord function here. // TODO(DEVELOPER): Write the app Handle verifySpellingWord office hither.
Now let's add business logic using functions to support Assistant Actions.
7. Create functions
Get the word definitions and write them to Cloud Firestore
You'll apply the dictionaryapi.dev
public API to become the word definitions.
In the index.js
file, replace the TODO for getWordDetailsFromDictionaryAPI
with the post-obit:
index.js
// Retrieves word definition and audio pronunciation from api.dictionaryapi.dev service // Office uses service provided by https://dictionaryapi.dev/ async office getWordDetailsFromDictionaryAPI(discussion) { let responseData=""; let req = https.request({ host: 'api.dictionaryapi.dev', port: 443, path:'/api/v2/entries/en/' + word, method:'GET' }, (res) => { res.setEncoding('utf8'); res.on('data', d => { responseData+=d; }) res.on('end',function(){ let object = JSON.parse(responseData) const wordListRef = db.collection('wordlist'); wordListRef.dr.(object[0].discussion).set( object[0] ); return responseData; }); }); req.end(); }
Add a Cloud Firestore trigger
Adjacent, you'll create a Cloud Function that triggers whenever a new certificate is created in Deject Firestore. It will telephone call the dictionaryapi.dev
API to go word definitions via the getWordDetailsFromDictionaryAPI
function we wrote just higher up.
In the index.js
file, supersede the TODO for createSpellingPracticeWord
with the following:
index.js
// Firestore trigger that fetches give-and-take definitions through getWordDetailsFromDictionaryAPI for every new Firestore document
exports.createSpellingPracticeWord = functions.firestore .certificate('wordlist/{give-and-take}') .onCreate((snap, context) => { const newValue = snap.data(); const word = newValue.word; getWordDetailsFromDictionaryAPI(give-and-take); });
Get a list of words for the game
You tin can write a Cloud Function that retrieves a listing of spelling practice words from Cloud Firestore for the Assistant. For this, we utilise the app handler.
In the index.js
file, supercede the TODO for getSpellingWordList
with the following.
Adding this function to the special app.handle
is a way of making the function accessible from the Assistant.
index.js
// Store the list of spelling words in Banana session app.handle('getSpellingWordList', conv => { const wordListRef = db.collection('wordlist').limit(50); const snapshot = wordListRef; if (snapshot.empty) { console.log('No matching documents.'); return; } VocabularyList = [] return snapshot.become().then(snapshot => { snapshot.forEach(doc => { if (doc.information().word) { let definition = 'unknown'; let audio = 'unknown'; endeavour { if(doc.data().hasOwnProperty('meanings')) { if(physician.data().meanings[0].hasOwnProperty('definitions')) { definition = doc.data().meanings[0].definitions[0].definition; } } if(doc.data().hasOwnProperty('phonetics')) { if(physician.information().phonetics.length > 0) sound = md.information().phonetics[0].audio; } } catch (fault) { console.log(mistake); } permit obj = { word: physician.information().discussion, answer: doc.data().word.split("").bring together(" "), definition: definition, audio: audio } VocabularyList.push(obj); } // Shuffle the array permit currentIndex = VocabularyList.length, temporaryValue, randomIndex; while (0 !== currentIndex) { randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; temporaryValue = VocabularyList[currentIndex]; VocabularyList[currentIndex] = VocabularyList[randomIndex]; VocabularyList[randomIndex] = temporaryValue; } conv.session.params.vocabWord = VocabularyList; conv.session.params.vocabWordIndex = 0; }); }); })
Go a word from Assistant session
You lot can write a Cloud Function that returns the adjacent spelling give-and-take from the word list.
In the index.js
file, supplant the TODO for getSpellingWord
with the post-obit:
index.js
// Returns a spelling practise word to Google Assistant and uses Speech Synthesis Markup Linguistic communication (SSML) to format the response app.handle('getSpellingWord', conv => { if (!conv.session.params.vocabWord.empty) { conv.session.params.vocabWordIndex+=1; const ssml = '<speak>' + '<sound src="'+ conv.session.params.vocabWord[conv.session.params.vocabWordIndex].audio +'">Use phonetics to spell the word.</audio> ' + '</speak>'; conv.add together(ssml); } else conv.add('Great job! You completed the Spelling exercise'); });
Enable the game to repeat the word
You can write a Cloud Function that repeats the current word for the game.
In the index.js
file, replace the TODO for repeatSpellingWord
with the following:
index.js
// Returns current spelling give-and-take app.handle('repeatSpellingWord', conv => { if (!conv.session.params.vocabWord.empty) { const ssml = '<speak>' + '<sound src="'+ conv.session.params.vocabWord[conv.session.params.vocabWordIndex].audio +'">Use phonetics to spell the word. </sound> ' + '</speak>'; conv.add(ssml); } else conv.add('Great job! Y'all completed the Spelling practice'); });
Get the definition of the word
You tin write a Cloud Role that provides the definition of the current discussion for the game.
In the index.js
file, supplant the TODO for definitionOfSpellingWord
with the following:
alphabetize.js
// Returns spelling word definition from Assistant session parameter app.handle('definitionOfSpellingWord', conv => { conv.add( 'It ways ' + conv.session.params.vocabWord[conv.session.params.vocabWordIndex].definition); });
Check the user'southward spelling response
Yous tin write a Cloud Role that verifies the user's response of how to spell the electric current word for the game.
In the index.js
file, replace the TODO for verifySpellingWord
with the following:
index.js
// Verifies user spelling response app.handle('verifySpellingWord', conv => { attempt { userResponse = conv.intent.params.userresponse.resolved.join(""); if (userResponse.toLowerCase() === conv.session.params.vocabWord[conv.session.params.vocabWordIndex].give-and-take.toLowerCase()) { conv.add('You are right. Say next to go along.'); } else { conv.add together('Sorry, wrong answer. The correct answer is ' + conv.session.params.vocabWord[conv.session.params.vocabWordIndex].answer + ' . Say next to go along.'); } } catch (error) { conv.add together('Sorry. I did not understand your response' ); } }); exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
Deploy all your functions
Your Cloud Functions will only be active after you've deployed them to Firebase.
From the root of the spelling-functions-start
directory, run the following command:
$ firebase deploy --but functions
This is the console output yous should see:
i deploying functions i functions: ensuring necessary APIs are enabled... ⚠ functions: missing necessary APIs. Enabling at present... i env: ensuring necessary APIs are enabled... ⚠ env: missing necessary APIs. Enabling now... i functions: waiting for APIs to activate... i env: waiting for APIs to actuate... ✔ env: all necessary APIs are enabled ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading... i functions: packaged functions (X.XX KB) for uploading ✔ functions: functions folder uploaded successfully i starting release process (may take several minutes)... i functions: creating function createSpellingPracticeWord(us-central1)... ✔ functions[createSpellingPracticeWord(us-central1)]: Successful create operation. i functions: creating part ActionsOnGoogleFulfillment(the states-central1)... ✔ functions[ActionsOnGoogleFulfillment(us-central1)]: Successful create operation. ✔ Deploy complete! Project Console: https://panel.firebase.google.com/project/spelling-practice-1234/overview
Make a note of ActionsOnGoogleFulfillment part Http endpoint url for later use. To go the endpoint, open Firebase Panel and then click spelling-practice project. Open up Functions dashboard to view the functions endpoint.
You take completed adding all the required functions. At present let'south movement to setting upwards Deject Firestore.
viii. Enable Deject Firestore
You'll need to enable Cloud Firestore.
In the Firebase panel'due south Build section, click Firestore. And so, click Create database.
Access to data in Deject Firestore is controlled past Security Rules. Offset you need to set some bones rules on the information to get started. Click Firestore and so In the Rules tab of the Firebase console, add the following rules, then click Publish.
The post-obit rules restrict data access to users who are signed in, which prevents unauthenticated users from reading or writing.
rules_version = 'two'; service cloud.firestore { match /databases/{database}/documents { match /{document=**} { // // Warning: These rules are insecure! We will supervene upon them with // more secure rules later in the codelab // allow read, write: if request.auth != null; } } }
9. Add spelling words data to Deject Firestore
In this pace, you'll write spelling words information to Cloud Firestore so that y'all can generate a list of words for the Assistant (and the game).
Deject Firestore data is structured into collections, documents, fields, and subcollections. Each word for the game will be stored every bit its own certificate in a top-level drove chosen wordlist
. For every new document in the Firestore collection, createSpellingPracticeWord function will be triggered to get the word details from the Dictionary API service.
Create a Cloud Firestore drove
- In the Firebase console, navigate to the Cloud Firestore section.
- Click + Start collection.
- In the Collection ID textbox, enter
wordlist
, so click Next.
Side by side, nosotros'll create a document for a give-and-take: agreement
- In the Certificate ID textbox, enter
agreement
. - In the Field textbox, enter
word
and in the Value textbox enteragreement
. - Click Save.
When you lot add together this document to Cloud Firestore, information technology triggers your createSpellingPracticeWord function to fetch the definition details for the word. Add more words (for example: awe, car, true, tell, better, commute, ...) by creating a new document for each word.
10. Fix Google Assistant
The following sections describe how to set up up your Google Assistant development environs and create your Deportment projection.
Check your Google permission settings
To examination the Action you build in this codelab, you need to enable the necessary permissions so the simulator can admission your Action. To enable permissions, follow these steps:
- Become to the Activity controls page.
- Sign in with your Google Account, if you lot take not already done so.
- Enable the following permissions:
- Web & App Action
- Nether Web & App Activity, select the checkbox adjacent to Include Chrome history and activity from sites, apps, and devices that use Google services.
Create an Actions project
Your Actions project is a container for your Action. To create your Actions project for this codelab, follow these steps:
- Open the Actions console.
- Click New project.
- Accept terms of service
- Blazon in or select
spelling-do-codelab
which you created using Firebase Console. (The name is for your internal reference. Later, y'all tin can set an external proper name for your projection.)
- Click Import project.
- In the What kind of Action do yous want to build? screen, select the Custom card.
- Click Next.
- Select the Blank project carte.
- Click Start building.
- Enter Spelling Practice for display proper name and click salvage.
Users start the chat with your Action through invocation. For example, users can invoke your Action by saying a phrase like "Hey Google, talk to Spelling Practice", where Spelling Do is the display name.
Your Action must have a display name if you lot desire to deploy it to product; however, to test your Activity, you don't need to define the display name. Instead, you tin use the phrase "Talk to my exam app" in the simulator to invoke your Action.
Configure fulfillment
You demand to connect to the Banana the consequence handlers for the Cloud Functions that you wrote and deployed earlier in this codelab.
To configure your fulfillment, follow these steps:
- Click Webhook in the side navigation.
- Select Https endpoint as fulfillment option:
- Enter the URL of your function'due south endpoint in the HTTPs endpoint textbox, so click Save.
In the next department, you'll customize the prompt for your main invocation in the Actions panel.
Gear up upward main invocation
Y'all must edit the principal invocation to define what happens after a user invokes your Action.
Past default, Deportment Builder provides a generic prompt when your invocation is triggered ("Kickoff building your Action past defining main invocation.").
To modify the prompt that your Action sends back to the user when they invoke your Action, follow these steps:
- Click Main invocation in the navigation.
- Check
Call your webhook
and add together the event handler namegetSpellingWordList
in the textbox. - In the code editor, replace the text in the
speech
field with the following welcome bulletin:Welcome to Spelling Exercise
Note: You can utilize either YAML or JSON formatting to edit your prompts.
- Click Save.
Test the main invocation in the simulator
The Deportment console provides a spider web tool for testing your Action called the simulator. The interface simulates hardware devices and their settings, so yous can antipodal with your Action as if it were running on a Smart Display, telephone, speaker, or KaiOS.
To examination your Activeness'southward chief invocation in the simulator, follow these steps:
- In the top navigation bar, click Test to go to the simulator.
- To invoke your Activeness in the simulator, type
Talk to Spelling Practice
in the input field on the acme left, then printing Enter on your keyboard.
When you trigger your Action'southward main invocation, the Assistant responds with your customized welcome message. At this point, the chat ends after the Banana responds with a greeting.
View effect logs
When you are in the Test tab, the panel on the right shows the upshot logs, which display the conversation history every bit event logs. Each event log displays the events that happen during that turn of the conversation. To view the upshot log click the grey icon before the event.
Your Action currently has ane event log, which shows both the user's input ("Talk to Spelling Do") and your Action's response. The following screenshot shows your Action's event log:
eleven. Build the chat for Spelling Do
Now that you lot've divers what happens subsequently a user invokes your Action, yous can build out the rest of your Activeness'due south conversation. Spelling Practice has four scenes, and y'all must actuate each scene earlier it can run. The well-nigh mutual manner to activate a scene is to configure your Action then that, when a user matches a user intent within a scene, that intent triggers the transition to some other scene and activates information technology.
Transition from main invocation to kickoff scene
In this section, you create a new scene called Start
, which sends a prompt to the user asking if they would like to start playing Spelling Do. Yous besides add together a transition from the main invocation to the new Outset
scene.
To create this scene and add a transition to it, follow these steps:
- Click Develop in the top navigation. Then, click Main invocation in the left navigation.
- In the Transition section on the right, click the drop-downwards card, then type
Kickoff
in the text field.
- Click Add. This creates a scene chosen
Start
, and tells the Activity to transition to theGet-go
scene after the Action delivers the welcome prompt to the user. - Click Scenes in the left navigation to evidence the list of scenes.
- Under Scenes, click Outset to see the
Start
scene. - Click + in the On enter department of the
Offset
scene. - Select Send prompts.
- Replace the sentence in the
speech
field (Enter the response that users will see or hear...
) with a question to enquire the user:Use phonetic alphabet to spell the word. For example alpha for a, bravo for b, charlie for c etc. Practise you want to keep?
Suggestion chips offering clickable suggestions for the user that your Action processes equally user input. In this section, you add suggestion chips that announced beneath the prompt you just configured ( Do you want to play
Spelling Practice
?
) to back up users on devices with screens.
To add together suggestion chips to the Starting time
scene's prompt, follow these steps:
- In the
Get-go
scene, click suggestions below the lawmaking editor. This action adds a single suggestion flake. - In the
title
field, replaceSuggested Response
with'Yes'
. - Using the aforementioned formatting, manually add a suggestion flake titled
'No'
and'Help with Phonetics'
. Your code should wait similar the following snippet: - Click Save.
Exam your Action in the simulator
At this point, your Action should transition from the main invocation to the Commencement scene and ask the user if they'd like to go along. Suggestion chips should likewise announced in the simulated display.
To test your Action in the simulator, follow these steps:
- In the navigation bar, click Test to have you to the simulator.
- To examination your Action in the simulator, type
Talk to Spelling Exercise
in the Input field. - Printing Enter. Your Action should respond with the
Main invocation
prompt and the addedGet-go
scene prompt, "Welcome to Spelling Practice. Utilize the phonetic alphabet to spell the give-and-take. For example blastoff for a, bravo for b, charlie for c etc. Practice you want to continue?".
The following screenshot shows this interaction:
- Click the
Yes
orNo
orHelp with Phonetics
suggestion chip to respond to the prompt. (Y'all tin can also say "Yes" or "No" or "Help with Phonetics" or enterYes
orNo
orAssist with Phonetics
in the Input field.)
When you respond to the prompt, your Action responds with a bulletin indicating that information technology can't understand your input: "Deplorable, I didn't catch that. Tin you lot endeavor once more?" Since yous haven't yet configured your Action to sympathize and respond to "Yes" or "No" input, your Action matches your input to a NO_MATCH
intent.
Past default, the NO_MATCH
arrangement intent provides generic responses, only yous can customize these responses to indicate to the user that you lot didn't empathize their input. The Assistant ends the user's conversation with your Action after it tin't lucifer user input iii times.
Add no and phonetics intents
Now that users can respond to the question your Activity poses, you tin configure your Action to understand the users' responses ("Yes" or "No" or "Help with Phonetics"). In the post-obit sections, you create user intents that are matched when the user says "Yep" or "No" or "Assistance with Phonetics" and add together these intents to the Start
scene. We'll utilize organisation intent aye
and will create other intents.
Create no
intent
Now, you need to create the no
intent to empathise and respond to the user when they don't desire to play the game. To create this intent, follow these steps:
- Click Develop in the navigation.
- Click Custom Intents in the navigation to open the list of intents.
- Click + (plus sign) at the end of the list of intents. Name the new intent
no
and press Enter. - Click no to open the
no
intent page. - In the Add training phrases section, click in to the Enter Phrase text box and enter the post-obit phrases:
-
No
-
N
-
I don't want
-
nope
- Click Save.
Add no
intent to Start
scene
Now, the Action can sympathise when a user is expressing "no" or something similar to "no", similar "nope". You need to add the no
user intent to the Offset
scene because the user is responding to the Commencement
prompt ("Welcome to Spelling Practice. Use the phonetic alphabet to spell the give-and-take. For example alpha for a, bravo for b, charlie for c etc. Do you want to go along?").
To add this intent for the Commencement
scene, follow these steps:
- Click the Start scene in the navigation.
- Click the + (plus sign) in the
Showtime
scene next to User intent handling. - In the Intent section, select no in the driblet-downwards.
- Click Send prompts and update the
speech
field with the following text:Skilful Farewell
.
The code in your editor should await similar the following snippet:
candidates: - first_simple: variants: - spoken language: >- Farewell.
- In the Transition department, select Finish conversation from the dropdown.
- Click Save.
Test no
intent in simulator
At this point, your Action understands when the user does not want to play the game and returns the appropriate response.
To test this intent in the simulator, follow these steps:
- In the navigation bar, click Test.
- Type
Talk to Spelling Do
in the Input field and pressEnter
. - Type
No
in the Input field and printing Enter. Alternatively, click the No proffer chip.
Add system Yes
intent to Offset
scene
At present, nosotros'll add together Organisation intent "YES" to the Start
scene, since the user is responding yes to the Start
prompt ("Welcome to Spelling Do. Utilise the phonetic alphabet to spell the word. For example blastoff for a, bravo for b, charlie for c etc. Do y'all want to go on?").
To add together this user intent to the Start
scene, follow these steps:
- Click the Start scene in the navigation.
- Click the + (plus sign) in the
Beginning
scene next to User intent handling. - Under All Organization Intents, Select YES in the intent drib-downwardly.
- Click Call your webhook and update the
issue handler
textbox with the function y'all created earlier:getSpellingWordList
- In the Transition section, click the drop-downwards and select End conversation.
- Click Salve.
Test Aye
intent in simulator
At this point, your Action understands when the user wants to play the game and returns the advisable response.
To test this intent in the simulator, follow these steps:
- In the navigation bar, click Test.
- To test your Action in the simulator, type
Talk to Spelling Practice
in the Input field and press Enter. - Type
Yes
in the Input field and press Enter. Alternatively, click theYeah
suggestion chip.
Your Activeness fetches a list of all spelling practice words and stores them in session. Your Activeness then ends the session because yous selected the Stop chat
transition for the YES
intent.
Create Phonetics
intent
To create the Phonetics
intent, follow these steps:
- Click Develop in the navigation.
- Click Custom Intents in the navigation to open the list of intents.
- Click + (plus sign) at the end of the list of intents. Name the new intent
phonetics
and pressEnter
. - Click the
phonetics
intent to open thephonetics
intent page. - In the Add together preparation phrases department, click the Enter Phrase text box and enter the following phrases:
-
how exercise I spell words
-
phonetics
-
assist me with phonetics
-
phonetic alphabet
- Click Relieve.
Add phonetics
intent to Start
scene
At present, the Action can understand when a user is expressing a "phonetics" intent. You can add the phonetics
user intent to the Start
scene, since the user is responding to the Start
prompt ("Welcome to Spelling Practice. Utilise the phonetic alphabet to spell the discussion. For example blastoff for a, bravo for b, charlie for c etc. Do you want to go along?").
To add this user intent to the Beginning
scene, follow these steps:
- Click the Start scene in the navigation.
- Click the + (plus sign) in the
Get-go
scene side by side to User intent treatment. - Select phonetics in the intent drop-downward.
- In the Transition department, click the driblet-down and select Stop conversation.
- Click Save.
Transition from Start scene to Spelling scene
In this section, you create a new scene called Spelling, which sends a prompt to the user to spell the word using the phonetic alphabet.
To create this scene and add together a transition to it, follow these steps:
- Click Develop in the top navigation. And then, click Kickoff scene in the left navigation.
- In the User intent handling department click
when actions.intent.YES is matched
and on the right in the transition section, click the drop-down menu and typeSpelling
in the text field. - Click Add. This creates a scene called
Spelling
, and tells the Activity to transition to theSpelling
scene subsequently the matching with YES intent. - Aggrandize Scenes in the left navigation to bear witness the list of scenes.
- Under Scenes, click Spelling to run across the
Spelling
scene. - Click + in the On enter section of the
Spelling
scene. - Click Call your webhook and enter getSpellingWord in the event handler textbox.
- Select Send prompts.
- Replace the sentence in the
voice communication
field (Enter the response that users will run into or hear...
) with {}. The actual prompt will be populated by webhook.
Suggestion chips offer clickable suggestions for the user that your Activeness processes as user input.
To add suggestion chips to the Spelling
scene's prompt, follow these steps:
- In the
Spelling
scene, click suggestions below the code editor. This action adds 3 suggestion fries. - In the
title
field, replaceSuggested Response
with'Repeat'
. - Using the same formatting, manually add together a suggestion chip titled
'Skip'
. - Using the same formatting, manually add a proffer chip titled
'Quit'
. Your code should look like the following snippet: - Click Salve.
suggestions: - title: 'Repeat' - championship: 'Skip' - title: 'Quit'
Create Repeat
intent
To create the echo
intent, follow these steps:
- Click Develop in the navigation.
- Click Custom Intents in the navigation to open the list of intents.
- Click + (plus sign) at the finish of the list of intents. Name the new intent
repeat
and pressEnter
. - Click the
repeat
intent to open up thedefinition
intent page. - In the Add grooming phrases section, click the Enter Phrase text box and enter the post-obit phrases:
-
i more time please
-
say the word once again
-
repeat the discussion
-
tell me again
-
repeat
- Click Save.
Add echo
intent to Spelling
scene
Now, the Action tin can understand when a user is expressing a "repeat" intent. You can add the repeat
user intent to the Spelling
scene, since the user is responding to the Spelling
prompt ("Spell the give-and-take using phonetic alphabet").
To add this user intent to the Spelling
scene, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene next to User intent handling. - Select repeat in the intent drop-down.
- Checkthe Call your webhook and enter repeatSpellingWord in the event handler textbox to get the word definition.
- Check Send prompts.
- Replace the sentence in the
speech
field (Enter the response that users will come across or hear...
) with ''. The actual prompt will be populated by webhook.
Add proposition chips to "When Repeat is matched"
- In "When Repeat is matched" under User Intent handling, click suggestions below the lawmaking editor. This action adds iii suggestion fries.
- In the
title
field, replaceSuggested Response
with'Skip'
. - Using the same formatting, manually add a suggestion chip titled
'Quit'
.Your code should look like the following snippet:
suggestions: - championship: 'Skip' - title: 'Quit'
- Click Save.
Create definition
intent
To create the definition
intent, follow these steps:
- Click Develop in the navigation.
- Click Custom Intents in the navigation to open the list of intents.
- Click + (plus sign) at the finish of the list of intents. Name the new intent
definition
and pressEnter
. - Click the
definition
intent to open thedefinition
intent folio. - In the Add training phrases section, click the Enter Phrase text box and enter the following phrases:
-
I would like to know the definition
-
tell me the definition
-
what does information technology mean
-
meaning
-
definition
-
what is the definition?
- Click Save.
Add definition
intent to Spelling
scene
Now, the Activeness tin can understand when a user is expressing a "definition" intent. You can add together the definition
user intent to the Spelling
scene, since the user is responding to the Spelling
prompt ("Spell the word using phonetic alphabet").
To add this user intent to the Spelling
scene, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene next to User intent handling. - Select definition in the intent drop-downward.
- Check the Phone call your webhook and enter definitionOfSpellingWord in the consequence handler textbox to go the give-and-take definition.
- Check Send prompts.
- Supplant the sentence in the
spoken language
field (Enter the response that users will meet or hear...
) with ''`. The actual prompt volition be populated by webhook.
Add together suggestion fries to the webhook response
- In the
Start
scene, click suggestions below the lawmaking editor. This activity adds three proffer chips. - In the
title
field, replaceSuggested Response
with'Skip'
. - Using the same formatting, manually add together a suggestion chip titled
'Quit'
.Your lawmaking should look like the following snippet:
suggestions: - title: 'Skip' - title: 'Quit'
- Click Save.
Create skip
intent
To create the skip
intent, follow these steps:
- Click Develop in the navigation.
- Click Intents in the navigation to open up the list of intents.
- Click + (plus sign) at the end of the list of intents. Name the new intent
skip
and pressEnter
. - Click the
skip
intent to open theskip
intent page. - In the Add training phrases section, click the Enter Phrase text box and enter the following phrases:
-
adjacent word
-
become next
-
next
-
skip
-
skip give-and-take
- Click Save.
Add Skip
intent to Spelling
scene
Now, the Action can understand when a user is expressing a "skip" intent. You can add the skip
user intent to the Spelling
scene, since the user is responding to the Spelling
prompt ("Spell the word using phonetic alphabet").
To add this user intent to the Spelling
scene, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene side by side to User intent handling. - Select skip in the intent drop-down.
- In the Transition department on the correct, click the drop-downwards card and select
Spelling
.
- Click Save.
Create quit
intent
To create the Quit
intent, follow these steps:
- Click Develop in the navigation.
- Click Intents in the navigation to open up the list of intents.
- Click + (plus sign) at the stop of the list of intents. Name the new intent
Quit
and pressEnter
. - Click the
Quit
intent to open the definition intent folio. - In the Add training phrases department, click the Enter Phrase text box and enter the following phrases:
-
I quit
-
Goodbye
-
Abolish
-
Go out
-
Quit
- Click Salvage.
Add Quit
intent to Spelling
scene
At present, the Action can sympathise when a user is expressing a "quit" intent. Yous can add the quit
user intent to the Spelling
scene, since the user is responding to the Spelling
prompt ("Spell the word using phonetic alphabet").
To add together this user intent to the Spelling
scene, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene next to User intent handling. - Select quit in the intent drib-downward.
- In the Transition department on the right, click the drop-down carte and select
End conversation
. - Click Relieve.
Create phonetic_alphabet
type
In this section, you create a new type called phonetic_alphabet
, which specifies the phonetic alphabet options the users can choose to spell the give-and-take. You can besides define a few synonyms for these options in example a user says something similar. In a later section, you add the phonetic_alphabet
type to a slot to specify that you want to obtain the user'south response.
To create the phonetic_alphabet
type, follow these steps:
- Click Develop in the navigation.
- Click the + (plus sign) nether Types.
- Type
phonetic_alphabet
and pressEnter
. - Click
phonetic_alphabet
to open the options. - In the What kind of values volition this Type support? section, select the Words and synonyms pick
- Enter the following entries and respective values in the Add entries section:
a | blastoff, apple tree, amsterdam |
b | bravo, butter, baltimore |
c | charlie, true cat, casablanca |
d | delta, dog, kingdom of denmark |
e | echo, edward, edison |
f | foxtrot, fob, florida |
g | golf, george, gallipoli |
h | hotel, harry, havana |
i | bharat, ink, italy |
j | juliette, johnny, jerusalem |
thou | kilo, king, kilogramme |
l | lima, love, london |
k | mike, money, madagascar |
due north | november, new york, nancy |
o | oscar, orangish, oslo |
p | papa, paris, peter |
q | quebec, queen |
r | romeo, roma, robert |
s | sierra, sugar, santiago |
t | tango, tommy, tripoli |
u | uniform, umbrella, uncle |
v | victor, vinegar, Valencia |
w | whiskey, william, washington |
ten | ten-ray |
y | yankee, yellow, yorker |
z | zulu, zebra, zurich |
Your key-value table should await like the following:
- Click Save.
Configure slot filling
Adjacent, yous demand to configure slot filling in the Spelling scene. To configure the slot-filling logic, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene for Slot filling. - In the Enter slot name field, add together
userresponse
as the slot proper name. - In the Select type drop-down, select phonetic_alphabet equally the slot blazon.
- Check This slot accepts a listing of values
- Cheque This slot is required.
- Select Customize slot value writeback selection and enter userresponse in the session parameter textbox.
- Click Relieve.
Add together Condition to Spelling
screen
To add Status to the Spelling
scene, follow these steps:
- Click the Spelling scene in the navigation.
- Click the + (plus sign) in the
Spelling
scene adjacent to Status. - Enter
scene.slots.status == "Concluding"
as condition - Check the Telephone call your webhook and enter verifySpellingWord in the event handler textbox to verify the user response.
- Check Send prompts.
- Replace the sentence in the
voice communication
field (Enter the response that users will run across or hear...
) with {}. The actual prompt volition be populated by webhook.
Add proffer chips to the webhook response
- In the
Start
scene, click suggestions below the code editor. This activity adds three suggestion chips. - In the
title
field, supervene uponSuggested Response
with'Next'
. - Using the same formatting, manually add a suggestion bit titled
'Quit'
.Your code should look like the following snippet:
suggestions: - title: 'Side by side' - title: 'Quit'
- Click Relieve.
12. Examination Spelling Practice in the simulator
To test your Activity in the simulator, follow these steps:
- In the navigation bar, click Test to take you to the simulator.
- To test your Activeness in the simulator, type
Talk to Spelling Practice
in the Input field. - Press Enter. Your Action should respond with the
Chief invocation
prompt and the addedFirst
scene prompt, "Welcome to Spelling Practice. Use the phonetic alphabet to spell the word. For instance blastoff for a, bravo for b, charlie for c etc. Practice you want to proceed?". - Say Yes to go along
- Simulator will play a word audio to spell
- You lot can spell the give-and-take using phonetic alphabets. For example, for ameliorate say or type "bravo repeat tango tango repeat romeo"
- Simulator volition reply with either the correct or wrong response.
- Say side by side to continue to the side by side word or say quit to exit the game loop.
13. Congratulations
Congratulations, you've successfully built your game, Spelling Practice!
You at present know the key steps required to build a game using Cloud Firestore, Cloud Functions, and Google Assistant Action Builder.
What you covered
- How to interact with Cloud Firestore
- How to use slots to gather data from the user
- How to process a user's input and return a response
- How to utilize weather condition to add logic to a scene
- How to add together a game loop
Additional learning resources
Y'all tin explore these resources for learning about building Actions for Google Banana:
- Documentation for developing Actions for Google Banana
- Deportment on Google GitHub page for sample code and libraries
- The official Reddit community for developers working with the Google Assistant
- Conversation pattern guidelines for best practices and guidelines regarding Conversational Deportment
- Introduction to Cloud Firestore
Clean up your project [recommended]
To avoid incurring possible charges, it is recommended to remove projects that you don't intend to utilize. To delete the projects yous created in this codelab, follow these steps:
- To delete your Firebase project and resources, complete the steps listed in the Shutting down (deleting) projects department.
Caution: Ensure that you select the right projection for deletion on the Google Deject Console's Settings page.
- Optional: To immediately remove your project from the Actions console, complete the steps listed in the Deleting a project section. If you don't complete this step, your project will automatically be removed after approximately 30 days.
Follow @ActionsOnGoogle & @Firebase on Twitter to stay tuned to our latest announcements and tweet to #GoogleIO to share what you lot have built!
Except as otherwise noted, the content of this page is licensed nether the Creative Commons Attribution iv.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Source: https://firebase.google.com/codelabs/firestore-google-assistant
Belum ada Komentar untuk "Google Actions Simulator Were Sorry"
Posting Komentar