I am testing a code to send an email after a site visitor fills out and submits a form.
I understand such contacts are classified as CONTACTS for it is their first time to share and submit information. However, whenever the code runs, the error handling section of the code suggests that the contact (saved via the function appendORCreateContact) is a MEMBER. I’ve repeated the test multiple times and I get the same result. Hence, the triggeredEmails.emailContact will not run/work. Can anyone review this code please and share your thoughts why a new contact defaults as MEMBER?
import { triggeredEmails, contacts } from 'wix-crm';
$w.onReady(function ()
$w('#SubmitBTN').onClick(async () => {
const firstName = $w('#firstName').value;
const lastName = $w('#lastName').value;
const email = $w('#email').value;
const contactInfo = {
name: { first: firstName, last: lastName },
emails: [{ email: email }]
};
let resolvedContact;
try {
resolvedContact = await contacts.appendOrCreateContact(contactInfo);
console.log('Resolved to contact', resolvedContact);
if (resolvedContact.identityType !== 'CONTACT') {
console.log('Current contact is already a site member', resolvedContact.identityType );
// emailContact() cannot be used to email site members.
// If you want to email a member, use triggeredEmails.emailMember()
return; }
else {
const emailId = "PreBookReceived";
const contactId = resolvedContact.contactId;
await triggeredEmails.emailContact(emailId, contactId);
console.log('Emailed contact');
}
} catch (error) {
console.error(error);
}
});
});