1

In twilio studio I have 2 messages that goes one after the other.

I need a 5 or 10 seconds wait time between these messages.

How can I do it in twilio studio? or How can I write a function that waits 10 seconds, runs after that and I send the other message.

I tried to use

setTimeout(function(){
   response ="This is response";

},5000);

But this did not worked at Twilio, I also tried wait(5000); but it gave error that wait is not defined.

Thanks.

Raviteja
  • 3,399
  • 23
  • 42
  • 69
  • 1
    Maybe my answer can help you (https://stackoverflow.com/questions/50977722/how-can-i-add-pause-to-twilio-studio-say-play-widget/51031632#51031632) – Alex Baban Sep 20 '18 at 06:04

1 Answers1

2

Twilio developer evangelist here.

You could use a Twilio Function to delay the message here, but Twilio Functions do time out after 5 seconds. (If you really need 10 seconds, you could queue this function up to run twice.)

Here's a Function that will wait 5 seconds and then return:

exports.handler = function(context, event, callback) {
  setTimeout(function() {
    callback(null, {});
  }, 5000)
}

The key is that you trigger the callback function within the callback to setTimeout.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • 1
    Thanks @philnash, we are hitting our sms rate limits very quickly. We are conducting surveys (question/answer x 15) and implementing a small delay has helped us avoid that error. – markokstate Sep 28 '20 at 19:51