Contacting Site Member Directly (P2P)

As Custom Registration issue is finally sorted, I have the last question left, in order to make my website functionable enough)

I have a repeater with player profiles. Once the Contact button is clicked, lightbox appears and I want a message, as well as sender’s information, to be sent as an email to the recipient + copy of that message to be sent over to me. Does anyone know how to do that?

Already tried to search for relevant posts?

This should give you enough of information, to solve your issue.

  1. https://www.wix.com/velo/forum/community-discussion/database-email-notification
  2. https://www.wix.com/velo/forum/tips-tutorials-examples/triggered-emails
  3. https://www.wix.com/velo/forum/community-discussion/sending-template-emails-with-sendgrid-v3
  4. https://www.wix.com/velo/forum/community-discussion/send-triggered-email-to-a-user-not-logged-in
  5. https://www.wix.com/velo/forum/tips-tutorials-examples/example-send-email-with-the-sendgrid-npm-interface
  6. https://www.wix.com/velo/forum/tips-tutorials-examples/example-send-email-with-the-sendgrid-rest-interface

And here a little template for you (i also once did some experiments on it).
https://russian-dima.wixsite.com/meinewebsite/blank-6

Good luck.

Tbf, I didn’t. Thanks again Dima, I will take a look once I am free! Have a great week!

Наконец-то я вернулся) Так, поехали!)

Just to start ball rolling, I will post your draft, as I have some questions, meanwhile I will keep looking for the information on the forum as well as on Velo Tech:

import wixUsers from ‘wix-users’ ;

$w.onReady( function () { });

//-----------------------------------------------------------------------------------------
export function button3_click(event) {send_Email ()}
//-----------------------------------------------------------------------------------------

function send_Email (parameter) {

let userId = wixUsers.currentUser.id;
let value1 = “test@test.com

console.log(userId) 
console.log(value1) 

wixUsers.emailUser( "DPCform1" , userId, { 

“variables” : {
“name” : $w( “#DPCname1” ).value,
“variable1” : value1,
“variable2” : “value for variable2”
}
} )

.then( () => { 
    console.log( "Triggered email sent" ); 
} ) 

. **catch** ( (err) => { 
    console.log(err); 
} ); 

console.log(( "Job done!" )) 

$w( '#DPCname1' ).show() 
$w( '#TXT1' ).text= "Test-Mail successfully sent. Delivery in about 15sec." 
setTimeout(()=>{$w( '#DPCname1' ).hide()}, 3500 ) 

}

//"variable2": "value for variable2"

what does this part mean?

    $w('#DPCname1').show()
    $w('#TXT1').text="Test-Mail successfully sent. Delivery in about 15sec."
    setTimeout(()=>{$w('#DPCname1').hide()},3500)

Is it just to confirm that the message was successfully sent?

let userId = wixUsers.currentUser.id;  
let value1 = "test@test.com"  
     
console.log(userId)     
console.log(value1)     
  
wixUsers.emailUser("DPCform1", userId, 
{  "variables": 
{  
"name": $w("#DPCname1").value, 
"text": $w("#DPCtext1").value,  
"variable1": value1,  
"variable2": "value for variable2"         
}     
} 
)

text will be my actual comment.

Do you I need to mention anywhere in the code the end user (receiver), or, as it part of the Repeater and it is connected to the database, the end user will receiver a notification anyway if someone is gonna contact him/her?

Once again sorry for the silly questions)

I still couldn’t find a way how it make it work. After looking on Wix forum, the closest topic I managed to find is this one, however no one actually provided a solution:
https://community.wix.com/partners/forum/technical-talk/sending-email-to-another-site-member

The only thing I need is a recipient to receive an email notification once someone from the site members have contacted them directly (by submitting Lightbox on players profiles page).

Thanks

OK, have tried to play a bit with the code, however the recipient still doesn’t receive an email (I only get a confirmation as an admin, but that’s not what is needed):

import wixUsers from ‘wix-users’ ;

$w . onReady ( function () { });

export function button3_click ( event ) { send_Email ()}
function send_Email ( parameter ) {

let userId = wixUsers . currentUser . id ;
let value1 = “a@a.com” ; (// on a code have got my personal one)
let name ;
let email ;

console . log ( userId ) 
console . log ( value1 ) 
console . log ( name ) 
console . log ( email ) 

wixUsers . emailUser ( "SWMN4Vx" ,  userId , { 

“variables” : {
“variable1” : value1 ,
“name” : name ,
“email” : email ,
“comments” : $w ( “#DPCtext1” ). value
}
} )

. then ( () => {
console . log ( “Triggered email sent” );
} )

. catch ( ( err ) => {
console . log ( err );
} );

console . log (( "Job done!" )) 

}

Already have seen this post here…?
https://www.wix.com/velo/forum/coding-with-velo/send-triggered-email-to-a-user-not-logged-in

https://www.wix.com/velo/reference/wix-users-backend/emailuser
https://www.wix.com/velo/reference/wix-crm-backend/emailcontact

You’ll need to do it from —> backend.

And you have still 2 other options…

  1. https://www.wix.com/velo/reference/wix-crm-backend/emailcontact
  2. https://www.wix.com/velo/forum/coding-with-velo/sending-template-emails-with-sendgrid-v3

Yes, I saw it before)

In my case it will be emailUser, as it will be done for site members only.

Have changed in to backend:

import wixUsersBackend from 'wix-users-backend';
 
export function button3_click(event) {send_Email ()}
 function send_Email (parameter) {

 let userId = wixUsersBackend.currentUser.id;
 let value1 = "e**@gmail.com";
 let name;
 let email;
 
    console.log(userId)
    console.log(value1)
    console.log(name)
    console.log(email)
 
    wixUsersBackend.emailUser("SWMN4Vx", userId, {
 "variables": {
 "variable1": value1,
 "name": name,
 "email": email,
 }
 } )
 
 .then( () => {
        console.log("Triggered email sent");
 } )

 .catch( (err) => {
        console.log(err);
 } );

    console.log(("Job done!"))
 
 }  

And now it works for you ?

  1. You created a JSW-file?
  2. You imported your back-end into front-end?

I assume it still does not work?

  1. Yes, did that
  2. nope - trying to figure out how to do that

Perhaps you will learn something from here… (parralel-post similar to your needs)…
How to work with Back-End and Front-End…

Thank you Dima. But now I even more confused))
What do you I need to code in backend then?

In my case it will be emailUser ,… . ----> RIGHT !
Do the same like in the shown (parallel) example…, but using —> emailUser
Divide your code into 2-parts → Back-End + Front-End.

Backend-Code…

//Send a Triggered Email to a site member with variable values
import wixUsersBackend from 'wix-users-backend';

export function myBackendFunction() {
   let userID = "Insert USER-ID here !" //first you will have to get the USER-ID
   let value1 = "My variable VALUE !"
   let value2 = "value for variable2"
   let emailID = "Insert Email-ID here !" //first you will have to get the email-ID

   console.log("User-ID: ", userID)
   console.log("Value-1: ", value1)
   console.log("Value-2: ", value2)
   console.log("E-Mail: ", emailID)

   wixUsersBackend.emailUser(emailID, userID, {
      "variables": {
      "variable1": value1,
      "variable2": value2
      }
   })
 .then(() => {console.log("Triggered email sent");})
 .catch( (err) => {console.log(err);});
}

Front-End-Code:

import {InsertBackEndFunctionNameHere} from 'InsertCreatedJSWfileNameHere.jsw';

//in this case the backend-function-name is ---> myBackendFunction()
//{InsertBackEndFunctionNameHere} ---> {myBackendFunction}

$w.onReady(function() {
 //generate your front-end-code here....
 //calling myBackendFunction() in Back-End....
    myBackendFunction();
});

Now you have 2-options…

  1. Getting all the user-data directly from backend…
  2. Gertting some user-data from front-end and send that data to back-end to get a RETURNed data back to front-end.

You will surely want to send some DATA from front-end to back-end…
This would be —> option-2 —> sending first data from FE to BE & than RETURN…

$w.onReady(function() {
 //generate your front-end-code here....
 //calling myBackendFunction() in Back-End....
    let myValue1 = "Here my message1, or what ever you want"
    let myValue2 = "Another message here"
    let User-ID = "1112223333444"
    
    myBackendFunction(myValue1, myValue2, UserID); //-----------------> no expected result
    let zzz = await myBackendFunction(myValue1, myValue2, UserID); //  --> expected result
});

Receiving data on Back-End…

export function myBackendFunction(myValue1, myValue2, UserID) {
    console.log(myValue1);
    console.log(myValue2);
    console.log(UserID);
    let xxx = UserID+"999"
    return xxx //<<--- RETURN back to Front-End..... (sending back RESULT of UserID)
}

Or would it be the better way, to get all the data right from beginning from back-end?

  1. Starting the back-end-process from front-end.
  2. Getting all needed data on back-end.
  3. Do some action (send email).
  4. Sending result to front-end (if needed)

Tnx Dima!

I know it is a total mess, but this what I got to (Backend // directcontact.jsw):

import wixUsersBackend from ‘wix-users-backend’ ;

let userId = user . id ;
let isLoggedIn = user . loggedIn ; // true
user . getEmail ()
. then ( ( email ) => {
let userEmail = email ;
} );

export function sendEmail ( parameter ) {

let userId = wixUsersBackend . currentUser . id or “Insert userID” ; //first you will have to get the USER-ID
let value1 = “e**@gmail.com” ;
let name ;
let emailId = “SWMN4Vx” or “Insert user emailID” //first you will have to get the email-ID

console . log ( userId ) 
console . log ( value1 ) 
console . log ( name ) 
console . log ( emailId ) 

wixUsersBackend . emailUser ( "SWMN4Vx" ,  userId , { 

“variables” : {
“variable1” : value1 ,
“name” : name ,
“email” : emailId ,
}
} )

. then ( () => {
console . log ( “Triggered email sent” );
} )

. catch ( ( err ) => {
console . log ( err );
} );

console . log (( "Job done!" )) 

}

and Frontend:

import { sendEmail } from ‘directcontract.jsw’ ;

$w . onReady ( function () {});

export function button3_click ( event ) { send_Email ()}
function send_Email ( parameter ) {

}

Please put your code into —> CODE-BLOCKs for better reading! Спасибо!

Hi Dima. Sorry for a delay, was tied up with other things.

Posting the code properly:

Backend:

import wixUsersBackend 
 from'wix-users-backend';
  let userId = user.id;
  let isLoggedIn = user.loggedIn;// true 
  user.getEmail()
  .then((email)=>{
  let userEmail = email;});
  
 exportfunctionsendEmail(parameter){
  let userId = wixUsersBackend.currentUser.id or "Insert userID";//first you will have to get the USER-ID
  let value1 ="e**@gmail.com";
  let name;
  let emailId ="SWMN4Vx" or "Insert user emailID"//first you will have to get the email-ID       
  
  console.log(userId)     
  console.log(value1)
  console.log(name)
  console.log(emailId)
  
  wixUsersBackend.emailUser("SWMN4Vx", userId,{
  "variables":{
  "variable1": value1,
  "name": name,
  "email": emailId,
  }
  })
 
   .then(()=>{
    console.log("Triggered email sent");
    })
  
    .catch((err)=>{
          console.log(err);
          });      
          
     console.log(("Job done!"))
     }

Frontend:

import{sendEmail}from'directcontract.jsw';  

$w.onReady(function(){});

exportfunctionbutton3_click(event){send_Email ()}
 functionsend_Email(parameter){}

Now my few questions…

  1. What do i see in your last post? Solution? Or question? I do not see any question, so i guess you found your solution ?

I am hones, i did not read all the post, i will do, when i know the answer for (1).

Second question: If it is still not resolved. Did you ever think about a messanging function, which would send an SMS or a Whattsapp-Message directly onto the wished user’s mobile instead of using an e-mail?

Why i am asking, because …

Contacting Site Member Directly (P2P)

Contacting to phone is even more DIRECT :grin:

Уловил подкол!:rofl:
No, it still not resolved, as this code doesn’t work. I have posted the stage/code where I am currently at and don’t know how to progress further on solving the problem.

Regarding contacting over the phone: some members obviously will receive more attention and the last thing you want is your phone constantly buzzing with the invitation to play a tennis match. Emails look an optimal solution.