Fix: Hook ohne e.collection und JSON.stringify (PocketBase v0.38 kompatibel)

This commit is contained in:
rene 2026-05-17 19:14:32 +02:00
parent ffca3ad315
commit fb6f331041

View file

@ -1,37 +1,34 @@
onRecordAfterCreateSuccess(function(e) {
if (e.collection.name !== "inquiries") return;
if (!e.record) return;
var key = $os.getenv("BREVO_KEY");
if (!key) { console.error("BREVO_KEY nicht gesetzt"); return; }
if (!key) return;
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");
var name = e.record.getString("name").replace(/"/g, "'");
var company = e.record.getString("company").replace(/"/g, "'");
var email = e.record.getString("email").replace(/"/g, "'");
var phone = e.record.getString("phone").replace(/"/g, "'");
var message = e.record.getString("message").replace(/"/g, "'");
var plan = e.record.getString("plan").replace(/"/g, "'");
var subject = "checkflo: Neue Anfrage von " + name + (company ? " (" + company + ")" : "");
var subject = "checkflo: Anfrage von " + name + (company ? " (" + company + ")" : "");
var text = "Von: " + name + (company ? " / " + company : "") +
"\nEmail: " + email +
(phone ? "\nTel: " + phone : "") +
(plan ? "\nPlan: " + plan : "") +
(phone ? "\nTel: " + phone : "") +
(plan ? "\nPlan: " + plan : "") +
(message ? "\nNachricht: " + message : "");
var body = '{"sender":{"name":"checkflo","email":"hallo@checkflo.de"},' +
'"to":[{"email":"checkflo@motocamp.de"}],' +
'"subject":"' + subject + '",' +
'"textContent":"' + text.replace(/\n/g, "\\n") + '"}';
try {
$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
})
url: "https://api.brevo.com/v3/smtp/email",
method: "POST",
headers: { "api-key": key, "Content-Type": "application/json" },
body: body
});
} catch(err) {
console.error("Brevo error: " + String(err));