我会在提示时让VUI重复其最后一句话(例如,当用户说'对不起,我没有听到你的声音)。我尝试使用库multivocal和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重复其语句,则“这是来自网络挂钩的响应”:
// 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);
});
正如@Prisoner指出的那样,您的代码仅适用于dialogflow-fulfillment
,但您基于Google行动示例。这就是代码错误的原因。
某些您想做的事情仅适用于Google的Actions,例如,对象conv
包含的功能仅在Google Assistant中执行时才起作用,这是问题的核心。
即使您修改了代码,以下的example you're仍将conv.data
用作对话期间座席最后一次回复的临时存储;但是conv.data
功能在Google Assistant平台之外不可用,目前,Dialogflow还没有一种直接的方法来获取代理的最后响应。
如果您不想与Google Assistant集成,那么您需要找到一种合适的解决方法来存储您的代理商的最新回复。 Here's a question讨论了有关临时存储的问题,也许您可以将其用作参考。
对于您的用例,我认为您可以通过使用上下文来存储最近的答复来摆脱它。