Skip to content

Commit

Permalink
Chat authentication docs (#116)
Browse files Browse the repository at this point in the history
* Chat authentication docs

* Update chat auth docs to use Plain.init instead of Plain.setCustomerDetails

* Fix lint

* Include new styling options
  • Loading branch information
jordrake authored Oct 22, 2024
1 parent b473f56 commit 277f2f8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
14 changes: 9 additions & 5 deletions _snippets/chat/customization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ Plain.init({
},
],

// Optional. The color of your brand which will be used in parts of the Chat as well as the launcher color
brandColor: '#000000',

// Optional. The entry point of the Chat, is either 'default' or 'chat'
// 'chat' will open the last conversation the user had. (default: 'default')
// 'chat' will open the last conversation the user had (default: 'default')
entryPoint: 'default',

// Optional. The color scheme of the Chat, is either 'auto', 'light', or 'dark'.
// Optional. The color scheme of the Chat, is either 'auto', 'light', or 'dark'
// 'auto' uses the user's browser preference to decide between light and dark mode (default: 'auto')
theme: 'light',

// Optional. Various styling options
// Colors can also be passed in this format { light: '#FFFFFF', dark: '#000000' }. Based on the theme chosen by you or browser preference
style: {
chatButtonColor: '#000000'; // These can also be passed in this foramt { light: '#FFFFFF', dark: '#000000' }
chatButtonIconColor: '#FFFFFF';
}
});
```
46 changes: 46 additions & 0 deletions chat/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: 'Authentication'
---

## 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:

```typescript
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 and pass it to the `Plain.init` 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.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
},
});
```
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 277f2f8

Please sign in to comment.