问题
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