Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

794
Visualizações
Webhooks Directus 9 - send an email when user create a record in a table

I created the "mission" collection. I want to send an email to a personalized recipient for each new recording on the mission table.

enter image description here

According to the Directus documentation, I saw that this is possible via webHooks.

enter link description here

However, I don't quite understand the logic. Especially since in the Directus administration interface, there is a page to add webhooks and link them to the collection concerned.

enter image description here

Can you tell me where I should start to achieve my POC.

I also put some screenshots on the architecture of my app, you can tell me if this is really how it should be or not. I have doubts.

enter image description here

enter image description here

enter image description here

{
  "name": "test1-directus",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "directus start"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "directus": "^9.0.0-rc.91",
    "mysql": "^2.18.1",
    "nodemailer": "^6.6.3"
  }
}

I created a project with the command: npx create-directus-project test1directus My project is running on port 8055 with a reverse proxy setting on nginx.

Is everything OK or did I miss a step?

Thank you in advance for your help.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found this example to put in: extensions / hooks / sync-with-external / index.js

After several modifications, this error persists on my writing:

An error was thrown while executing hook "items.create" Cannot destructure property 'mission' of 'undefined' as it is undefined.

The console.log doesn't show me anything.

const axios = require("axios");

module.exports = function registerHook({ services, exceptions }) {
  const { MailService } = services;
  const { ServiceUnavailableException, ForbiddenException } = exceptions;

  return {
    // Force everything to be admin-only at all times
    "items.*": async function ({ item, accountability }) {
      if (accountability.admin !== true) throw new ForbiddenException();
    },
    // Sync with external recipes service, cancel creation on failure
    "items.create": async function (input, { mission, schema }) {
      console.log(items);
      if (mission !== "recipes") return input;

      const mailService = new MailService({ schema });

      try {
        await axios.post("https://example.com/items", input);
        await mailService.send({
          to: "pseudo.pseudo@gmail.com",
          template: {
            name: "item-created",
            data: {
              collection: mission,
            },
          },
        });
      } catch (error) {
        throw new ServiceUnavailableException(error);
      }

      input[0].syncedWithExample = true;

      return input;
    },
  };
};

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda