diff --git a/docker-compose.yml b/docker-compose.yml index ec07e7b..c8e04f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: - /volume1/docker/checkflo/pocketbase/data/pb_hooks:/pb_hooks environment: - TZ=Europe/Berlin + - BREVO_KEY=${BREVO_KEY} networks: - default - npm_bridge diff --git a/pocketbase/pb_hooks/inquiries.pb.js b/pocketbase/pb_hooks/inquiries.pb.js index 0e2b254..f296c94 100644 --- a/pocketbase/pb_hooks/inquiries.pb.js +++ b/pocketbase/pb_hooks/inquiries.pb.js @@ -1,59 +1,39 @@ -/// - -// Sendet eine Benachrichtigungs-Mail bei neuer Demo-Anfrage -onRecordCreate((e) => { - e.next(); - +onRecordAfterCreateSuccess(function(e) { if (e.collection.name !== "inquiries") return; - const r = e.record; - const name = r.getString("name"); - const company = r.getString("company"); - const email = r.getString("email"); - const phone = r.getString("phone"); - const message = r.getString("message"); - const plan = r.getString("plan"); + var key = $os.getenv("BREVO_KEY"); + if (!key) { console.error("BREVO_KEY nicht gesetzt"); return; } - const subject = `checkflo: Neue Anfrage von ${name}${company ? " (" + company + ")" : ""}`; + var name = e.record.getString("name"); + var company = e.record.getString("company"); + var email = e.record.getString("email"); + var phone = e.record.getString("phone"); + var message = e.record.getString("message"); + var plan = e.record.getString("plan"); - const html = ` - - - - -
-
- NEUE DEMO-ANFRAGE -
-

${name}

- ${company ? `

${company}

` : `
`} - - - - ${phone ? `` : ""} - ${plan ? `` : ""} - ${message ? `` : ""} -
E-Mail${email}
Telefon${phone}
Plan${plan}
Nachricht${message}
- -
- - Alle Anfragen in PocketBase → - -
-
- -`; + var subject = "checkflo: Neue Anfrage von " + name + (company ? " (" + company + ")" : ""); + var text = "Von: " + name + (company ? " / " + company : "") + + "\nEmail: " + email + + (phone ? "\nTel: " + phone : "") + + (plan ? "\nPlan: " + plan : "") + + (message ? "\nNachricht: " + message : ""); try { - const message = new MailerMessage({ - from: { address: "hallo@checkflo.de", name: "checkflo" }, - to: [{ address: "checkflo@motocamp.de" }], - subject: subject, - html: html, + $http.send({ + url: "https://api.brevo.com/v3/smtp/email", + method: "POST", + headers: { + "api-key": key, + "Content-Type": "application/json" + }, + body: JSON.stringify({ + sender: { name: "checkflo", email: "hallo@checkflo.de" }, + to: [{ email: "checkflo@motocamp.de" }], + subject: subject, + textContent: text + }) }); - $app.newMailClient().send(message); - } catch (err) { - console.error("Inquiry-Mail Fehler:", err); + } catch(err) { + console.error("Brevo error: " + String(err)); } -}); +}, "inquiries");