Triggers & State Manager
Hi there! In this tutorial we are going to talk about Triggers and State Manager.
Suppose you are planning to build a workflow that checks for newly received emails. You'll first need to determine how the workflow will identify which messages are new.
This means the workflow should be able to persist the last received message, so that it can resume from that point during the next run.
This also applies to databases and many different applications.
Easyflow's state manager feature provides a powerful and flexible way to manage such use cases.
Let’s take a look at how you can do this in Gmail. As you can see, Gmail has a trigger operation called “Watch New Emails”. It’s identical to the search operation called “List of messages”. The only difference is with triggers we configured the State Manager for you.
In order to keep track of your most recent email, you'll need to enable the State Manager section in the "Watch new Emails" step. This will allow your step to persist the last received email ID based on the predefined JSON path in the key textbox.
Let’s run the workflow without enabling the state manager first. This will give us an idea about how the data will look like.
Let’s call the workflow for a second time, as we see the data hasn't changed and the same list of message ids are returning back.
Now, let’s enable the state manager and try again.
In the first workflow call after enabling the state manager, the data will return as it. Also, we can see that the last email id is persisted in the “Start Value” textbox.
Let’s call the workflow again, as a result, no new messages are appearing.
I will send an email to email@example.com and try to call the workflow again.
Cool, the workflow returns the new last received message only.
Now, let’s have a look at the “List of messages” operation. In its state manager the key is not predefined, so you can predefine a key to be persisted as your preferences.
Thank you for watching this tutorial.
Please feel free to contact us if you have any questions.
Updated on: 04/08/2022