@neuphlo/widget-react 0.1.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/dist/index.d.ts +14 -1
- package/dist/index.js +33 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @neuphlo/widget-react
|
|
2
2
|
|
|
3
|
-
React bindings for the [Neuphlo](https://neuphlo.com)
|
|
3
|
+
React bindings for the [Neuphlo](https://neuphlo.com) Messenger. Renders a floating launcher; conversations land in your Neuphlo inbox with the same draft-and-approve flow as email.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -45,10 +45,36 @@ import { openNeuphloWidget } from "@neuphlo/widget-react"
|
|
|
45
45
|
|
|
46
46
|
| Option | Default | Description |
|
|
47
47
|
| --- | --- | --- |
|
|
48
|
-
| `widgetKey` | — | Workspace widget key from Inbox settings →
|
|
48
|
+
| `widgetKey` | — | Workspace widget key from Inbox settings → Messenger |
|
|
49
|
+
| `user` | — | Signed-in user: `{ id, name, email, hash }` |
|
|
49
50
|
| `position` | `"right"` | Launcher corner, `"left"` or `"right"` |
|
|
50
51
|
| `color` | `"#171717"` | Launcher accent color |
|
|
51
52
|
| `appUrl` | Neuphlo cloud | Your app origin for self-hosted installs |
|
|
52
53
|
| `scriptUrl` | `https://get.neuphlo.com/widget.js` | Loader script URL |
|
|
53
54
|
|
|
54
55
|
The widget unmounts cleanly — the launcher and panel are removed when the component unmounts.
|
|
56
|
+
|
|
57
|
+
## Identifying users
|
|
58
|
+
|
|
59
|
+
Pass the signed-in user so conversations are recognized in your inbox:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
<NeuphloWidget
|
|
63
|
+
widgetKey="your-widget-key"
|
|
64
|
+
user={{ id: user.id, name: user.name, email: user.email, hash: user.neuphloHash }}
|
|
65
|
+
/>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`hash` enables identity verification — compute it **server-side** with the
|
|
69
|
+
widget identity secret from Inbox settings → Messenger:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { createHmac } from "node:crypto"
|
|
73
|
+
|
|
74
|
+
const neuphloHash = createHmac("sha256", process.env.NEUPHLO_IDENTITY_SECRET)
|
|
75
|
+
.update(user.id)
|
|
76
|
+
.digest("hex")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Workspaces with "Require verified identities" enabled reject identified
|
|
80
|
+
conversations without a valid hash; anonymous visitors are unaffected.
|
package/dist/index.d.ts
CHANGED
|
@@ -10,9 +10,22 @@ export interface NeuphloWidgetApi {
|
|
|
10
10
|
toggle: () => void;
|
|
11
11
|
destroy: () => void;
|
|
12
12
|
}
|
|
13
|
+
export interface NeuphloWidgetUser {
|
|
14
|
+
/** Your product's user id, stored on the conversation. */
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
/**
|
|
19
|
+
* HMAC-SHA256 of the user id (or email when no id), keyed with your
|
|
20
|
+
* workspace's widget identity secret. Compute it server-side.
|
|
21
|
+
*/
|
|
22
|
+
hash?: string;
|
|
23
|
+
}
|
|
13
24
|
export interface NeuphloWidgetOptions {
|
|
14
|
-
/** Workspace widget key from Inbox settings →
|
|
25
|
+
/** Workspace widget key from Inbox settings → Messenger. */
|
|
15
26
|
widgetKey: string;
|
|
27
|
+
/** Identify the signed-in user so conversations are recognized. */
|
|
28
|
+
user?: NeuphloWidgetUser;
|
|
16
29
|
/** Loader script origin. Defaults to the Neuphlo cloud. */
|
|
17
30
|
scriptUrl?: string;
|
|
18
31
|
/** Neuphlo app origin, for self-hosted installs. */
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,14 @@ export function loadNeuphloWidget(options) {
|
|
|
18
18
|
script.dataset.position = options.position;
|
|
19
19
|
if (options.color)
|
|
20
20
|
script.dataset.color = options.color;
|
|
21
|
+
if (options.user?.id)
|
|
22
|
+
script.dataset.userId = options.user.id;
|
|
23
|
+
if (options.user?.name)
|
|
24
|
+
script.dataset.userName = options.user.name;
|
|
25
|
+
if (options.user?.email)
|
|
26
|
+
script.dataset.userEmail = options.user.email;
|
|
27
|
+
if (options.user?.hash)
|
|
28
|
+
script.dataset.userHash = options.user.hash;
|
|
21
29
|
document.body.appendChild(script);
|
|
22
30
|
return () => {
|
|
23
31
|
window.NeuphloWidget?.destroy();
|
|
@@ -26,8 +34,31 @@ export function loadNeuphloWidget(options) {
|
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
36
|
export function useNeuphloWidget(options) {
|
|
29
|
-
const { widgetKey, scriptUrl, appUrl, position, color } = options;
|
|
30
|
-
|
|
37
|
+
const { widgetKey, scriptUrl, appUrl, position, color, user } = options;
|
|
38
|
+
const userId = user?.id;
|
|
39
|
+
const userName = user?.name;
|
|
40
|
+
const userEmail = user?.email;
|
|
41
|
+
const userHash = user?.hash;
|
|
42
|
+
useEffect(() => loadNeuphloWidget({
|
|
43
|
+
widgetKey,
|
|
44
|
+
scriptUrl,
|
|
45
|
+
appUrl,
|
|
46
|
+
position,
|
|
47
|
+
color,
|
|
48
|
+
user: userId || userName || userEmail
|
|
49
|
+
? { id: userId, name: userName, email: userEmail, hash: userHash }
|
|
50
|
+
: undefined,
|
|
51
|
+
}), [
|
|
52
|
+
widgetKey,
|
|
53
|
+
scriptUrl,
|
|
54
|
+
appUrl,
|
|
55
|
+
position,
|
|
56
|
+
color,
|
|
57
|
+
userId,
|
|
58
|
+
userName,
|
|
59
|
+
userEmail,
|
|
60
|
+
userHash,
|
|
61
|
+
]);
|
|
31
62
|
}
|
|
32
63
|
export function NeuphloWidget(props) {
|
|
33
64
|
useNeuphloWidget(props);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuphlo/widget-react",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "React
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "React bindings for the Neuphlo Messenger",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|