GithubHelp home page GithubHelp logo

actions-on-google / codelabs-nodejs Goto Github PK

View Code? Open in Web Editor NEW
264.0 34.0 187.0 140 KB

Actions on Google Codelabs

Home Page: https://codelabs.developers.google.com/?cat=Assistant

License: Apache License 2.0

JavaScript 100.00%

codelabs-nodejs's Introduction

Actions on Google: Codelabs

⚠️ Warning: Conversational Actions will be deprecated on June 13, 2023. For more information, see Conversational Actions Sunset.

These samples serve as the completed source code for Actions on Google codelabs. The level1-complete directory should be used as a reference for the Level 1 codelab, and as a starting point for the Level 2 codelab. The level2-complete directory can be used as a reference for the Level 2 codelab, and as a starting point for the Level 3 codelab. The level3-complete directory can be used as a reference for the Level 3 codelab.

⚠️ These codelab samples were built using Dialogflow. We now recommend using Actions Builder or the Actions SDK to develop, test, and deploy Conversational Actions.

Setup Instructions

For detailed instructions on using this code, refer to the Actions on Google codelabs, Level 1, 2 and 3. Below are steps to deploy the code for any directory (i.e. level1-complete, level2-complete, or level3-complete).

Steps

  1. Use the Actions on Google Console to add a new project with a name of your choosing and click Create Project.
  2. Scroll down to the More Options section, and click on the Conversational card.
  3. On the left navigation menu under BUILD, click on Actions. Click on Add Your First Action and choose your app's language(s).
  4. Select Custom intent, click BUILD. This will open a Dialogflow console. Click CREATE.
  5. Click on the gear icon to see the project settings.
  6. Select Export and Import.
  7. Select Restore from zip. Follow the directions to restore from the codelab-level-<one/two>.zip file in this repo.
  8. Deploy the fulfillment webhook provided in the functions folder using Google Cloud Functions for Firebase:
    1. Follow the instructions to set up and initialize Firebase SDK for Cloud Functions. Make sure to select the project that you have previously generated in the Actions on Google Console and to reply N when asked to overwrite existing files by the Firebase CLI.
    2. Run firebase deploy --only functions and take note of the endpoint where the fulfillment webhook has been published. It should look like Function URL : https://${REGION}-${PROJECT}.cloudfunctions.net/dialogflowFirebaseFulfillment. If the Function URL doesn't show, you can always check at the Firebase console.
  9. Go back to the Dialogflow console and select Fulfillment from the left navigation menu. Enable Webhook, set the value of URL to the Function URL from the previous step, then click Save.
  10. Select Integrations from the left navigation menu and open the Integration Settings menu for Actions on Google.
  11. Enable Auto-preview changes and Click Test. This will open the Actions on Google simulator.
  12. Type Talk to my test app in the simulator, or say OK Google, talk to my test app to any Actions on Google enabled device signed into your developer account.

For more detailed information on deployment, see the documentation.

References & Issues

Make Contributions

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.

codelabs-nodejs's People

Contributors

atulep avatar canain avatar jmicco avatar lucaswadedavis avatar mandnyc avatar smishra2 avatar taycaldwell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codelabs-nodejs's Issues

Fake colors in codelab 2

I have multiple issues with the fake colors.

In codelab2: step8: point 6 it seems to me the system is supposed to recognize the fake colors: "You should see the "fakeColor" parameter show up under Actions and parameters now that Dialogflow recognizes your custom entity."
When I try this the system instead recognizes ordinary colors:
training phrases

So I tried to edit like this:
edited training phrases

After making the correction suggested by ethai regarding capital 'T' in Title (see Step 8 - Code Lab 2 #34) I do get two of the fake colors to be recognized but not "blue grey coffe" which returns lucky number 4 (probably from "blue") instead. What's wrong here?

I noticed the fakeColor enitity definition automatically added the fake colors a second time after training. Is this the expected behavior? I can't get "Tell me about the first/second/third one" to work either.
entity

Error message is incorrect in Level 2, Step 3

(Side note: I miss the days when code labs were github projects and we could pull request changes, this seems inefficient)

The yellow box below has text that should be updated to match current state.

image

maybe it changed since this was first written, it now reads like this (missing the "from the CLI"):

image

Outdated version of firebase-functions

Level 2, step 3. After running npm -install I got an error reading:

"package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory. Package.json says "firebase-functions": "^1.0.2" while the latest version is 3.0.1

After running this command and adding

"engines": {
"node": "8"
},
to package.json, the deployment worked.

Level 2 Step 4 custom fallback intent overriding implicit invocation at invocation time

At the end of Level 2, Step 4, if I use the deep link when invoking the Action project, the response is the custom fallback intent.

Basically, following the tutorial to the letter works perfectly. Making the 'favorite color' intent an implicit invocation intent works: "Talk to my test app about blue", response is "Your lucky number is 4". Defining the custom fallback intent works: "Talk to my test app about bananas", response is "Sorry, I am not sure about banana. What's your favorite color?".

However, after defining the custom fallback intent, if I try "Talk to my test app about blue", the response is "Sorry, I am not sure about blue. What's your favorite color?" If I then type "blue", the response is as expected, "Your lucky number is 4".

Possibly @sys.any is overriding the implicit invocation intent at invocation time.

Add a Custom Entity - Step #8

In configuring your webhook:

Step 2 - Replace this code:

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

with this:

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

BasicCard,
The ending comma causes issues.

"Select at least one language..." out of order?

When creating a project step 8 says "Select at least one language for your Action, followed by Update. For this codelab, we recommend only selecting English."

I do not see this after clicking "Add an action" (step 7). Is it supposed to happen in Dialog flow after clicking Build?

Glitch in Level 1, Step 5: Fulfillment

The description says to "Turn on Enable webhook call for this intent." but doesn't mention the second setting "Enable webhook call for slot filling".

image

When this setting isn't enabled, testing the intent fails... either the response isn't understood or an error message appears (I can't reproduce the error message though).

Make sure to use nodejs Version 8

Please update the documents to ensure that users (who do not have nodejs) install nodejs version 8.
the the npm install step tries to install grpc, which is not compatible with versions of nodejs newer than 8

Permission intent handler stores name in conv.data instead of conv.user.storage (level 3)

A developer has reported the following:

I had a similar problem but I solved it by replacing the conv.data.userName with conv.user.storage.userName in the below methods of index.js file. Prior to this change, in the actions_intent_PERMISSION method, the username received from conv.user.name.display was set to conv.data.userName instead of being set to our storage variable at conv.user.storage.userName. Since the storage value was never set in the first place, the intent never returned the else part of the Default Welcome Intent method.

// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
  const name = conv.user.storage.userName;
  if (!name) {
    // 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',
    }));
  } else {
    conv.ask(`Hi again, ${name}. What's your favorite color?`);
  }
 });

// 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?`);
    conv.ask(new Suggestions('Blue', 'Red', 'Green'));
  } else {
    // If the user accepted our request, store their name in
    // the 'conv.user.storage.userName' object for the duration of the conversation.
    conv.user.storage.userName = conv.user.name.display;
    conv.ask(`Thanks, ${conv.user.storage.userName}. What's your favorite color?`);
    conv.ask(new Suggestions('Blue', 'Red', 'Green'));
  }
});

// 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.user.storage.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.user.storage.userName}, your lucky number is ` +
      `${luckyNumber}.<audio src="${audioSound}"></audio> ` +
      `Would you like to hear some fake colors?</speak>`);
    conv.ask(new Suggestions('Yes', 'No'));
  } else {
    conv.ask(`<speak>Your lucky number is ${luckyNumber}.` +
      `<audio src="${audioSound}"></audio> ` +
      `Would you like to hear some fake colors?</speak>`);
    conv.ask(new Suggestions('Yes', 'No'));
  }
});

@taycaldwell / @smishra2 to confirm this :) Thanks!

Originally posted by @re3el in #26 (comment)

The code snippets provided in codelab 2 make the user create an intent handler for PERMISSION. In this intent handler, the name of the user is stored using conversation data. When user storage is introduced as a concept in codelab 3, we assume the name will be stored in user storage instead of conversation data, making the developers code out-of-date/sync.

Level 2 - Module 8,error:Sorry, this action is not available for your app.

According to the tutorial (https://codelabs.developers.google.com/codelabs/actions-2/index.html#7), after completing step 8, test on the simulator, when it comes to reply "Would you like to hear some Fake colors?" When I type yes, I get the following error:
Sorry, this action is not available for your app.
In the simulator, you are only able to invoke actions that you have added to your app. For more information on how to invoke your app, click here https://developers.google.com/actions/discovery/explicit

How can I solve it?

Card and suggestions not displayed in simulator

I'm following the level 3 section of the codelab. For some reason, I'm having trouble displaying the basic card in the simulator. I've tried refreshing my browser and flushing my cache. In the firebase function logs and simulator response view, I see that my response has the basicCard item, but it is not displayed in the simulator:

Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Here you go."
              }
            },
            {
              "basicCard": {
                "title": "Indigo Taco",
                "formattedText": "Indigo Taco is a subtle bluish tone.",
                "image": {
                  "url": "https://storage.googleapis.com/material-design/publish/material_v_12/assets/0BxFyKV4eeNjDN1JRbF9ZMHZsa1k/style-color-uiapplication-palette1.png",
                  "accessibilityText": "Indigo Taco Color"
                },
                "imageDisplayOptions": "WHITE"
              }
            },
            {
              "simpleResponse": {
                "textToSpeech": "Do you want to hear about another fake color?"
              }
            }
          ],
          "suggestions": [
            {
              "title": "Yes"
            },
            {
              "title": "No"
            }
          ]
        }
      }
    }
  }
}

And here is the code from the tutorial I'm using to add the card to the response:

const colorMap = {
    'indigo taco': {
        title: 'Indigo Taco',
        text: 'Indigo Taco is a subtle bluish tone.',
        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': {
        title: 'Pink Unicorn',
        text: 'Pink Unicorn is an imaginative reddish hue.',
        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': {
        title: 'Blue Grey Coffee',
        text: 'Calling out to rainy days, Blue Grey Coffee brings to mind your favorite coffee shop.',
        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('favorite fake color', (conv, { fakeColor }) => {
    fakeColor = conv.arguments.get('OPTION') || fakeColor;
    console.log(`[favorite fake color]: fakeColor = ${fakeColor}`);
    // Present user with the corresponding basic card and end the conversation.
    if (!conv.screen) {
        conv.ask(colorMap[fakeColor].text);
    } else {
        conv.ask(`Here you go.`, new BasicCard(colorMap[fakeColor]));
    }
    conv.ask('Do you want to hear about another fake color?');
    conv.ask(new Suggestions('Yes', 'No'));
});

google-action-card-problem

Step 4 "Starting a conversation" no longer works as originally intended

The phone surface seems to have a bug that is causing the testing at the bottom of step 4 to not work as pictured in the code lab. You can see screenshots, etc. here.

The cliff notes are the simulator phone does not say the text that can be clearly seen in the response JSON, that is should be saying.

This can demoralize new developers that are onboarding, and may give up on the platform, presuming it is buggy and unreliable.

A simple and but not great fix would be to add text like "due to a bug in the simulator, please switch your surface to speaker or smart display before testing".

A better fix would be to resolve the problem in the phone surface.

Does the simulator have it's own issue tracker?

Codelab does not work Level 1 part 6

The simulator does not respond to a favourite colour. In fact, it doesn't seem that it works at all apart from the default welcome intent.

I get the error:

Sorry, this action is not available for your app. In the simulator, you are only able to invoke actions that you have added to your app. For more information on how to invoke your app, click here https://developers.google.com/actions/discovery/explicit

I have trained the favorite color intent and added the webhook as outlined but I still get the same response when I input a colour.

Error: A simple response is required in addition to this type of response

In Level 2 - Step 6 it describes how to add speech through SSML to our responses.

However when I follow the instructions I receive the following error in my firebase logs:

Error: A simple response is required in addition to this type of response
    at DialogflowConversation.response (/user_code/node_modules/actions-on-google/dist/service/actionssdk/conversation/conversation.js:267:19)
    at DialogflowConversation.serialize (/user_code/node_modules/actions-on-google/dist/service/dialogflow/conv.js:159:129)
    at Function.<anonymous> (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:157:28)
    at next (native)
    at fulfilled (/user_code/node_modules/actions-on-google/dist/service/dialogflow/dialogflow.js:19:58)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

I can resolve this by modifying the favourite colour intent to look like this:

// 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.close(new SimpleResponse({
            speech: `<speak>${conv.data.userName}, your lucky number is ` +
            `${luckyNumber}.<audio src="${audioSound}"></audio></speak>`,
            text: `${conv.data.userName}, your lucky number is ` + `${luckyNumber}.`,
        }));
    } else {
        conv.close(new SimpleResponse({
            speech: `<speak>Your lucky number is ${luckyNumber}.` +
            `<audio src="${audioSound}"></audio></speak>`,
            text: `Your lucky number is ` + `${luckyNumber}.`,
        }));
    }
});

Could be worth documenting, unless I missed something! -Thanks :)

Step 8 - Code Lab 2

the suggested code references 'title' property which appears to be undefined when the code is executed.

const colorMap = {
  'indigo taco': {
    title: 'Indigo Taco',
    text: 'Indigo Taco is a subtle bluish tone.',
    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': {
    title: 'Pink Unicorn',
    text: 'Pink Unicorn is an imaginative reddish hue.',
    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': {
    title: 'Blue Grey Coffee',
    text: 'Calling out to rainy days, Blue Grey Coffee brings to mind your favorite coffee shop.',
    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',
  },
};

i updated with 'Title' instead to have it working as described in the tutorial

Extra comma in Codelab 2 step 5

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

The comma after Suggestions needs to be removed.

Step 4 - Code Lab 2

The below example of 'Implicit invocation' in the console seems to be confusing because the name of the app 'Personal Chef' is specified in the user query.

screen shot 2018-09-14 at 11 43 24 am

Tell to use `firebase list` to get project id

Where it says:

Tip: Your Action's project ID can be found in the Actions console under Overview > (Gear icon) > Project settings.

It would be better to say:

Tip: Your Action's project ID can be found in the Actions console under Overview > (Gear icon) > Project settings, or with firebase list at the console.

It happens at part 2 and 3.

Code lab breaks design guideline (serial comma) in step 7

In step 7 "Add follow-up intents", this instruction:

Under Responses, add "Which color, indigo taco, pink unicorn or blue grey coffee?" as a Text response.

Is missing a comma after "pink unicorn", per the punctuation design guidelines here. The sentence requires a serial/oxford/harvard comma after the second item in the list.

Also, too trivial for it's own issue, but look at the erratic punctuation at Step 8, instruction 6:

Under Training phrases, type:

- "indigo taco",
- "tell me about pink unicorn"
- "i want to know about blue grey coffee".

The first line has a comma at end, second line has nothing, third has a period. Either add a comma to second or (my preference, as this is a bulleted list) get rid of all the trailing punctuation, to make it consistent for the reader.

firebase deploy error

Can't firebase deploy, appears this error:
Error: Error parsing triggers: Cannot find module 'firebase-admin'

Simulator message is different

Screenshot of simulator in the codelab documentation :
screen shot 2018-09-14 at 11 23 13 am

The message that shows up during testing is pasted below because the app has not been published yet.
screen shot 2018-09-14 at 11 21 18 am

Copy change (Firebase version)

Not sure if I overlooked something on this page: https://codelabs.developers.google.com/codelabs/actions-2/index.html#1.

After installing firebase and running firebase --version I am on version 3.18.5. Which appears to be the correct version (as per the npm badge on https://github.com/firebase/firebase-tools) despite the copy reading

Make sure the version of the Firebase CLI is above 3.5.0 so that it has all the latest features required for Cloud Functions.

Have I misread or is this an error in the version number?

Use storage with a WebhookClient object

In the third Get Started it tells us how to use storage feature to store user preferences throughout different sessions.

Example:

conv.user.storage.userName = 'jdoe';

Can the storage be implemented over a WebhookClient object like:

const agent = new WebhookClient({ request, response });
agent.user.storage.userName = 'jdoe';

If this is not the proper way to use storage with a WebhookClient object, how would it be then?

Sample on colours not responding

I followed all the instructions given in the Google codelabs but after that I'm facing an error that 'final_response must be set'. Also when I try to test it on my Google Assistant, it leaves the conversation in the middle

Missing step in the codelab 2

One step is missing as highlighted in the screenshot.

If the users miss this step, the inline editor will remain enabled and users might not be able to figure out the issue.
screen shot 2018-09-14 at 11 06 16 am

[Build Actions for the Google Assistant (Level 1)] Proposed copy changes

Here are a few changes which should be made to the following codelab:

https://codelabs.developers.google.com/codelabs/actions-1/index.html

  • In part 5, 'Create conversational responses', should remove steps 6 and 7.

  • In part 5, 'Create conversational responses', change the text at the end of the page

After you've completed these steps, Dialogflow will automatically extract parameters it recognizes from user speech which triggers this intent; in this case, the color parameter. Once it obtains this information, Dialogflow makes it available to your fulfillment.

In the next section of this codelab, we'll discuss how to create a Dialogflow webhook that processes the parameter value and handles the intent.

to

After you've completed these steps, Dialogflow will automatically extract parameters it recognizes from user speech which triggers this intent; in this case, the color parameter. Once it obtains this information, Dialogflow makes it available to your fulfillment.

In the next section of this codelab, we'll discuss how to create a Dialogflow fulfilment that processes the parameter value and handles the intent.
  • In part 6, 'Implement a webhook', in the left sidebar

rename

Implement a webhook

to

Implement a fulfilment
  • In part 6, 'Implement a webhook', in the title of the page
6. Implement a webhook

to

6.  Implement a fulfilment

Next, it would have been much clearer to me if the following statement was added to the top of the Fulfillment page:

A Fulfilment is a Webhook which can be implemented as a 'Web Service' or by using 'Inline Editor(Powered by Cloud Functions for Firebase)'.  

Then I would change 'Webhook' to 'Web Service'. Why? A webhook here represents a higher level of abstraction and shouldn't be used as concrete header on the UI.

Level 1, Step 6 wrong answer

after insert the source code in Inline Editor the test on agent don't save the changes .
the response to "Talk to my test app" is "Okay. Getting the test version of my test app.Hi! How are you doing?"

The deploy logs

10:29:36.464 PM warning dialogflowFirebaseFulfillment Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail  
10:29:36.464 PM warning dialogflowFirebaseFulfillment Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail  

Minor text change in "Starting a Conversation"

Just working through this codelab and spotted something quite small:

In "Test the welcome intent" there're a couple of instructions which refer to a screenshot of the Google Assistant Integration. Point 2 reads: "Click Test to update your Actions project and load it into the Actions Console simulator. (If you see a ‘Check auto-preview setting' dialog, you can leave the ‘Auto-preview changes' option is enabled, then click Continue.)"

In the image below there isn't a "Continue" action, just "Test" which is the correct link to click.

basic card in Codelab-2

After Completing Step 8 i.e. adding code to index.js file and then after deploying to firebase, when I test by typing "talk to my test app" the process initiates and assistant responds and asks for my name permission after giving permission it asks for favorite color and I type "Blue" then it replies that "Zaid Kesarani, your lucky number is 4.
Would you like to hear some fake colors?" then I type "yes" but it dose not work and asks again and finally Conversation End! instead of showing basic cards..

Here I attached snapshots:
image
image
image

Here is my index.js code:

// 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 from the Actions on Google client library.
// Import the Dialogflow module and response creation dependencies from the
// Actions on Google client library.
// Import the Dialogflow module and response creation dependencies from the
// Actions on Google client library.
const {
  dialogflow,
  Permission,
  Suggestions,
  BasicCard,
} = 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;
  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>`);
    conv.ask(new Suggestions('Yes', 'No'));
  } else {
    conv.ask(`<speak>Your lucky number is ${luckyNumber}.` +
      `<audio src="${audioSound}"></audio> ` +
      `Would you like to hear some fake colors?</speak>`);
    conv.ask(new Suggestions('Yes', 'No'));
  }
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
  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) {
    conv.ask(`Ok, no worries. What's your favorite color?`);
    conv.ask(new Suggestions('Blue', 'Red', 'Green'));
  } else {
    conv.data.userName = conv.user.name.display;
    conv.ask(`Thanks, ${conv.data.userName}. What's your favorite color?`);
    conv.ask(new Suggestions('Blue', 'Red', 'Green'));
  }
});

// Define a mapping of fake color strings to basic card objects.
const colorMap = {
  'indigo taco': {
    title: 'Indigo Taco',
    text: 'Indigo Taco is a subtle bluish tone.',
    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': {
    title: 'Pink Unicorn',
    text: 'Pink Unicorn is an imaginative reddish hue.',
    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': {
    title: 'Blue Grey Coffee',
    text: 'Calling out to rainy days, Blue Grey Coffee brings to mind your favorite coffee shop.',
    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 '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`, new BasicCard(colorMap[fakeColor]));
});

Error in Followup Intent - Actions on Google Codelab 2, step 7

re: https://codelabs.developers.google.com/codelabs/actions-2/index.html#6

I was trying out the followup intent page (listed above. The dialog would terminate as soon as I entered a color, and I could not enter a followup intent.

I traced the problem to the sample code created in step 5. The 'favorite color' intent handler used the conv.close() construct to issue a response. This immediately terminated the conversation and did not allow for a followup intent.

I fixed this by replacing the conv.close() with conv.ask(). I also changed the text of the response to add the word "Again?", indicating the user should say "yes" or "no" (in line with the followup intent).

The codelab should be fixed to update the 'favorite color' intent handler as described.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.