Understand Directus Flows, We'll explain how it enables custom event-driven task automation within Directus through triggers, operations, and data chains.
Speaker 0: Directus Automate provides flows, which enable custom event driven task automation within Directus. Each flow is composed of 1 trigger followed by a series of operations and finally returning data. Each flow starts with 1 trigger. The first is event driven based on data changes in your project. You can create a filter trigger which intercepts a database transaction before it happens, allowing you to validate or manipulate the data and optionally rejecting the transaction.
Or action filters trigger once the change has happened in your database. This includes create, update, and deleting of items. This is great for data enrichment or follow-up logic that doesn't need to delay the database transaction from happening. The schedule trigger will run regularly on a specified interval. It uses the 6 point cron job syntax, so you can get as granular as second or as wide as weeks.
The webhook trigger creates a unique URL for your flow and will be run whenever that URL is requested. Any data sent with the request will be available in the trigger object. The manual flow trigger adds a button to configured collections in Directus Explore and Directus Editor that can be clicked by users in the data studio. Optionally, a confirmation prompt can be shown with a form to collect data. And finally, you can chain flows together and configure them to be triggered by a parent flow.
Data can be passed into them from the parent and once the flow has concluded it can be returned back up. Each time a flow is run it has its own data chain which is a JSON object passed from the trigger and to each operation, which will append information to the data chain. Now there are some dynamic properties available in every data chain. Trigger contains all of the data generated by the flows trigger. Accountability contains data about who or what started the flow.
Env contains all of the environment variables that have been allowed to be shown and used inside of flows. And last contains return data from the previous operation whenever used. That means in every operation, the value of last will change to always be the output of the previous step. Each step which we call operations will receive all data in the data chain, perform some logic and return data back into the data chain. Each operation has a success and failure path which we call resolve and reject.
So be sure to account for failed operations, especially when they rely on specific permissions or external services. A couple of very common operations include the webhook request url operation that allows your flow to make an external web request. You can select a method, url, and set custom headers as well as providing a payload. The create, read, update and delete data operations perform actions on items from a collection and adds the result to the data chain. You may select items by their ID or by running a query using directives' filter syntax.
The run script operation lets you add custom JavaScript snippets. The script will be executed securely in an isolated sandbox, which means it only has access to standard built in objects and has no access outside of the sandbox except for sharing input and output values. This means, for example, no access to the file system, no ability to do network requests, and no support for third party packages. You can do each of these by using other operations that are provided as part of directors or by building custom operation extensions that use packages. Accessible from the sidebar, logs store information for each flow execution.
Each log will display information from triggers as well as each operation in the flow. Keep in mind that if you've configured a flow to track logs, all of this will be stored in your database. So you may periodically need to delete this data if your flows get a lot of use. Directus automate is super powerful and I hope this explains the basics of how to utilize them. You can download custom operations from the directors marketplace and follow the tutorials in our documentation to set up specific flows.