@neuphlo/widget-react 0.1.0 → 0.3.0

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/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
25
  /** Workspace widget key from Inbox settings → Chat widget. */
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
- useEffect(() => loadNeuphloWidget({ widgetKey, scriptUrl, appUrl, position, color }), [widgetKey, scriptUrl, appUrl, position, color]);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuphlo/widget-react",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "React component for the Neuphlo support chat widget",
5
5
  "license": "MIT",
6
6
  "repository": {