Providing customer details

By default, customers chatting with you will be anonymous. You can pass customer details, if you know them, in the Plain.init function call:

Plain.init({
  // ... Other options
  customerDetails: {
    fullName: 'John Doe', // Optional
    shortName: 'John', // Optional
    chatAvatarUrl: 'https://picsum.photos/32/32', // Optional
  },
});

These details will be shown to you in the Plain app when you are chatting with the customer but they will not be matched to an existing customer even if they have the same details.

Matching chat users to existing customers

If you want to match the customer to an existing customer in your workspace, you will need to pass their email. To avoid security issues around impersonation you will also need to provide the email address hashed using a shared secret. You can generate this secret in the Chat settings page in the Plain app.

Once you have this secret, you can calculate the hash. This must be done in backend code to avoid leaking the secret. If your secret is leaked malicious users will be able to impersonate your customers in chats.

Backend code:

import * as crypto from 'node:crypto';

const secret = '<YOUR_SECRET>';
const email = 'johndoe@example.com';
const hmac = crypto.createHmac('sha256', secret);
hmac.update(email);
const hash = hmac.digest('hex');

Then you can request the hash from your backend and init Plain:

const email = 'johndoe@example.com';
const hash = fetchHashFromBackend(email);

Plain.init({
  customerDetails: {
    email: email,
    emailHash: hash,
    // If you pass other customer details (e.g. fullName), this will also update their customer details within Plain
    // If you don't pass any other customer details, we will use their existing details within Plain
  },
});

Customer verification

If you want to see the name and email of customers who get in touch via chat you can require them to provide their details by setting requireAuthentication to true in Plain init:

Plain.init({
  requireAuthentication: true
});

When enabled, any customer getting in touch will first be presented with a form allowing them to enter their name and email address.

The customer will then receive a verification code to that email which they can enter to start a chat.

If an emailHash is already set in customerDetails, then the verification screen will not appear since the customer has already been authenticated.