javascript - DialogFlow 和带有 voximplant 的上下文
问题描述
我尝试使用此处描述的 Voximplant 集成在 DialogFlow 中设置上下文: https ://cogint.ai/voximplant-dialogflow-connector-2019/#settingcontexts
require(Modules.AI);
const languageCode = "en-US";
const agentId = 247;
let agent,
call,
conversation,
endUserParticipant,
isConversationCreated = false,
isCallCreated = false,
isCallConnected = false,
isParticipantCreated = false;
VoxEngine.addEventListener(AppEvents.Started,
function (ev) {
agent = new CCAI.Agent(agentId);
agent.addEventListener(CCAI.Events.Agent.Started, () => {
conversation = new CCAI.Conversation({ agent: agent });
conversation.addEventListener(CCAI.Events.Conversation.Created, () => {
isConversationCreated = true;
createParticipant();
});
});
});
VoxEngine.addEventListener(AppEvents.CallAlerting,
function (ev) {
isCallCreated = true;
createParticipant();
call = ev.call;
call.answer();
call.addEventListener(CallEvents.Connected,
function () {
isCallConnected = true;
//Script whith phone number to contexts must be added here somehow. Probably in setupMedia function.
setupMedia();
});
call.addEventListener(CallEvents.Disconnected,
function () {
conversation.stop();
VoxEngine.terminate();
});
});
function createParticipant() {
if (!isConversationCreated || !isCallCreated) return;
endUserParticipant = conversation.addParticipant({
call: call,
options: { role: "END_USER" },
dialogflowSettings: {
lang: languageCode,
singleUtterance: true,
replyAudioConfig: { audioEncoding: "OUTPUT_AUDIO_ENCODING_OGG_OPUS" },
},
});
endUserParticipant.addEventListener(CCAI.Events.Participant.Created, () => {
isParticipantCreated = true;
setupMedia();
});
}
function setupMedia() {
if (!isParticipantCreated || !isCallConnected) return;
endUserParticipant.analyzeContent({
eventInput: { name: "WELCOME", languageCode: languageCode },
});
endUserParticipant.addEventListener(
//Script whith phone number to contexts must be added here somehow.
phoneContext = {
name: "phone",
lifespanCount: 99,
parameters: {
caller_id: call.callerid(),
called_number: call.number()
}
},
//endUserParticipant.setQueryParameters({contexts: [phoneContext]})
//Script whith phone number to contexts must be added here somehow.
CCAI.Events.Participant.PlaybackFinished,
() => {
//Added by and call works, but hang up
VoxEngine.setQueryParameters({contexts: [phoneContext]});
//Added by and call works, but hang up
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
);
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
Voximplant 号码被转发到 Dialogflow,但 20 秒后语音机器人变为静音,但呼叫未终止。我删除了上下文部分,呼叫和语音机器人按预期工作。
怎么了?
解决方案
推荐阅读
- javascript - 将标头发送到客户端 nunjucks/express 后无法设置标头
- android - 如何在 Facebook 开发者工具包的帮助下在 android 的登录屏幕上进行会话?
- .htaccess - htaccess - 重定向条件不适用于本地主机
- java - java.io.IOException 疑难解答:服务器返回 HTTP 响应代码:503
- javascript - 获取触发AOS自定义事件的元素
- java - Android SQLite 错误:变量号必须介于 ?1 和 ?999 之间
- java - ftp 检索文件时是否需要临时文件?
- django - Django 无法使用 inspectdb 对遗留数据库进行建模
- javascript - 如何将实时图像 url 转换为角度的 blob?
- r - 在 r 中将嵌套列表的相同数据帧相加