【发布时间】:2019-05-16 16:11:40
【问题描述】:
我有一些问题。
我想用这个程序制作一个机器人。
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
我:你好
Bot : 欢迎来到我的代理!
机器人:你叫什么名字?
我:史密斯
机器人:史密斯
机器人:1
机器人:2
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
我将意图设置为“你好”,其参数为“名称”。
但是当它运行时,它会按照以下顺序运行。
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
我:你好
机器人:你叫什么名字?
我:史密斯
Bot : 欢迎来到我的代理!
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
这与我的意图完全不同。
您能推荐制作我的对象的正确方法吗?
非常感谢。
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
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 hello(agent) {
agent.add(`Welcome to my agent!`);
let city = request.body.queryResult.parameters['name'];
agent.add(`${city}`);
information().then((a) => {
agent.add(JSON.stringify(a));
});
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
let intentMap = new Map();
intentMap.set('hello', hello);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
function information(){
return new Promise(function (resolve, reject) {
var a = ['1','2'];
resolve(a);
});
}
【问题讨论】:
-
您能否更新您的问题以显示您已定义并且您认为应该在每个阶段触发的 Intent 的屏幕截图?例如,不清楚应该发送什么提示“你叫什么名字”,或者为什么你认为它会按照你指定的顺序发生。
-
我附上了关于 Intents 的照片,非常简单。我想知道订单,看看它是如何给出的。了解后,我将构建我的真实示例。但是当我用简单的例子这样练习时,它并没有按照我的意图工作。所以,也就是说,我想让 bot 说,当它访问 Intents 时,[1] Bot 说 'Agent.add(hello)' [2] Bot 询问我的名字作为参数。 [3] Bot 说我的名字作为参数。 [4] Bot 通过下面的函数说出数组的值。
标签: javascript node.js dialogflow-es