How to use the actions-on-google.DialogflowApp 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 laurenthu / dorothycares / firebase / functions / index.js View on Github external
exports.dorothyCares = functions.https.onRequest((request, response) => {
  // 1. declaring our app so that we can make requests
  const app = new App({
    request,
    response
  });
  // 2. Logging the request
  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));

  function giveRessources(app) {
    // Keeping track of the version of the function that will be deployed
    console.log('give ressources v1.5');
    let technology = app.getArgument(TECH_ARGUMENT);
    // make the request to our api to have the informations
    console.log('https://dorothycares.herokuapp.com/ressources/' + technology);
    https.get('https://dorothycares.herokuapp.com/ressources/' + technology, (res) => {
      // declaring the body
      let body = '';
github NGRP / node-red-contrib-viseo / archives / api-ai / server-api-ai.js View on Github external
const receive = (node, config, req, res) => { 
    let json = req.body
    // try { json = JSON.parse(json); } catch (ex) { console.log('Parsing Error', ex, json) }

    let app = new DialogflowApp({request: req, response: res});

    if(json.originalRequest == undefined) {
        console.log(json);
        node.warn('Empty request received');
        return;
    }

    let data = botmgr.buildMessageFlow({ message : json }, {
        userLocale: 'message.originalRequest.data.user.locale',
        userId:     'message.originalRequest.data.user.userId', 
        convId:     'message.originalRequest.data.conversation.conversationId',
        payload:    'message.originalRequest.data.inputs[0].rawInputs[0].query',
        inputType:  'message.originalRequest.data.inputs[0].rawInputs[0].inputType',
        source:     CARRIER
    })
github google / voice-iot-maker-demo / dialogflow-webhook / 2-app-engine / app.js View on Github external
app.post('/', (req, res) => {
  // grab the ledState value from the Dialogflow webhook
  const assistant = new DialogflowApp({
    request: req,
    response: res
  });

  // define the action map of responses
  const actionMap = new Map();
  actionMap.set(NAME_ACTION, responseHandler);

  // ask Assistant to respond accordingly
  assistant.handleRequest(actionMap);
});
github googlecreativelab / mix-lab / webhook / index.js View on Github external
const initialize = (req, res) => {
    // Our main app website should pass along an extra var with Dialogflow request letting us know
    // where its coming from. Lacking this variable means coming from Home, Dialogflow, Web Simulator etc
    let requestFromFrontend =
        (req.body.originalRequest && req.body.originalRequest["source"] && req.body.originalRequest["source"] === "frontend") || false;

    if (requestFromFrontend) {
        // frontend doesn't yet need any fancy processing, pass the result along from Dialogflow straight back to frontend
        // so they can handle on their own
        res.send(req.body);
    } else if (req.body.result) {
        // we have a result so lets process all this good stuff
        new DialogflowApp({ request: req, response: res }).handleRequest(app => {
            logDebug("handleWebhook() result", req.body.result.fulfillment, req.body.result);
            logDebug("handleWebhook() originalRequest", req.body.originalRequest);

            if (req.body.originalRequest && req.body.originalRequest.data && isHealthCheck(req.body.originalRequest.data)) {
                // send original body through so we don't create anything in datastore
                logDebug("isHealthCheck() true - exiting.");
                return res.send(JSON.stringify(req.body));
            }

            let action = app.getIntent();

            if (action === "input.unknown") {
                handleFallback(req, res);
            } else if (action.includes("followup.")) {
                handleFollowups(app, req.body, res);
            } else {
github DefinitelyTyped / DefinitelyTyped / types / actions-on-google / actions-on-google-tests.ts View on Github external
function testDialogflow(request: express.Request, response: express.Response) {
    const app = new DialogflowApp({request, response});
    const actionMap = new Map();
    actionMap.set(app.StandardIntents.MAIN, () => {
        const order: Transactions.Order = app.buildOrder('foo');
        app.askForTransactionDecision(order, {
            type: app.Transactions.PaymentType.PAYMENT_CARD,
            displayName: 'VISA-1234',
            deliveryAddressRequired: true
        });
    });
    app.handleRequest(actionMap);
}
github googlearchive / interactive-fiction-nodejs / app.js View on Github external
expressApp.post('/', (request, response) => {
  const app = new DialogflowApp({request: request, response: response});
  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));
  const WELCOME_INTENT = 'input.welcome';
  const UNKNOWN_INTENT = 'input.unknown';
  const DIRECTION_INTENT = 'input.directions';
  const DIRECTION_ARGUMENT = 'Directions';
  const LOOK_INTENT = 'input.look';

  const runner = runnerFactory(story, app);
  if (runner === null) {
    throw new Error('Runner not found!');
  }

  const welcomeIntent = (app) => {
    console.log('welcomeIntent');
    runner.started = app.data.hasOwnProperty('restore');
github frogermcs / WaterLog-assistant-app / functions / index.js View on Github external
exports.waterLog = functions.https.onRequest((request, response) => {
    console.log('Request headers: ' + JSON.stringify(request.headers));
    console.log('Request body: ' + JSON.stringify(request.body));

    //Initialise app dependencies
    const dialogflowApp = new DialogflowApp({request, response});
    const userManager = new UserManager(firebaseAdmin);
    const timeManager = new TimeManager(firebaseAdmin, geoTz, moment);
    const waterLog = new WaterLog(firebaseAdmin, timeManager);
    const factsRepository = new FactsRepository(dialogflowApp);

    const chatbase = ChatbaseFactory
        .setApiKey(process.env.MY_CHATBASE_KEY)
        .setPlatform('GoogleAssistant')
        .setUserId(dialogflowApp.getUser().userId);

    const analytics = new Analytics(chatbase);

    const conversation = new Conversation(dialogflowApp, userManager, waterLog, timeManager, factsRepository, analytics);

    //Define map of Dialogflow agent Intents
    let actionMap = new Map();
github googlearchive / dialogflow-trivia-game-nodejs / functions / index.js View on Github external
exports.triviaGame = functions.https.onRequest((request, response) => {
  logger.info(logObject('trivia', 'handleRequest', {
    info: 'Handle request',
    headers: JSON.stringify(request.headers),
    body: JSON.stringify(request.body)
  }));

  const app = new DialogflowApp({request, response});
  const themes = new Themes();

  const userId = app.getUser().userId;
  const userIdKey = utils.encodeAsFirebaseKey(userId);
  let questions = [];
  let answers = [];
  let followUps = [];
  let gameLength = QUESTIONS_PER_GAME;
  let last = false;
  let middle = false;
  let ssmlNoInputPrompts;
  let questionPrompt;
  let selectedAnswers;
  let hasLastPrompt = false;

  const hasScreen = app.hasSurfaceCapability(app.SurfaceCapabilities.SCREEN_OUTPUT);