Feature: PocketBase Hook für Inquiry-Benachrichtigung per Mail (checkflo@motocamp.de)

This commit is contained in:
rene 2026-05-17 18:16:21 +02:00
parent fcb95449f5
commit e5aeadd01c
2 changed files with 67 additions and 0 deletions

View file

@ -18,6 +18,10 @@ TAR_EXCLUDE := --exclude='.git' \
--exclude='./.env' \ --exclude='./.env' \
--exclude='./.DS_Store' --exclude='./.DS_Store'
# Hook-Sync: pb_hooks nach jedem Deploy auf DS kopieren
HOOKS_SRC := pocketbase/pb_hooks
HOOKS_DST := /volume1/docker/checkflo/pocketbase/data/pb_hooks
.PHONY: help check-ssh start stop restart status logs logs-f logs-app \ .PHONY: help check-ssh start stop restart status logs logs-f logs-app \
shell-pb pb-admin deploy setup-db seed-demo shell-pb pb-admin deploy setup-db seed-demo
@ -58,6 +62,10 @@ check-ssh:
deploy: check-ssh deploy: check-ssh
@echo "→ Sync zu DS..." @echo "→ Sync zu DS..."
@COPYFILE_DISABLE=1 tar czf - $(TAR_EXCLUDE) . | ssh $(DS_HOST) "tar xzf - -C $(DS_PATH)/" @COPYFILE_DISABLE=1 tar czf - $(TAR_EXCLUDE) . | ssh $(DS_HOST) "tar xzf - -C $(DS_PATH)/"
@echo "→ PocketBase Hooks synchronisieren..."
@for f in $(HOOKS_SRC)/*.pb.js; do \
cat "$$f" | ssh $(DS_HOST) "cat > $(HOOKS_DST)/$$(basename $$f)"; \
done
@echo "→ Docker rebuild + restart..." @echo "→ Docker rebuild + restart..."
@ssh $(DS_HOST) " \ @ssh $(DS_HOST) " \
cd $(DS_PATH) && \ cd $(DS_PATH) && \

View file

@ -0,0 +1,59 @@
/// <reference path="../pb_data/types.d.ts" />
// Sendet eine Benachrichtigungs-Mail bei neuer Demo-Anfrage
onRecordCreate((e) => {
e.next();
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");
const subject = `checkflo: Neue Anfrage von ${name}${company ? " (" + company + ")" : ""}`;
const html = `
<!DOCTYPE html>
<html lang="de">
<head><meta charset="utf-8"></head>
<body style="font-family:sans-serif;background:#f5f7fa;margin:0;padding:0">
<div style="max-width:560px;margin:32px auto;background:#fff;border-radius:12px;padding:32px;box-shadow:0 2px 8px rgba(0,0,0,.08)">
<div style="margin-bottom:24px">
<span style="background:#0B1023;color:#F97316;padding:6px 14px;border-radius:20px;font-size:12px;font-weight:700;letter-spacing:1px">NEUE DEMO-ANFRAGE</span>
</div>
<h2 style="color:#0B1023;margin:0 0 4px">${name}</h2>
${company ? `<p style="color:#888;margin:0 0 20px;font-size:14px">${company}</p>` : `<div style="margin-bottom:20px"></div>`}
<table style="width:100%;border-collapse:collapse;font-size:14px">
<tr><td style="padding:8px 0;color:#888;width:100px">E-Mail</td><td style="padding:8px 0;color:#0B1023"><a href="mailto:${email}" style="color:#F97316">${email}</a></td></tr>
${phone ? `<tr><td style="padding:8px 0;color:#888">Telefon</td><td style="padding:8px 0;color:#0B1023">${phone}</td></tr>` : ""}
${plan ? `<tr><td style="padding:8px 0;color:#888">Plan</td><td style="padding:8px 0;color:#0B1023;font-weight:600">${plan}</td></tr>` : ""}
${message ? `<tr><td style="padding:8px 0;color:#888;vertical-align:top">Nachricht</td><td style="padding:8px 0;color:#0B1023">${message}</td></tr>` : ""}
</table>
<div style="margin-top:28px;padding-top:20px;border-top:1px solid #eee">
<a href="https://api.checkflo.de/_/#/collections/inquiries"
style="background:#F97316;color:#fff;padding:12px 24px;border-radius:8px;text-decoration:none;font-weight:700;font-size:14px">
Alle Anfragen in PocketBase
</a>
</div>
</div>
</body>
</html>`;
try {
const message = new MailerMessage({
from: { address: "hallo@checkflo.de", name: "checkflo" },
to: [{ address: "checkflo@motocamp.de" }],
subject: subject,
html: html,
});
$app.newMailClient().send(message);
} catch (err) {
console.error("Inquiry-Mail Fehler:", err);
}
});