ratty-blush
ratty-blush2y ago

Can I use setTimeout() in a Javascript Step?

Hi, I would like to set a delay between the steps I design on Voiceflow Canvas and was curious if using setTimeout() is supported in the Javascript step. If not are there plans to add a delay step as my use case would be to place it between 2 API steps that are rate limited.
6 Replies
Tico | Voiceflow Assistant
In Voiceflow, the JavaScript methods such as setTimeout() are not supported out-of-the-box due to their dependence on browser or Node.js runtime APIs and not part of the ECMAScript (JavaScript) language specification itself. This means you cannot use setTimeout() in a JavaScript step to set a delay between steps on the Voiceflow Canvas. As an alternative, you might consider handling the rate limit on the server-side where the API is hosted, or using a middleware to add delay between API calls. However, please note that these solutions would require additional coding and infrastructure outside of Voiceflow. As of now, there's no built-in delay step in Voiceflow. However, Voiceflow is always working on improving and adding new features based on user feedback. You can keep an eye on the Voiceflow Changelog and Voiceflow's Discord community for updates and new feature announcements.
NiKo | Voiceflow
You can use a Capture step with a no-reply set to x second between your two API steps. But best practice is to use a Function do handle that.
ratty-blush
ratty-blushOP2y ago
hmmm setTimeout isn't supported so how would I accomplish that in a function step? I see it working with the capture step with no reply set but it seems a bit hacky to do it that way as the option is hidden underneath the capture step UI
ratty-blush
ratty-blushOP2y ago
No description
NiKo | Voiceflow
You can use this in Functions
function wait(ms) {
return new Promise((resolve) => {
const startTime = Date.now()
let currentTime = Date.now()
while (currentTime - startTime < ms) currentTime = Date.now()
resolve()
});
}
function wait(ms) {
return new Promise((resolve) => {
const startTime = Date.now()
let currentTime = Date.now()
while (currentTime - startTime < ms) currentTime = Date.now()
resolve()
});
}
ratty-blush
ratty-blushOP2y ago
oh neat, thanks for sharing!

Did you find this page helpful?