URGENT - Set some pause in a Custom action

I’m trying to pause for 5 sec in a custom action code.
I tried several option ( basic one with node.js is “sleep” ), but it is not working
any trick on how to pause ?


note :
var sleep = require(‘sleep’);* *

Hey @smalldragoon !

You can find solutions on how to implement sleep in Javascript here https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep

Hope this helps!

Thanks a lot, will work on it

Still on, for some reasons, I can no get the loop working into botpress while it works outside …

HI, I think I found the issue :
ActionService An error occurred while executing the action "builtin/waitmobileApprove [Error, Module “sleep” not found. Tried these locations: “/opt/botpress/modules/.cache/module__07792467c39bdcc4e171ca5371dcb1af9595dbe683b88f49191034eb35356614, /opt/botpress/data/global/actions/builtin”]

but my “sleep” looks to be correctly installed … ( checked with npm install and npm audit fix )
I will repost another message as the title do not match anymore

Hi smalldragon

Check out below guide on how to add delay in your conversation.


Hi abhisheksimion
Thanks a lot but it is not really what I need .
in short, I need to perform API call(s), with a delay between each, until a proper value is responded by the API answer :frowning:
from my understanding, it is only possible via custom actions ?

@smalldragoon If I understand correctly you want to add delay or sleep in between your API calls. Check if below snippet works for you, use it in your custom action.

const sleep = ms => {
  return new Promise(resolve => setTimeout(resolve, ms));

const myAction = () => {
  await sleep(5000);
  console.log("API Call 1")
  await sleep(5000);
  console.log("API Call 2")
  await sleep(5000);
  console.log("API Call 3")

return myAction()

@abhisheksimion, Thanks a lot for your support :smiley:
trying your snipet I get this :

ActionService An error occurred while executing the action "builtin/bck_wait [SyntaxError, await is only valid in async function]

I tried in the past the await and got the same error.
my need is the following : I want to poll ( let say 15 times ) via an API some values. I need to “return” either is the API response value is ok OR if I reached the 15 times

Thx again !