Code Monkey home page Code Monkey logo

dialogflow-number-genie-nodejs's Introduction

Actions on Google: Number Genie Sample

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

This sample demonstrates Actions on Google features for use on Google Assistant, including how to steer conversation in a numeric guessing game through the use of localization (French and English), deep links, fallbacks, contexts, alongside rich responses -- using the Node.js client library and deployed on Cloud Functions for Firebase.

This Action uses the i18n-node library to provide responses in both French and English, which are listed in the locales directory. In each function execution, the strings.js setLocale() function is called to set the i18n-node locale based on the user locale in the incoming request. Prompts are then selected by i18n-node from the available languages, defaulting to en if the user's language is unavailable.

⚠️ This code sample was built using Dialogflow. We now recommend using Actions Builder or the Actions SDK to develop, test, and deploy Conversational Actions.

Setup Instructions

Prerequisites

  1. Node.js and NPM
    • We recommend installing using NVM
  2. Install the Firebase CLI
    • We recommend using version 6.5.0, npm install -g [email protected]
    • Run firebase login with your Google account

Configuration

Actions Console

  1. From the Actions on Google Console, New project (this will become your Project ID) > Create project > under More options > Conversational
  2. From the top menu under Develop > Actions (left nav) > Add your first action > BUILD (this will bring you to the Dialogflow console) > Select language and time zone > CREATE.
  3. In the Dialogflow console, go to Settings ⚙ > Export and Import > Restore from zip using the agent.zip in this sample's directory.

Firebase Deployment

  1. On your local machine, in the functions directory, run npm install
  2. Run firebase deploy --project {PROJECT_ID} to deploy the function
    • To find your Project ID: In Dialogflow console under Settings ⚙ > General tab > Project ID.

Dialogflow Console

  1. Return to the Dialogflow Console > select Fulfillment > Enable Webhook > Set URL to the Function URL that was returned after the deploy command > SAVE.
    Function URL (dialogflowFirebaseFulfillment): https://${REGION}-${PROJECT_ID}.cloudfunctions.net/dialogflowFirebaseFulfillment
    
  2. From the left navigation menu, click Integrations > Integration Settings under Google Assistant > Enable Auto-preview changes > Test to open the Actions on Google simulator then say or type Talk to my test app.

Running this Sample

  • You can test your Action on any Google Assistant-enabled device on which the Assistant is signed into the same account used to create this project. Just say or type, “OK Google, talk to my test app”.
  • You can also use the Actions on Google Console simulator to test most features and preview on-device behavior.

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.

dialogflow-number-genie-nodejs's People

Contributors

atulep avatar canain avatar fleker avatar kbielski avatar norulesjustfeels avatar silvolu 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

Watchers

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

dialogflow-number-genie-nodejs's Issues

Error deploying on Firebase

When I try to send the command firebase deploy the CLI give me ann error

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] lint: eslint --fix "**/*.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\david\AppData\Roaming\npm-cache_logs\2018-04-03T13_43_08_308Z-debug.log`

What is this?

input.welcome intent not handled

I imported the project into an app on firebase, deployed it and tried to test it. The default intent I get is input.welcome and I don't see any handler for that in the code. I'm thinking that should be there as that is the intent which starts the game. Am I missing something ?
Handled intents are
const Actions = {
GENERATE_ANSWER: 'generate_answer',
CHECK_GUESS: 'check_guess',
QUIT: 'quit',
PLAY_AGAIN_YES: 'play_again_yes',
PLAY_AGAIN_NO: 'play_again_no',
DEFAULT_FALLBACK: 'input.unknown',
UNKNOWN_DEEPLINK: 'deeplink.unknown',
NUMBER_DEEPLINK: 'deeplink.number',
DONE_YES: 'done_yes',
DONE_NO: 'done_no',
REPEAT: 'repeat'
};

Cannot see number genie nodejs working on simulator.

I followed all the steps mentioned in readme file and successfully able to import the actions and deploy the node on firebase. When I goto the simulator to check then I get default response and get the following error on Google actions simulator:

"message": "Webhook error (206)"

On DialogFlow simulator, in the diagnostic report I see following error in the fulfillment response:

{
  "error": "Converting circular structure to JSON"
}

getRandomPrompt alternates first two elements from array vs. picking random element from array

After the first prompt, getRandomPrompt alternates between the first two elements of the array vs. picking a random element that is not the last prompt.

The code below demonstrates the issue:
https://repl.it/ISpe/2

// Utility function to pick prompts
function getRandomPrompt (app, array) {
  let lastPrompt = app.data.lastPrompt;
  let prompt;
  if (lastPrompt) {
    for (let index in array) {
      prompt = array[index];
      if (prompt != lastPrompt) {
        break;
      }
    }
  } else {
    prompt = array[Math.floor(Math.random() * (array.length))];
  }
  return prompt;
}

// Utility function to pick prompts
function getRandomPrompt_updated (app, array) {
  let lastPrompt = app.data.lastPrompt;
  let filteredArray = array.filter(x => x != lastPrompt)
  return filteredArray[Math.floor(Math.random() * (filteredArray.length))];
}


var app = { data: { }};
const HIGHER_PROMPTS = ['You\'re getting warm. It\'s higher than %s. Have another guess?',
    'Warmer. It\'s also higher than %s. Take another guess.', 'It\'s so close, but it\'s higher than %s.'];
    
console.log("=====Current method=====");
for(let i = 0;i < 20;i++) {
  app.data.lastPrompt = getRandomPrompt(app, HIGHER_PROMPTS);
  console.log(app.data.lastPrompt);
}
console.log("=====Updated method=====");
app = { data: { }};
for(let i = 0;i < 20;i++) {
  app.data.lastPrompt = getRandomPrompt_updated(app, HIGHER_PROMPTS);
  console.log(app.data.lastPrompt);
}

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.