inbound/muster (WordPress): Vorname/Nachname & Ort korrekt mappen

Der WP-Webhook schickt vorname + name(=Nachname) getrennt und die Stadt als „ort".
Bisher wurde nur body.name als kompletter Name genommen (nur Nachname), city aus
body.city gelesen (leer) und kein first_name/last_name gespeichert – daher stand
beim Übernehmen der Nachname im Vornamen und Ort blieb leer.

- Anzeigename = vorname + name; address bekommt first_name/last_name.
- Stadt aus „ort" (Aliase stadt/city), plus robuste Feld-Aliase via feldWert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
s4luorth
2026-09-11 21:52:09 +02:00
parent ba9c073bb9
commit 3ebe05c954

View File

@@ -1607,8 +1607,11 @@ const handler = (router, { services, getSchema, logger }) => {
}
if (!['muster', 'anfrage'].includes(kind)) return res.status(404).json({ error: 'Unbekannter Hook (muster|anfrage).' });
const name = String(body.name || '').trim();
const email = norm(body.email);
// WP schickt Vor-/Nachname GETRENNT: vorname + name(=Nachname). Anzeigename = beides.
const vorname = feldWert(body, 'vorname', 'first_name', 'firstname');
const nachname = feldWert(body, 'name', 'nachname', 'last_name', 'lastname');
const name = [vorname, nachname].filter(Boolean).join(' ');
const email = norm(feldWert(body, 'email', 'e_mail', 'e-mail', 'mail'));
if (!name) return res.status(400).json({ error: 'Name fehlt.', felder: Object.keys(body) });
if (!isEmail(email)) return res.status(400).json({ error: 'Gültige E-Mail-Adresse fehlt.', felder: Object.keys(body) });
@@ -1622,26 +1625,32 @@ const handler = (router, { services, getSchema, logger }) => {
filter: { email: { _eq: email } }, limit: 1, fields: ['id'],
}))?.[0];
const phone = clean(String(body.telefon || body.phone || '').trim()) || null;
const phone = clean(feldWert(body, 'telefon', 'phone', 'tel', 'telefonnummer')) || null;
let record; let subject; let mailHtml;
if (kind === 'muster') {
const produkt = body.produkt_interesse ? clean(String(body.produkt_interesse)) : null;
const produkt = feldWert(body, 'produkt_interesse', 'product', 'produkt');
const strasse = feldWert(body, 'street', 'strasse', 'straße', 'adresse');
const plz = feldWert(body, 'zipcode', 'zip', 'plz', 'postleitzahl');
const ort = feldWert(body, 'ort', 'city', 'stadt', 'wohnort');
const land = feldWert(body, 'country', 'land');
record = {
type: 'muster', name: clean(name), email, phone, product: produkt, message: null,
type: 'muster', name: clean(name), email, phone, product: produkt ? clean(produkt) : null, message: null,
address: {
street: clean(String(body.street || '')),
zip: clean(String(body.zipcode || body.zip || '')),
city: clean(String(body.city || '')),
country: clean(String(body.country || '')),
first_name: clean(vorname),
last_name: clean(nachname),
street: clean(strasse),
zip: clean(plz),
city: clean(ort),
country: clean(land),
},
status: 'neu', customer: customer?.id ?? null,
};
subject = `Neue Musteranfrage: ${name}`;
mailHtml =
`<p><strong>${clean(name)}</strong> (${email}${phone ? `, ${phone}` : ''})</p>` +
`<p>Interesse: <strong>${produkt || 'k. A.'}</strong></p>` +
`<p>${clean(String(body.street || ''))}, ${clean(String(body.zipcode || body.zip || ''))} ${clean(String(body.city || ''))}, ${clean(String(body.country || ''))}</p>`;
`<p>Interesse: <strong>${produkt ? clean(produkt) : 'k. A.'}</strong></p>` +
`<p>${clean(strasse)}, ${clean(plz)} ${clean(ort)}, ${clean(land)}</p>`;
} else {
const unternehmen = clean(String(body.unternehmen || '').trim());
const nachricht = clean(String(body.nachricht || body.message || '').trim());