Skip to content

Commit

Permalink
Chat authentication docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jordrake committed Oct 18, 2024
1 parent 1c9e1db commit e052af8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions chat/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: 'Authentication'
---

## Providing customer details

By default, customers chatting with you will be anonymous. You can pass customer details, if you know them, by calling `Plain.setCustomerDetails`:

```typescript
Plain.setCustomerDetails({
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 a hashed email address 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 and pass it to the `Plain.setCustomerDetails` function:

```typescript
import * as crypto from 'node:crypto';

const secret = '<YOUR_SECRET>';
const email = '[email protected]';
const hmac = crypto.createHmac('sha256', secret);
hmac.update(email);
const hash = hmac.digest('hex');

Plain.setCustomerDetails({
fullName: 'John Doe',
shortName: 'John',
chatAvatarUrl: 'https://picsum.photos/32/32',
email: email,
emailHash: hash,
});
```
3 changes: 2 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
{
"group": "Chat",
"pages": [
"chat"
"chat",
"chat/authentication"
]
},
{
Expand Down

0 comments on commit e052af8

Please sign in to comment.