I have a question that I feel is probably really simple to do, but I can’t figure it out.
My process is: I have a Hubspot form submission for a “Call me back” form, that enters a phone number into a Scenario using a Webhook. I then make an API call to Aircall to get the availability of agents. This returns a JSON with agent IDs and a value for availability: available, unavailable or offline.
Now I want to randomly pick one of the available agents, so that I can put their ID into another API call to Aircall to start an outbound call.
I’m at the point where I have:
- An Iterator to turn the JSON into separate agent bundles
- A filter that runs right after the iterator to only pass agents that have availability = Available.
…but now I need to randomize the selection of the agent somehow. And I’m lost
I’ve tried putting them in a data store first, along with an incremented for a key, then using a Set Variable to generate a random number between 1 and after the last iteration, to decide which record to retrieve from the database. But I reached a dead end there because I couldn’t find a way to stop the iteration without also losing access to the . That’s probably way too convoluted…
This is what I had:
Any ideas? I feel like this should be relatively easy but I can’t figure it out.
The most effective method to select a random bundle involves the following steps:
- Transform your bundles into an array utilizing the array aggregator.
- In the immediate subsequent module, employ the array iterator with the 'map' option enabled. This will iterate through the aggregated array, but crucially, use the
shuffle()
function to randomize the array's contents. - The iterator will then generate bundles from your array in a randomized sequence. You can subsequently configure a filter to, for instance, select bundles based on their position number (e.g., the first x bundles, or simply the first one).
In this scenario, the array aggregator is linked to a Search module that has just fetched a collection of bundles from an application. The array aggregator then converts all these retrieved bundles into a single array, where each original bundle is represented as a collection within this new array.
The iterator then proceeds to reorder the results randomly using the shuffle functionality, thereby regenerating the bundles for subsequent processing.