How to avoid duplicated executions before a sleep module?

I’m trying to create a scenario where I recieve multiple messages from Facebook Messenger module in a short period of time (15 seconds) and after creating a record for each message I join them with a text aggregator.

When I execute this scenario it works for the first run but I don’t understand why it runs again using the messages recieved after the first one as a new inputs. And this produces an error in the modules that use the final aggregated message as the value is empty.

Here is a detailed explanation of the workflow:

  1. Receive Message 1 (M1)
  2. Store M1 in Data Store module
  3. Sleep for 15 sec
  4. Before the 15 sec are completed I send a second test-message (M2)
  5. Stores M2 in Data Store module
  6. Keeps waiting for the Sleep module to finish the countdown.
  7. After the 15 seconds I search for the records in the Data Store
  8. I aggregate text from M1 and M2 into a new message (MSG)
  9. Delete Data Store records
  10. I use MSG to generate a response and send it back through Facebook Messenger.

This executes successfully and I get the response in Messenger.

However the scenario executes a second time using M2 as the only input

  1. Receives M2.
  2. Stores M2 in Data Store module
  3. Waits 15 seconds again
  4. Search records but this time the result is empty.
  5. As there are no records the text aggregator output is also empty
  6. The value for MSG is empty so none of the modules that use this value can run and the operation fails.

Producing this error:

Is there any way to avoid the second execution that uses only M2 as an input?

Hey Miguel,

your flow is completely wrong. If you need to wait a certain time before processing the messages then you will need one scenario to collect them and only when its done collecting, you start a second scenario to process them.

At the moment you have once scenario that is executing several times in parallel. So of course the second run will produce an error when the first run processed the data already. You either need to change your trigger to get all the messages together (time based execution for example, instead of the instant one) or split it in two separate scenarios - one to collect messages and one to process them and respond once the collection is done.

2 Likes

Thank you! I will try both options to see which one works better in my case.