Fix Resend contact sync payload and support separate contacts key
This commit is contained in:
@@ -122,9 +122,10 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
|
||||
|
||||
const resend = new Resend(process.env.RESEND_API_KEY)
|
||||
const { firstName, lastName } = splitName(trimmedName)
|
||||
const contactResend = new Resend(process.env.RESEND_CONTACTS_API_KEY ?? process.env.RESEND_API_KEY)
|
||||
|
||||
try {
|
||||
const { error: contactError } = await resend.contacts.create({
|
||||
const { error: contactError } = await contactResend.contacts.create({
|
||||
email: trimmedEmail,
|
||||
firstName,
|
||||
lastName,
|
||||
@@ -132,22 +133,14 @@ app.post('/api/contact', contactRateLimit, async (req, res) => {
|
||||
...(process.env.RESEND_SEGMENT_ID
|
||||
? { segments: [{ id: process.env.RESEND_SEGMENT_ID }] }
|
||||
: {}),
|
||||
properties: {
|
||||
source: 'website-contact-form',
|
||||
last_message_at: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
if (contactError) {
|
||||
const { error: updateError } = await resend.contacts.update({
|
||||
const { error: updateError } = await contactResend.contacts.update({
|
||||
email: trimmedEmail,
|
||||
firstName,
|
||||
lastName,
|
||||
unsubscribed: false,
|
||||
properties: {
|
||||
source: 'website-contact-form',
|
||||
last_message_at: new Date().toISOString(),
|
||||
},
|
||||
})
|
||||
|
||||
if (updateError) {
|
||||
|
||||
Reference in New Issue
Block a user