首页 > 解决方案 > 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 秒后语音机器人变为静音,但呼叫未终止。我删除了上下文部分,呼叫和语音机器人按预期工作。

怎么了?

标签: javascriptdialogflow-es

解决方案


我建议使用 Voximplant 的Modules.AI集成,而不是Modules.CCAI我在您提到的 cogint.ai 文章中使用的那样。Modules.CCAI通过 Dialogflow 的一键式集成自动使用,但据我所见,它并没有得到很好的支持。

他们在此处提供了相关说明,并此处提供了演练视频。不幸的是,API 与 CCAI 模块中的 API 非常不同,但您会发现更多的参考和示例(就像我在 cogint.ai 上的一样)。

Modules.AI仅适用于 Dialogflow ES。


推荐阅读