0

I've tried to implement a delay feature on my bot to display multiple messages one after the other. The delay feature is displaying in my Flow Bot Builder diagram, but when I test in the conversation tester, and proxy bot on Messenger, the delay doesn't actually happen - all the messages display at once.

I have added the delay code in the IDE to the default.scr file:

[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"}]}

I've also added the options.apikey line of code to the index.js file as instructed to do here: https://www.gupshup.io/developer/docs/bot-platform/guide/sending-multiple-messages-botscript

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";
}

Is there any obvious reason why the delay effect wouldn't be working in between messages? I've used the apikey that is displayed for my gupshup account when I click the logo in the top right.

1 Answers1

1

You have placed the API key after the scripting tool execute function is called. Place the API Key anywhere before the botScriptExecutor.execute and the delay should work.

Also, the timing of the delay is in milliseconds.

Sample:

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);

}

Shreyans
  • 1,738
  • 1
  • 13
  • 19