@wexio/messenger-widget-react 1.0.0 → 1.0.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 +206 -24
- package/dist/widget-react.js +1 -1
- package/dist/widget-react.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
# @wexio/messenger-widget-react
|
|
1
|
+
# Welcome to @wexio/messenger-widget-react 👋
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@wexio/messenger-widget-react)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://wexio.io/docs)
|
|
5
6
|
|
|
6
|
-
Native React component for the [Wexio](https://wexio.io) web messenger. Renders inside a Shadow DOM portal
|
|
7
|
+
Native React component for the [Wexio](https://wexio.io) web messenger. Renders inside a Shadow DOM portal for full style isolation — same `WidgetShell` runtime as the script-injected iframe and the `<wexio-widget>` web component. Same chat, same visitor identity, same backend; the only difference is **where the React tree mounts.**
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
🏠 [Website](https://wexio.io)
|
|
10
|
+
📚 [Developer Docs](https://wexio.io/docs)
|
|
11
|
+
|
|
12
|
+
## 📂 Description
|
|
13
|
+
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick start](#quick-start)
|
|
16
|
+
- [Identifying users](#identifying-users)
|
|
17
|
+
- [Props](#props)
|
|
18
|
+
- [Methods](#methods)
|
|
19
|
+
- [Types](#types)
|
|
20
|
+
- [SSR](#ssr)
|
|
21
|
+
- [Browser support](#browser-support)
|
|
22
|
+
- [Troubleshooting](#troubleshooting)
|
|
23
|
+
- [Use with other frameworks](#use-with-other-frameworks)
|
|
24
|
+
- [Author](#author)
|
|
25
|
+
- [License](#-license)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
9
28
|
|
|
10
29
|
```bash
|
|
11
30
|
yarn add @wexio/messenger-widget-react
|
|
12
|
-
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or
|
|
34
|
+
|
|
35
|
+
```bash
|
|
13
36
|
npm install @wexio/messenger-widget-react
|
|
14
37
|
```
|
|
15
38
|
|
|
@@ -17,6 +40,8 @@ npm install @wexio/messenger-widget-react
|
|
|
17
40
|
|
|
18
41
|
## Quick start
|
|
19
42
|
|
|
43
|
+
Import the package on every page that should display the messenger (or on a common component used by them) and render the component. This must be done on the client side.
|
|
44
|
+
|
|
20
45
|
```tsx
|
|
21
46
|
import { WexioWidget } from "@wexio/messenger-widget-react";
|
|
22
47
|
|
|
@@ -30,24 +55,24 @@ export default function App() {
|
|
|
30
55
|
}
|
|
31
56
|
```
|
|
32
57
|
|
|
33
|
-
That's it — the widget mounts a floating launcher
|
|
58
|
+
That's it — the widget mounts a floating launcher, handles its own theme/locale/state, and the operator dashboard sees the visitor immediately. The component manages its own lifecycle internally, so re-renders due to host DOM changes won't trigger a re-boot.
|
|
34
59
|
|
|
35
60
|
## Identifying users
|
|
36
61
|
|
|
37
|
-
Pass a verified `user` to log a known visitor in (the Wexio equivalent of Intercom's `boot({ user_id, ... })`). Provide ONE proof — a Google FedCM `id_token`, a host-signed `jwt`, or
|
|
62
|
+
Pass a verified `user` to log a known visitor in (the Wexio equivalent of Intercom's `boot({ user_id, ... })`). Provide ONE proof — a Google FedCM `id_token`, a host-signed `jwt`, or the legacy `userId` + `userHash` HMAC pair:
|
|
38
63
|
|
|
39
64
|
```tsx
|
|
40
65
|
<WexioWidget
|
|
41
66
|
publicKey="pk_live_..."
|
|
42
67
|
user={{
|
|
43
|
-
jwt: serverSignedJwt,
|
|
68
|
+
jwt: serverSignedJwt, // host-signed identity token (recommended)
|
|
44
69
|
name: "Ada Lovelace",
|
|
45
70
|
email: "ada@example.com",
|
|
46
71
|
}}
|
|
47
72
|
/>
|
|
48
73
|
```
|
|
49
74
|
|
|
50
|
-
For an unverified pre-fill (skip the prechat form when the visitor's email is already known but you can't sign it), use `prefill
|
|
75
|
+
For an **unverified pre-fill** (skip the prechat form when the visitor's email is already known but you can't sign it), use `prefill`:
|
|
51
76
|
|
|
52
77
|
```tsx
|
|
53
78
|
<WexioWidget publicKey="pk_live_..." prefill={{ email: "ada@example.com" }} />
|
|
@@ -66,35 +91,146 @@ For an unverified pre-fill (skip the prechat form when the visitor's email is al
|
|
|
66
91
|
| `prefill` | [`VisitorPrefill`](#visitorprefill) | Unverified pre-fill for the prechat form. |
|
|
67
92
|
| `config` | [`InjectableWidgetConfig`](#injectablewidgetconfig) | Pre-resolved widget config. Set this if you already have the config server-rendered or fetched app-wide — skips the bootstrap fetch. |
|
|
68
93
|
| `lightboxViewport` | `boolean` | Render the media lightbox (image / video gallery) as a viewport-fixed overlay. Set `true` when the widget's host box is very small. |
|
|
69
|
-
| `onResize` | `(size: { width: number; height: number }) => void` | Fired whenever the widget's intended dimensions change (open ↔ closed ↔ expanded).
|
|
94
|
+
| `onResize` | `(size: { width: number; height: number }) => void` | Fired whenever the widget's intended dimensions change (open ↔ closed ↔ expanded). Use for host-side layout sync. |
|
|
70
95
|
| `onClose` | `() => void` | Fired when the visitor taps the close chip. |
|
|
71
96
|
| `className` | `string` | Pass-through class on the outer host `<div>`. Style this with normal layout CSS. |
|
|
72
97
|
| `style` | `React.CSSProperties` | Pass-through inline styles for the outer host `<div>`. |
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
## Methods
|
|
100
|
+
|
|
101
|
+
The visitor- and operator-facing imperative methods (`show`, `hide`, `update`, `shutdown`, `showSpace`, `showMessages`, `whoami`, `onUnreadCountChange`, etc.) live on `window.WexioWidget` once the component has mounted, mirroring the script loader's surface. A typed React hook (`useWexioWidget()`) ships in a future minor — until then, reach for the global from `useEffect`.
|
|
102
|
+
|
|
103
|
+
### show / hide / toggle
|
|
104
|
+
|
|
105
|
+
Open or close the messenger panel.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
window.WexioWidget?.show();
|
|
109
|
+
window.WexioWidget?.hide();
|
|
110
|
+
window.WexioWidget?.toggle();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### update
|
|
114
|
+
|
|
115
|
+
Patch live config (swap identity, switch theme, change locale).
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
window.WexioWidget?.update({ locale: "uk" });
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### shutdown / boot
|
|
122
|
+
|
|
123
|
+
Wipe session (token, sticky visitor id, prechat flags); `boot` re-initialises. Use on logout / shared devices.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
window.WexioWidget?.shutdown();
|
|
127
|
+
window.WexioWidget?.boot({ publicKey: "pk_live_..." });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### showSpace
|
|
131
|
+
|
|
132
|
+
Open the messenger and route to a specific tab.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
window.WexioWidget?.showSpace("home");
|
|
136
|
+
window.WexioWidget?.showSpace("messages");
|
|
137
|
+
window.WexioWidget?.showSpace("help");
|
|
138
|
+
window.WexioWidget?.showSpace("news");
|
|
139
|
+
window.WexioWidget?.showSpace("profile");
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### showMessages
|
|
143
|
+
|
|
144
|
+
Alias for `showSpace("messages")`.
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
window.WexioWidget?.showMessages();
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### showNewMessage
|
|
151
|
+
|
|
152
|
+
Open ready-to-compose. Optional prefill for the composer.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
window.WexioWidget?.showNewMessage();
|
|
156
|
+
window.WexioWidget?.showNewMessage("Hi, I have a question about...");
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### showArticle / showNews
|
|
160
|
+
|
|
161
|
+
Deep-link into a help article or news post.
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
window.WexioWidget?.showArticle(articleId);
|
|
165
|
+
window.WexioWidget?.showNews(newsItemId);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### onShow / onHide
|
|
169
|
+
|
|
170
|
+
Fire a callback when the messenger opens/closes.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
window.WexioWidget?.onShow(() => {
|
|
174
|
+
console.log("messenger opened");
|
|
175
|
+
});
|
|
176
|
+
window.WexioWidget?.onHide(() => {
|
|
177
|
+
console.log("messenger closed");
|
|
178
|
+
});
|
|
179
|
+
```
|
|
75
180
|
|
|
76
|
-
|
|
181
|
+
### onUnreadCountChange
|
|
182
|
+
|
|
183
|
+
Fires immediately with the current count, then on every change. Common use: badge the host tab title.
|
|
77
184
|
|
|
78
185
|
```tsx
|
|
79
186
|
useEffect(() => {
|
|
80
|
-
window.WexioWidget?.onUnreadCountChange?.((count) => {
|
|
187
|
+
return window.WexioWidget?.onUnreadCountChange?.((count) => {
|
|
81
188
|
document.title = count > 0 ? `(${count}) Inbox` : "Inbox";
|
|
82
189
|
});
|
|
83
190
|
}, []);
|
|
84
191
|
```
|
|
85
192
|
|
|
86
|
-
|
|
193
|
+
### hideNotifications
|
|
194
|
+
|
|
195
|
+
Suppress launcher peek bubbles on new operator messages.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
window.WexioWidget?.hideNotifications(true); // suppress
|
|
199
|
+
window.WexioWidget?.hideNotifications(false); // restore
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### whoami / getVisitorId
|
|
203
|
+
|
|
204
|
+
Read the current session.
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
const me = window.WexioWidget?.whoami();
|
|
208
|
+
// → { visitorId, peopleId, displayName, verified } | null
|
|
209
|
+
const visitorId = window.WexioWidget?.getVisitorId();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### setLocale
|
|
213
|
+
|
|
214
|
+
Programmatic language switch.
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
window.WexioWidget?.setLocale("uk");
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Future / reserved
|
|
221
|
+
|
|
222
|
+
The following names are reserved on the public surface for upcoming features and are no-ops today (with a `console.warn` in dev builds): `trackEvent`, `startTour`, `startSurvey`, `startChecklist`, `showTicket`. They'll light up when the corresponding backend features ship.
|
|
87
223
|
|
|
88
224
|
## Types
|
|
89
225
|
|
|
90
|
-
###
|
|
226
|
+
### VisitorIdentity
|
|
91
227
|
|
|
92
228
|
```ts
|
|
93
229
|
interface VisitorIdentity {
|
|
94
|
-
googleIdToken?: string;
|
|
95
|
-
jwt?: string;
|
|
96
|
-
userId?: string;
|
|
97
|
-
userHash?: string;
|
|
230
|
+
googleIdToken?: string; // Google FedCM id_token (preferred)
|
|
231
|
+
jwt?: string; // Host-signed JWT
|
|
232
|
+
userId?: string; // Legacy HMAC pair…
|
|
233
|
+
userHash?: string; // …(HMAC-SHA256(userId, integrationSecret))
|
|
98
234
|
name?: string;
|
|
99
235
|
email?: string;
|
|
100
236
|
phone?: string;
|
|
@@ -102,7 +238,7 @@ interface VisitorIdentity {
|
|
|
102
238
|
}
|
|
103
239
|
```
|
|
104
240
|
|
|
105
|
-
###
|
|
241
|
+
### VisitorPrefill
|
|
106
242
|
|
|
107
243
|
```ts
|
|
108
244
|
interface VisitorPrefill {
|
|
@@ -112,7 +248,7 @@ interface VisitorPrefill {
|
|
|
112
248
|
}
|
|
113
249
|
```
|
|
114
250
|
|
|
115
|
-
###
|
|
251
|
+
### InjectableWidgetConfig
|
|
116
252
|
|
|
117
253
|
The pre-resolved widget config shape (theme, features, blocks, prechat, messenger chrome, sounds, locale strategy). It deliberately excludes `status`, `branding`, and `security.allowedOrigins` — those are server-owned and not host-overridable. Pull the full type from the package:
|
|
118
254
|
|
|
@@ -128,6 +264,52 @@ The component renders `null` on the server. The Shadow-DOM portal target mounts
|
|
|
128
264
|
|
|
129
265
|
Modern evergreen browsers — anything that supports Shadow DOM and ES2020. Internet Explorer is not supported.
|
|
130
266
|
|
|
131
|
-
##
|
|
267
|
+
## Troubleshooting
|
|
268
|
+
|
|
269
|
+
### Messenger not showing on page
|
|
270
|
+
|
|
271
|
+
- Check that the correct `publicKey` is being passed.
|
|
272
|
+
- Check the messenger is **active** for your integration on https://app.wexio.io.
|
|
273
|
+
- Confirm the component renders on the client (not during SSR) — `<WexioWidget>` returns `null` until the first `useEffect`.
|
|
274
|
+
|
|
275
|
+
### No user data attached
|
|
276
|
+
|
|
277
|
+
- Verify you're computing `userHash` server-side as `HMAC-SHA256(userId, integrationSecret)`. Never expose the integration secret to the browser.
|
|
278
|
+
- Confirm the proof you pass in `user` is one of: `googleIdToken`, `jwt`, or `userId` + `userHash`. Passing multiple proofs uses the first one detected (Google → jwt → HMAC).
|
|
279
|
+
|
|
280
|
+
### TypeScript errors after upgrade
|
|
281
|
+
|
|
282
|
+
The public type surface is locked to `entries/public.ts` in the source repo. If you previously relied on undocumented props (`mode: "preview"`, `configOverride`, `useDummyData`, `previewData`), they are no longer exposed — they were dashboard-only and never meant to ship. Remove them and the build will pass.
|
|
283
|
+
|
|
284
|
+
## Use with other frameworks
|
|
285
|
+
|
|
286
|
+
The underlying widget runtime is a Web Component, so it works in any modern framework — even without a typed wrapper:
|
|
287
|
+
|
|
288
|
+
```html
|
|
289
|
+
<wexio-widget public-key="pk_live_..."></wexio-widget>
|
|
290
|
+
<script type="module" src="https://cdn.wexio.io/widget.js"></script>
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Typed wrappers are on the roadmap:
|
|
294
|
+
|
|
295
|
+
- `@wexio/messenger-widget-vue` — coming soon
|
|
296
|
+
- `@wexio/messenger-widget-angular` — coming soon
|
|
297
|
+
- `@wexio/messenger-widget-ember` — coming soon
|
|
298
|
+
|
|
299
|
+
For plain HTML / script-injection setups, paste the loader snippet from https://wexio.io/docs.
|
|
300
|
+
|
|
301
|
+
## Author
|
|
302
|
+
|
|
303
|
+
👤 **Wexio** ([https://wexio.io](https://wexio.io))
|
|
304
|
+
|
|
305
|
+
## Show your support
|
|
306
|
+
|
|
307
|
+
Give a ⭐️ if this package helped you!
|
|
308
|
+
|
|
309
|
+
## 📝 License
|
|
310
|
+
|
|
311
|
+
This project is [MIT](./LICENSE) licensed.
|
|
312
|
+
|
|
313
|
+
---
|
|
132
314
|
|
|
133
|
-
[
|
|
315
|
+
_Created with ❤️ by [Wexio](https://wexio.io)_
|