0

我试图在我的机器人上实现一个延迟功能,以一个接一个地显示多条消息。延迟功能显示在我的 Flow Bot Builder 图表中,但是当我在对话测试器和 Messenger 上的代理机器人中进行测试时,延迟实际上并没有发生 - 所有消息同时显示。

我已将 IDE 中的延迟代码添加到 default.scr 文件中:

[main]
   label_dych:Hi! I'm delay-bot and I'm here to help you with any questions you have.:continue
     ((delay 2000))
       label_gthk:I'll never need to take any personal or financial information from you, so as we chat please don't tell me any!:continue
         ((delay 1000))
           label_ylbn:{"name":"quickreply","type":"quick_reply","alias":"What can I help you with?","msgid":"117af569-5188-ff7e-9b48-8c553c2f36cb","content":{"type":"text","text":"What can I help you with?"},"options":[{"type":"text","title":"My Page","iconurl":"","id":"ac49ad32-c9bc-469f-2152-c7c842bad8ea","isDuplicate":false,"name":"user"},{"type":"text","title":"Team Spaces","iconurl":"","id":"8a2017ac-2fc3-0901-be8d-1fad5a2dba12","isDuplicate":false,"name":"user"},{"type":"text","title":"Offline Support","iconurl":"","id":"70861407-e706-17a3-207b-c43958fde83e","isDuplicate":false,"name":"user"},{"type":"text","title":"Something else","iconurl":"","id":"d3f7b6b4-e70a-098d-dde9-1da3e8cc08dc","isDuplicate":false,"name":"user"}]}

我还按照此处的说明将 options.apikey 代码行添加到 index.js 文件中:https ://www.gupshup.io/developer/docs/bot-platform/guide/sending-multiple-messages-脚本

function ScriptHandler(context, event){
    var options = Object.assign({}, scr_config);
    options.current_dir = __dirname;
    //options.default_message = "Sorry Some Error Occurred.";
    // You can add any start point by just mentioning the 
<script_file_name>.<section_name>
    // options.start_section = "default.main";
    options.success = function(opm){
        context.sendResponse(JSON.stringify(opm));
    };
    options.error = function(err) {
        console.log(err.stack);
        context.sendResponse(options.default_message);
    };
    botScriptExecutor.execute(options, event, context);
    options.apikey = "1mbccef47ab24dacad3f99557cb35643";
}

延迟效果在消息之间不起作用有什么明显的原因吗?当我单击右上角的徽标时,我使用了为我的 gupshup 帐户显示的 apikey。

4

1 回答 1

1

在调用脚本工具执行函数后,您已放置 API 密钥。将 API 密钥放在 之前的任何位置,botScriptExecutor.execute延迟应该可以工作。

此外,延迟的时间以毫秒为单位。

样本:

function ScriptHandler(context, event){
var options = Object.assign({}, scr_config);
options.current_dir = __dirname;
//options.default_message = "Sorry Some Error Occurred.";
options.apikey = "1mbccef47ab24dacad3f99557cb35643";
// You can add any start point by just mentioning the 
<script_file_name>.<section_name>
// options.start_section = "default.main";
options.success = function(opm){
    context.sendResponse(JSON.stringify(opm));
};
options.error = function(err) {
    console.log(err.stack);
    context.sendResponse(options.default_message);
};
botScriptExecutor.execute(options, event, context);

}

于 2017-10-20T06:12:14.203 回答