我正在使用Dialogflow构建应用程序。用户回答了一些问题,可以稍后查看他们的答案。我的问题是构建服务器以返回用户以前的答案。
这是到目前为止的代码,其中意图是QUESTION_1和QUESTION_2,参数是GRATEFUL_1和GRATEFUL_2:
'use strict';
process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');
// a. the action names from the Dialogflow intents
const QUESTION_1 = 'Question-1';
const QUESTION_2 = 'Question-2';
// b. the parameters that are parsed from the intents
const GRATEFUL_1 = 'any-grateful-1';
const GRATEFUL_2 = 'any-grateful-2';
exports.JournalBot = functions.https.onRequest((request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
// Return the last journal entry
function reflect (app) {
let grateful_1 = app.getArgument(GRATEFUL_1);
app.tell('Here is your previous entry: ' + grateful_1);
}
// Build an action map, which maps intent names to functions
let actionMap = new Map();
actionMap.set(QUESTION_1, reflect);
app.handleRequest(actionMap);
});
我希望'reflect'函数映射到GRATEFUL_2响应以及GRATEFUL_1。我知道如何做到这一点,但是如何更改下一位以包括两个意图:
actionMap.set(QUESTION_1, reflect);
答案 0 :(得分:2)
如果您希望QUESTION_2意图转到df = pd.DataFrame(list(d.items()),columns=['country','count'])
df.head()
country count
0 Germany 3
1 Philippines 8
2 Mexico 9
3 Nigeria 9
4 Saudi Arabia 9
功能,您只需添加
reflect()
但我不认为这是你的问题。在actionMap.set(QUESTION_2, reflect);
内,你需要知道是什么意思让你在那里。
您可以使用reflect()
获取具有意图名称的字符串,然后将其与您要提供的响应相匹配。所以这样的事情可能有用:
app.getIntent()
当然还有其他变种。
您无需实际使用function reflect( app ){
let intent = app.getIntent();
var grateful;
switch( intent ){
case QUESTION_1:
grateful = GRATEFUL_1;
break;
case QUESTION_2:
grateful = GRATEFUL_2;
break;
}
var response = app.getArgument( grateful );
app.tell( 'You previously said: '+response );
}
和actionMap
。如果您有其他方法想要根据意图字符串确定要提供的输出,则可以自由使用它。