我正在尝试为包含确认的意图创建自定义后备。这是代码:
const functions = require('firebase-functions');
const {
dialogflow,
Confirmation
} = require('actions-on-google');
const app = dialogflow({
debug: true,
});
app.intent('vitals-confirmation', (conv, input, confirmation) => {
conv.ask(new Confirmation(`Great! Have you fainted recently?`));
});
app.intent('vitals-confirmation-fallback', (conv, input, confirmation) => {
conv.ask(new Confirmation(`Sorry I didn't understand what you said. Did you faint?`));
})
app.intent('S1-confirmation', (conv, input, confirmation) => {
if (confirmation) {
conv.ask(new Confirmation(`I have recorded that you have fainted. Have your feet been hurting?`));
} else {
conv.ask(new Confirmation(`I have recorded that you have not fainted. Have your feet been hurting?`));
}
});
我的应用程序询问用户是否对“ vitals-confirmation”感到晕倒,并且期望用户使用肯定或否定的答案进行回答,如果答案正确,他们将转到“ S1确认”,将被问到下一个问题。
但是,当我回答不是肯定/否定答案(例如:“红色”)的答案时,会输出以下内容:
Sorry, Great! Have you fainted recently?
似乎有一个默认的后备,其响应为“对不起,[重复以前的文本输出]”,并且没有转到我创建的自定义后备意图(这是我想要的结果)。
答案 0 :(得分:0)
看看{。{3}}的Actions SDK for Node.js。
您必须在DialogFlow中使用actions_intent_CONFIRMATION
事件设置一个意图,以便检索用户响应。我的建议是检查您如何配置意图并使用此方法,否则请确保创建具有所需上下文寿命的后续意图。
文档示例:
app.intent('Default Welcome Intent', conv => {
conv.ask(new Confirmation('Are you sure you want to do that?'))
})
// Create a Dialogflow intent with the `actions_intent_CONFIRMATION` event
app.intent('Get Confirmation', (conv, input, confirmation) => {
if (confirmation) {
conv.close(`Great! I'm glad you want to do it!`)
} else {
conv.close(`That's okay. Let's not do it now.`)
}
})