Simple Pause Function

175 views
Skip to first unread message

Craig Pearce

unread,
Jun 6, 2018, 1:09:26 PM6/6/18
to Twilio Functions
Hi all

I'm a new Studio user and looking for a simple pause function.  My studio layout has a series of text messages sent to the user.  I'd like to input a short pause (2-4 seconds) between each message which will allow them to read each message before the next arrives.  I guess one option would be to send one long message, but I find sometime they get out of order.

Here is what I tried, however I do not know node.js, so I basically just pulled this from stackoverflow and it wasn't a relevant answer to twilio studio.

function timer() {
    console.log('timer has started')
}

setTimeout(timer, 4000);

I put the function between two messages but it didn't seem to pause at all.

Thanks for any help!

Alan

unread,
Jun 17, 2018, 8:29:57 PM6/17/18
to Twilio Functions
Hi Craig,

How about the below, calling it with the Studio Run Function Widget and passing the Function Parameter key pause with a value in milliseconds (it defaults to 4 seconds if no value is passed).

exports.handler = function(context, event, callback) {

    pauseInterval = parseInt(event.pause) || 4000;
    
    console.log(pauseInterval);
    
setTimeout(() => {
    callback(null, `${pauseInterval}ms pause complete`)}, pauseInterval);
};
Reply all
Reply to author
Forward
0 new messages