(resolved)how can a site member email a contact, using code?

Hi guys can anyone help? i want a loggedIn site member to be able to email a stored contact, so the site member would query the crm contacts database with the contacts email address with code that is fetched via a dataset from a separate JobPosts database, and if it finds the email in the contacts it then sends a triggered email with a message onto the contact, can this be done thanks?

And I’ve already tried this code and it doesn’t work?

import { contacts, triggeredEmails } from 'wix-crm-backend';

/* Sample emailToFind value:
 * 'zackary.sirko@example.com'
 */

export async function sendEmailToContact(emailToFind) {

  let contactId;
  const queryResults = await contacts.queryContacts()
    .eq('info.emails.email', emailToFind)
    .find();
  const contactsWithEmail = queryResults.items;

  if (contactsWithEmail.length === 1) {

    console.log('Found 1 contact');
    contactId = contactsWithEmail[0]._id;

  } else if (contactsWithEmail.length > 1) {

    console.log('Found more than 1 contact');
    // Handle when more than one contact is found

  } else {

    console.log('No contacts found');
    // Handle when no contacts are found

  }

  const triggeredEmailTemplate = 'welcome_email';

  try {
    await triggeredEmails.emailContact(triggeredEmailTemplate, contactId);
    console.log('Email sent to contact');
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

Turns out a modified code of the above snippet does work, i tried until i was blue in the face yesterday with different versions of this code, however it turns out it was a wix bug, the datasets on the page also the data on the page was sticking and causing a bug, so undid any changes made to the page, then my code above was being recognised. the site logs and error were also sticking and no matter how many times i changed the code it was the same error, i think wix needs to sort itself out.