tirggeredEmails code defaults contacts as MEMBER

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);
    }
  });
});

Hi,

Is it possible you are testing the visitor form in preview mode or while logged in?

This would return a ContactIdentification object with the status “MEMBER”.

Or are you entering visitor information that is associated to a existing member profile (even while logged off)?

This would return a ContactIdentification object with the status “NOT_AUTHENTICATED_MEMBER”.

Based on the documentation, here is the behavior for what contacts.appendOrCreateContact() returns:

  1. If the current visitor is a logged-in member: appendOrCreateContact() reconciles with the member’s associated contact.
  2. If the visitor is not a logged-in member: appendOrCreateContact() tries to reconcile any specified email addresses and/or phone numbers with an existing contact.
  3. If no contact can be reconciled in the previous steps: appendOrCreateContact() tries to reconcile the visitor’s session identity with an existing contact.
  4. If no contact can be reconciled and an email address, phone number, or name are provided: A new contact is created and appendOrCreateContact() reconciles with the new contact.
  5. If no contact can be created: The Promise is rejected.

Hello Thomas. Thank you for taking time to reply to my post.

I save the code and publish the site prior to testing. I’m logged in as the administrator during the test, but i provide random information and an email address that is not registered as a contact or member yet.

Is that the reason why my code always return MEMBER?

If so how should i test the triggeredemail please?

@gettyah

That sounds like it might be the issue. If you’re logged into your account on the live site, the following condition will be triggered: