DialogFlow 和上下文与 voximplant
DialogFlow and contexts with 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 秒后语音机器人变得无声,但通话并未终止。我删除了上下文部分,呼叫和语音机器人按预期工作。
怎么了?
我建议使用 Voximplant 的 Modules.AI
集成,而不是我在您提到的 cogint.ai 文章中使用的 Modules.CCAI
。 Modules.CCAI
通过 Dialogflow 的一键式集成自动使用,但据我所知,除此之外它没有得到很好的支持。
他们有这方面的说明 here and a walkthrough video here。不幸的是,API 与您在 CCAI 模块中所拥有的非常不同,但是您会找到更多关于它的参考和示例(就像我在 cogint.ai 上所拥有的)。
Modules.AI
仅适用于 Dialogflow ES。
我最终重写了我的代码。我能够将 caller_id / caller_number 参数传递给 DialogFlow,而不是通过脚本作为上下文。但是,我在欢迎意图中将这两个变量添加为上下文。
function setupMedia() {
if (!isParticipantCreated || !isCallConnected) return;
endUserParticipant.analyzeContent({
eventInput: {
name: "WELCOME",
languageCode: languageCode,
parameters: {
//phone: call.callerid(),
caller_id: call.callerid(),
called_number: call.number()}
},
});
endUserParticipant.addEventListener(
CCAI.Events.Participant.PlaybackFinished,
() => {
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
);
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
我尝试使用此处描述的 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 秒后语音机器人变得无声,但通话并未终止。我删除了上下文部分,呼叫和语音机器人按预期工作。
怎么了?
我建议使用 Voximplant 的 Modules.AI
集成,而不是我在您提到的 cogint.ai 文章中使用的 Modules.CCAI
。 Modules.CCAI
通过 Dialogflow 的一键式集成自动使用,但据我所知,除此之外它没有得到很好的支持。
他们有这方面的说明 here and a walkthrough video here。不幸的是,API 与您在 CCAI 模块中所拥有的非常不同,但是您会找到更多关于它的参考和示例(就像我在 cogint.ai 上所拥有的)。
Modules.AI
仅适用于 Dialogflow ES。
我最终重写了我的代码。我能够将 caller_id / caller_number 参数传递给 DialogFlow,而不是通过脚本作为上下文。但是,我在欢迎意图中将这两个变量添加为上下文。
function setupMedia() {
if (!isParticipantCreated || !isCallConnected) return;
endUserParticipant.analyzeContent({
eventInput: {
name: "WELCOME",
languageCode: languageCode,
parameters: {
//phone: call.callerid(),
caller_id: call.callerid(),
called_number: call.number()}
},
});
endUserParticipant.addEventListener(
CCAI.Events.Participant.PlaybackFinished,
() => {
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
);
VoxEngine.sendMediaBetween(call, endUserParticipant);
}