首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用voximplant的DialogFlow和上下文

使用voximplant的DialogFlow和上下文
EN

Stack Overflow用户
提问于 2020-12-10 00:36:16
回答 2查看 169关注 0票数 0

我尝试使用这里描述的Voximplant集成在DialogFlow中设置上下文:https://cogint.ai/voximplant-dialogflow-connector-2019/#settingcontexts

代码语言:javascript
复制
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秒后,voicebot变得静默,但呼叫没有终止。我去掉了上下文部分,call和voicebot就可以正常工作了。

怎么啦?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-11 02:20:42

我推荐使用Voximplant的Modules.AI集成,而不是您在cogint.ai文章中使用的Modules.CCAIModules.CCAI是通过Dialogflow的一键式集成自动使用的,但除了我所看到的以外,它还没有得到很好的支持。

他们有该here的说明和演练视频here。不幸的是,它的应用编程接口与CCAI模块有很大的不同,但是你会找到更多的参考资料和例子(就像我在cogint.ai上看到的)。

Modules.AI仅适用于对话流ES。

票数 0
EN

Stack Overflow用户

发布于 2020-12-15 04:36:29

我最终重写了我的代码。我能够通过脚本将caller_id / caller_number参数传递给DialogFlow,而不是作为上下文。但是,我在我的欢迎意图中添加了这两个变量作为上下文。

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65220961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档