Fix: Hook ohne e.collection und JSON.stringify (PocketBase v0.38 kompatibel)
This commit is contained in:
parent
ffca3ad315
commit
fb6f331041
1 changed files with 20 additions and 23 deletions
|
|
@ -1,37 +1,34 @@
|
||||||
onRecordAfterCreateSuccess(function(e) {
|
onRecordAfterCreateSuccess(function(e) {
|
||||||
if (e.collection.name !== "inquiries") return;
|
if (!e.record) return;
|
||||||
|
|
||||||
var key = $os.getenv("BREVO_KEY");
|
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 name = e.record.getString("name").replace(/"/g, "'");
|
||||||
var company = e.record.getString("company");
|
var company = e.record.getString("company").replace(/"/g, "'");
|
||||||
var email = e.record.getString("email");
|
var email = e.record.getString("email").replace(/"/g, "'");
|
||||||
var phone = e.record.getString("phone");
|
var phone = e.record.getString("phone").replace(/"/g, "'");
|
||||||
var message = e.record.getString("message");
|
var message = e.record.getString("message").replace(/"/g, "'");
|
||||||
var plan = e.record.getString("plan");
|
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 : "") +
|
var text = "Von: " + name + (company ? " / " + company : "") +
|
||||||
"\nEmail: " + email +
|
"\nEmail: " + email +
|
||||||
(phone ? "\nTel: " + phone : "") +
|
(phone ? "\nTel: " + phone : "") +
|
||||||
(plan ? "\nPlan: " + plan : "") +
|
(plan ? "\nPlan: " + plan : "") +
|
||||||
(message ? "\nNachricht: " + message : "");
|
(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 {
|
try {
|
||||||
$http.send({
|
$http.send({
|
||||||
url: "https://api.brevo.com/v3/smtp/email",
|
url: "https://api.brevo.com/v3/smtp/email",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { "api-key": key, "Content-Type": "application/json" },
|
||||||
"api-key": key,
|
body: body
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
sender: { name: "checkflo", email: "hallo@checkflo.de" },
|
|
||||||
to: [{ email: "checkflo@motocamp.de" }],
|
|
||||||
subject: subject,
|
|
||||||
textContent: text
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error("Brevo error: " + String(err));
|
console.error("Brevo error: " + String(err));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue