title: How to make a flow in directus with the following function
body: <p>I have a custom (coded) hook that works like:</p>
  <ul>
  <li>a collection is updated</li>
  <li>is it the collection &quot;events&quot;?</li>
  <li>is one of the updated fields one of these: time_show_start, time_show_end, ...</li>
  <li>get all contacts from a collection who want to recieve mails</li>
  <li>send a mail to these contacts with some info about the event (icluding old and new times)</li>
  </ul>
  <p>it should look something like this, but i just can't get it to work
  <a href="https://i.stack.imgur.com/N94i7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N94i7.png" alt="enter image description here" /></a></p>
  <pre><code>
  module.exports = function registerHook({ action }, { services, exceptions }) {
    const { MailService, ItemsService } = services;
    const { ServiceUnavailableException, ForbiddenException } = exceptions;
  
    // Send mail to admin when event time is updated
    action('items.update', async ({ keys, collection, payload }, { schema, accountability }) =&gt; {
      if (collection !== 'events') return;
      if (
        !payload.time_get_in &amp;&amp;
        !payload.time_setup_start &amp;&amp;
        !payload.time_setup_end &amp;&amp;
        !payload.time_soundcheck_start &amp;&amp;
        !payload.time_soundcheck_end &amp;&amp;
        !payload.time_dinner &amp;&amp;
        !payload.time_doors &amp;&amp;
        !payload.time_show_start &amp;&amp;
        !payload.time_show_end &amp;&amp;
        !payload.time_curfew_live_music &amp;&amp;
        !payload.time_curfew_guests
      ) {
        return;
      }
  
      const eventsService = new ItemsService('events', { accountability: accountability, schema: schema });
      const contactsService = new ItemsService('contacts', { accountability: accountability, schema: schema });
      const mailService = new MailService({ schema });
  
      const contacts = await contactsService.readByQuery({ filter: { getsmailon_eventtimechange: { _eq: true } } });
  
      contacts.forEach(async (contact) =&gt; {
        keys.forEach(async (el) =&gt; {
          // get event
          let event = null;
          try {
            event = await eventsService.readOne(el, { fields: ['*'] });
          } catch (error) {
            console.error(error);
            throw new ServiceUnavailableException(error);
          }
  
          // send mail
          try {
            await mailService.send({
              to: contact.email,
              subject: 'Zeit der Veranstaltung ' + event.name + ' geändert',
              text: 'Zeit der Veranstaltung &lt;b&gt;' + event.name + '&lt;/b&gt; geändert',
              template: {
                name: 'event-time-update',
                data: {
                  collection: collection,
                  event: event,
                  payload: payload,
                },
              },
            });
            console.log('mail sent for event', event.id);
          } catch (error) {
            console.error(error);
            throw new ServiceUnavailableException(error);
          }
        });
      });
  
      return;
    });
  };
  
  </code></pre>