app.setContext() in dialogflow v2 api?

筅森魡賤 提交于 2019-12-23 16:21:11

问题


What is the equivalent of dialogflow's app.setContext() from v1 in the v2 API? Given the setup that the migration guide outlines (below), what call would you make to--for example--set a context when the welcome intent is triggered in the demo code below?

// v2
const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');

const app = dialogflow();

app.intent('Default Welcome Intent', conv => {
  conv.ask('How are you?');
});

exports.factsAboutGoogle = functions.https.onRequest(app);

回答1:


Set the context like this:

    const parameters = { // Custom parameters to pass with context
      welcome: true,
    };

    conv.contexts.set('welcome-context', 5, parameters);

The second parametr is for context lifespan.

In your example code:

const functions = require('firebase-functions');
const { dialogflow } = require('actions-on-google');

const app = dialogflow();

app.intent('Default Welcome Intent', conv => {
  conv.ask('How are you?');
  const parameters = { // Custom parameters to pass with context
      welcome: true,
    };
  conv.contexts.set('welcome-context', 5, parameters);
});

exports.factsAboutGoogle = functions.https.onRequest(app);

Then you can access the contexts with:

const contexts = conv.contexts;


来源:https://stackoverflow.com/questions/50109823/app-setcontext-in-dialogflow-v2-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!