๐Ÿ“ฆ directus / docs

๐Ÿ“„ 7.create-an-automation.md ยท 53 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53---
title: Create an Automation
description: Get started using flows, triggers, operations and the data chain in Directus Automate.
navigation:
  title: Create an Automation
---

:video-embed{video-id="6e6965e7-13cc-4f86-b512-f567d66cfbe9"}

This guide will cover custom event-driven data processing using Directus Automate.

## Before You Start

You will need a Directus project.

:cta-cloud

Create a `posts` collection with at least a `title` and `content` field. [Follow the Data Modeling quickstart to learn more](/getting-started/data-model).

## Create a Flow

![Create a new flow pane - including name, metadata, and option to track activity and logs.](/img/3c337848-a40f-4e62-9370-c943e8d5e761.webp)

Navigate to the Flows section in the Settings module. Click on :icon{name="material-symbols:add-circle"} in the page header and name the new flow "Post Created".

## Configure a Trigger

![Create a new flow pane - trigger setup where the trigger is an event hook.](/img/bf02c5e9-ebe2-4bf4-9fc5-3c00811a7a8a.webp)

Click on :icon{name="material-symbols:play-arrow"} to open trigger setup. Select "Event Hook" as the trigger type and select "Action (Non-Blocking)". This will allow you to set up this flow to respond to when an event takes place by running an action that doesn't interrupt.

Select `items.create` as the scope, and then check the "Posts" collection. This combination means that the operation will be triggered when an post is created. 

## Configure an Operation

![In the flow editor, the trigger connects to an operation. The operation configuration pane is open with a type of Send Notification.](/img/4c072da6-b396-47ad-85ff-f300e3eb9661.webp)

Click on :icon{name="material-symbols:add-circle"} on the trigger panel.

Here, you can create an operation. Give it the name "Notify Post Created" and the key "notify_post_created" will be written alongside.

Select the "Send Notification" operation type. Fill in the "User" field with the UUID of your user, which can be found in the user directory. Under "Permissions", select "From Trigger", which will cause the operation to have the same permissions as those that came from the trigger itself.

Fill in the "Subject" and "Message" fields as desired, leaving "Collection" and "Item" blank.

When finished, click on :icon{name="material-symbols:check-circle-rounded"} in the flow's top right corner.

Now, when you create a post, the user you entered will be notified.

## Next Steps

Read more about different [triggers](/guides/automate/triggers) available in flows and how data is passed through a flow with [the data chain](/guides/automate/data-chain).