我试图让我的VUI在提示时重复它的最后一句(例如,当用户说‘对不起,我没听到)。我尝试使用多音库和VoiceRepeater来实现它,但这不适合我,所以我想按照这个指南实现它:https://developers.google.com/assistant/conversational/tips。
我已经采取了以下步骤:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function repeat(agent) {
const REPEAT_PREFIX = [
'Sorry, Ik zei ',
'Laat me het herhalen: ',
'Wat ik zei is'
];
const reply = (agent, inputPrompt, noInputPrompts) => {
agent.data.lastPrompt = inputPrompt;
agent.data.lastNoInputPrompts = noInputPrompts;
agent.ask(inputPrompt, noInputPrompts);
};
// Intent handlers
const normalIntent = (agent) => {
reply(agent, 'Hey this is a question', 'Ik zie niks');
};
let repeatPrefix = promptFetch.getRepeatPrefix(); // randomly chooses from REPEAT_PREFIX
// Move SSML start tags over
if (agent.data.lastPrompt.startsWith(promptFetch.getSSMLPrefix())) {
agent.data.lastPrompt =
agent.data.lastPrompt.slice(promptFetch.getSSMLPrefix().length);
repeatPrefix = promptFetch.getSSMLPrefix() + repeatPrefix;
}
agent.add(repeatPrefix + agent.data.lastPrompt,
agent.data.lastNoInputPrompts);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Repeat', repeat);
agent.handleRequest(intentMap);
});不幸的是,这对我不起作用,我发现一个错误就是它说'FetchPrompt没有定义‘,这我不明白。我知道设置是可以的,因为这段代码确实会返回:如果我提示VUI重复它的句子,“这是来自web钩子的响应”:
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function repeat(agent) {
agent.add('this is a response from the webhook');
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Repeat', repeat);
agent.handleRequest(intentMap);
});发布于 2020-02-09 19:15:24
正如@Prisoner所指出的那样,您的代码只打算与dialogflow-fulfillment一起工作,但是您基于谷歌上的一个操作示例。这就是代码错误的原因。
您想要做的一些事情仅适用于谷歌上的操作,例如,对象conv包含仅在Google中执行时才能工作的功能,这是问题的核心。
即使您修复了代码,下面的例如你是也使用conv.data作为会话期间代理的最后一个答复的临时存储;但是conv.data功能在Google平台之外是不可用的,而且目前对话框流没有一种直接的方法来获取代理的最后响应。
如果你不想与谷歌助理集成,那么你需要找到一个合适的方法来存储你的代理最后的回复。在这里有个问题中讨论了临时存储的这个问题,也许您可以将其用作参考。
对于您的用例,我认为您可以通过使用上下文来存储最后的回复来摆脱它。
https://stackoverflow.com/questions/60114298
复制相似问题