【发布时间】:2020-07-23 21:32:19
【问题描述】:
A.我做的步骤
- 创建了新的机器人
- 使用@sys.geo-country.country 创建实体visaCountry
- 创建了名为 getVisaCountry 的 Intent 并在参数中调用了实体。
- 检查 $visaCountry 是否正确设置为文本响应中的参数。
- 将意图与实现联系起来
-
将 package.json 中的最新版本更新到
"@google-cloud/firestore": "^0.16.1", "actions-on-google": "^2.12.0", "firebase-admin": "^8.10.0", "firebase-functions": "^3.6.0", "dialogflow": "^0.6.0", "googleapis": "^27.0.0", "dialogflow-fulfillment": "^0.6.1", "request": "^2.85.0", "uuid": "^3.0.1" -
在 index.js 中添加管理员权限
var admin = require('firebase-admin'); var app = admin.initializeApp(); -
映射意图
intentMap.set('getVisaCountry', ffVisaCountry); 创建函数 ffVisaCountry
- 函数中调用参数visaCountry。
- 回复是
[object object]
B.我的代码
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
var admin = require('firebase-admin');
var app = admin.initializeApp();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function ffVisaCountry(agent) {
let visaCountry = agent.parameters.visaCountry;
agent.add(`FF reply: ${visaCountry}`);
}
'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('getVisaCountry', ffVisaCountry);
agent.handleRequest(intentMap);
});
C.我尝试遵循备用参数。
- 用 const 和 var 替换 let
- 将参数移出函数括号
- 将
agent.parameters.visaCountry;替换为agent.parameters['visaCountry']; - 尝试添加上下文
D.代理的预期和实际行为
预期行为:FF 回复:{用户输入的国家/地区名称}
实际行为:FF回复:[object Object]
【问题讨论】:
-
欢迎来到 StackOverflow!尽管您的问题非常详细,但如果您使用出现问题的 Intent 的 Dialogflow 配置屏幕截图更新问题也会有所帮助 - 在这种情况下为
getVisaCountryIntent。
标签: node.js dialogflow-es-fulfillment