How to use the actions-on-google.dialogflow function in actions-on-google

To help you get started, we’ve selected a few actions-on-google examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github entertailion / Magnificent-Escape-Action / fulfillment.js View on Github external
const utils = require('./utils');
// Game management functions.
const game = require('./game');
// All the user prompts.
const prompts = game.prompts;
// Google Analytics.
const analytics = game.analytics;

// Import the Dialogflow module from the Actions on Google client library.
// https://github.com/actions-on-google/actions-on-google-nodejs
const {dialogflow, Image, SimpleResponse, BasicCard} = require('actions-on-google');
// Node util module used for creating dynamic strings
const util = require('util');

// Instantiate the Dialogflow client with debug logging enabled.
const app = dialogflow({
  debug: true,
});

// Do common tasks for each intent invocation.
app.middleware((conv, framework) => {
  logger.info(`Intent=${conv.intent}`);
  logger.info(`Type=${conv.input.type}`);
  logger.info(`Raw=${conv.input.raw}`);

  // https://developers.google.com/actions/console/actions-health-check
  conv.isHealthCheck = false;
  if (conv.arguments[game.HEALTH_CHECK_ARGUMENT]) {
    logger.info(`Health check`);
    // Short circuit for health checks to do a simple response in the
    // main welcome intent handler.
    conv.isHealthCheck = true;
github actions-on-google / codelabs-nodejs / level3-complete / functions / index.js View on Github external
// Import the Dialogflow module and response creation dependencies
// from the Actions on Google client library.
const {
  dialogflow,
  BasicCard,
  Permission,
  Suggestions,
  Carousel,
  Image,
} = 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': {
    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: {
github actions-on-google / dialogflow-quotes-nodejs / functions / index.js View on Github external

'use strict';

const {
  dialogflow,
  BasicCard,
  Image,
  SimpleResponse,
} = require('actions-on-google');
const functions = require('firebase-functions');
const fetch = require('isomorphic-fetch');

const URL = 'https://raw.githubusercontent.com/actions-on-google/dialogflow-quotes-nodejs/master/quotes.json';
const BACKGROUND_IMAGE = 'https://lh3.googleusercontent.com/t53m5nzjMl2B_9Qhwc81tuwyA2dBEc7WqKPlzZJ9syPUkt9VR8lu4Kq8heMjJevW3GVv9ekRWntyqXIBKEhc5i7v-SRrTan_=s688';

const app = dialogflow({debug: true});

// Retrieve data from the external API.
app.intent('Default Welcome Intent', (conv) => {
  // Note: Moving this fetch call outside of the app intent callback will
  // cause it to become a global var (i.e. it's value will be cached across
  // function executions).
  return fetch(URL)
    .then((response) => {
      if (response.status < 200 || response.status >= 300) {
        throw new Error(response.statusText);
      } else {
        return response.json();
      }
    })
    .then((json) => {
      // Grab random quote data from JSON.
github myweekinjs / gactions-life-stats / functions / index.js View on Github external
const { dialogflow } = require('actions-on-google')
const functions = require('firebase-functions')
const admin = require('firebase-admin')

// Config file generated through the Firebase admin interface
const serviceAccount = require("./life-stats-168c9-firebase-adminsdk-tiaoj-4c55fe4206.json")

// Initialise the app with the config file
// databaseURL should probably be in a .env file
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://life-stats-168c9.firebaseio.com"
})

// create a dialogflow app
const app = dialogflow({
  debug: true
})

// For the Add Coffee intent
// The coffee variable is passed from DialogFlow far giving the intent several Training Phrases
app.intent('Add Coffee', (conv, { coffees }) => {
  // Print out a request while the DB is being updated
  conv.ask(`Processing your request...`)
  
  // Push the coffee count + a timestamp into the DB
  return admin.database().ref('/coffee').push({
    coffee: parseInt(coffees), // the coffee variable is a string by default
    timestamp: admin.database.ServerValue.TIMESTAMP // used to organise when coffees were consumed
  })
  // Print out a success message
  .then((snapshot) => conv.close(`We've added ${coffees} coffees`))
github actions-on-google / codelabs-nodejs / level2-complete / functions / index.js View on Github external

'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',
github NGRP / node-red-contrib-viseo / node-red-contrib-dialogflow / server-dialogflow.js View on Github external
const helper  = require('node-red-viseo-helper')
const botmgr  = require('node-red-viseo-bot-manager')
const uuidv4 = require('uuid/v4');

const LRUMap = require('./lib/lru.js').LRUMap;
const { Message } = require('./lib/messages.js');
const CARRIER = "GoogleHome"

const { dialogflow } = require('actions-on-google');
let app = dialogflow({ ordersv3: true });


// --------------------------------------------------------------------------
//  NODE-RED
// --------------------------------------------------------------------------


module.exports = function(RED) {
    const register = function(config) {
        RED.nodes.createNode(this, config);
        var node = this;

        start(RED, node, config);
        this.on('close', (done)  => { stop(node, config, done) });
    }
    RED.nodes.registerType("dialogflow-server", register);
github actions-on-google / actions-on-google-nodejs / samples / js / app / facts-about-google / functions / index.js View on Github external
SimpleResponse,
} = require('actions-on-google')

const { values, concat, random, randomPop } = require('./util')
const responses = require('./responses')

const AppContexts = {
  FACT: 'choose_fact-followup',
  CATS: 'choose_cats-followup',
}

const Lifespans = {
  DEFAULT: 5,
}

const app = dialogflow({
  debug: true,
  init: () => ({
    data: {
      facts: responses.categories.reduce((o, c) => { // Convert array of facts to map
        o[c.category] = c.facts.slice()
        return o
      }, {}),
      cats: responses.cats.facts.slice(), // copy cat facts
    },
  }),
})

app.intent('Unrecognized Deep Link Fallback', conv => {
  const response = util.format(responses.general.unhandled, conv.query)
  const suggestions = responses.categories.map(c => c.suggestion)
  conv.ask(response, new Suggestions(suggestions))
github alvarowolfx / codelab-actions-on-google / 03-pizza-bot / snippets / 01.js View on Github external
const INTENT_WELCOME = 'Default Welcome Intent';

/**
 * @param {DialogflowConversation} assistant
 */
function welcomeHandler(assistant) {
  let welcoming = 'Welcome to Mamma Mia Pizza!';
  if (assistant.user.name.display) {
    welcoming = `Welcome to Mamma Mia Pizza, is awesome to have you back ${assistant.user.name.display}!`;
  }
  welcoming += ' What pizza do you want today ?';

  assistant.ask(welcoming);  
}

const app = dialogflow();
app.intent(INTENT_WELCOME, welcomeHandler);

exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
github yoichiro / generator-action / templates / dialogflow.javascript.index.js View on Github external
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');

const app = dialogflow({
  debug: true
});

app.intent('Default Welcome Intent', conv => {
  conv.close('Hello, world!');
});

exports.fulfillment = functions.https.onRequest(app);
github alvarowolfx / talking-plant-aog / functions / conversation.js View on Github external
constructor( plant ) {
    this.plant = plant;

    const app = dialogflow();

    app.intent( ACTION_WELCOME, this.welcomeHandler.bind( this ) );
    app.intent( ACTION_ENVIRONMENT, this.enviromentHandler.bind( this ) );
    app.intent( ACTION_STATUS, this.statusHandler.bind( this ) );
    app.intent( ACTION_WATER_ON, this.waterOnHandler.bind( this ) );
    app.intent( ACTION_WATER_OFF, this.waterOffHandler.bind( this ) );
    app.intent( ACTION_LIGHT_ON, this.lightOnHandler.bind( this ) );
    app.intent( ACTION_LIGHT_OFF, this.lightOffHandler.bind( this ) );

    this.app = app;
  }