-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Chat authentication docs * Update chat auth docs to use Plain.init instead of Plain.setCustomerDetails * Fix lint * Include new styling options
- Loading branch information
Showing
3 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,8 @@ | |
{ | ||
"group": "Chat", | ||
"pages": [ | ||
"chat" | ||
"chat", | ||
"chat/authentication" | ||
] | ||
}, | ||
{ | ||
|