首页 > 解决方案 > 如何在对话流中的一段时间后调用事件

问题描述

我正在尝试使用对话流构建一个聊天机器人,我试图在一段时间后调用一个事件,如下面的代码所示:

function createLink(agent) {
    setTimeout(cnf, 3000);
    agent.add(`Please complete payment by clicking (https://www.aa.bb)`);
}

function cnf(agent) { 
   console.log('In cnf');
   agent.setFollowupEvent('cnf_event');
}

日志显示 cnf 函数已执行,但 dialogflow 从未执行 cnf_event

这里发生了什么,我该怎么做

任何帮助,在此先感谢!

标签: dialogflow-esdialogflow-es-fulfillment

解决方案


您需要agent在 set-timeout 函数内传递,

function createLink(agent) {
    setTimeout((agent) => {
        cnf(agent)
    }, 3000);
   console.log(`Please complete payment by clicking (https://www.aa.bb)`);
}

function cnf(agent) { 
   console.log('In cnf');
   agent.setFollowupEvent('cnf_event');
}

推荐阅读