@wexio/messenger-widget-ember 1.0.23
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/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +90 -0
- package/dist/widget.js +100809 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wexio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# Welcome to @wexio/messenger-widget-ember 👋
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@wexio/messenger-widget-ember)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://learn.wexio.io/docs/web-widget)
|
|
6
|
+
|
|
7
|
+
Ember integration for the [Wexio](https://wexio.io) web messenger. Registers the underlying `<wexio-widget>` custom element so Glimmer renders it natively — no Ember component wrapper required.
|
|
8
|
+
|
|
9
|
+
🏠 [Website](https://wexio.io)
|
|
10
|
+
📚 [Developer Docs](https://learn.wexio.io/docs/web-widget)
|
|
11
|
+
|
|
12
|
+
## 📂 Description
|
|
13
|
+
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick start](#quick-start)
|
|
16
|
+
- [Event handling](#event-handling)
|
|
17
|
+
- [Identifying users](#identifying-users)
|
|
18
|
+
- [Service helper](#service-helper)
|
|
19
|
+
- [Types](#types)
|
|
20
|
+
- [Browser support](#browser-support)
|
|
21
|
+
- [Author](#author)
|
|
22
|
+
- [License](#-license)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add @wexio/messenger-widget-ember
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @wexio/messenger-widget-ember
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Ember 4+ is supported. The package has no required peer deps — `ember-source` is listed as an optional peer for clarity.
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
|
|
40
|
+
Import the package **once** at app boot to register the custom element:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// app/app.js (or any module loaded at boot)
|
|
44
|
+
import "@wexio/messenger-widget-ember";
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then use `<wexio-widget>` directly in any template:
|
|
48
|
+
|
|
49
|
+
```hbs
|
|
50
|
+
{{! app/templates/application.hbs }}
|
|
51
|
+
<wexio-widget public-key="pk_live_..."></wexio-widget>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Glimmer renders the unknown tag as a native DOM element. The custom-element runtime kicks in, mounts a Shadow-DOM-isolated Wexio messenger, and the operator dashboard sees the visitor immediately.
|
|
55
|
+
|
|
56
|
+
## Event handling
|
|
57
|
+
|
|
58
|
+
`<wexio-widget>` dispatches standard `CustomEvent`s. Bind handlers with Ember's built-in `{{on}}` modifier:
|
|
59
|
+
|
|
60
|
+
```hbs
|
|
61
|
+
<wexio-widget
|
|
62
|
+
public-key="pk_live_..."
|
|
63
|
+
{{on "wexio:resize" this.onResize}}
|
|
64
|
+
{{on "wexio:close" this.onClose}}
|
|
65
|
+
></wexio-widget>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
// app/components/foo.js
|
|
70
|
+
import Component from "@glimmer/component";
|
|
71
|
+
import { action } from "@ember/object";
|
|
72
|
+
|
|
73
|
+
export default class FooComponent extends Component {
|
|
74
|
+
@action onResize(event) {
|
|
75
|
+
const { width, height } = event.detail;
|
|
76
|
+
console.log(width, height);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@action onClose() {
|
|
80
|
+
console.log("visitor closed the panel");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Identifying users
|
|
86
|
+
|
|
87
|
+
Identity is set imperatively on the DOM element. Use the [service helper](#service-helper) or grab the element directly:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
// app/routes/application.js
|
|
91
|
+
import Route from "@ember/routing/route";
|
|
92
|
+
import { inject as service } from "@ember/service";
|
|
93
|
+
|
|
94
|
+
export default class ApplicationRoute extends Route {
|
|
95
|
+
@service session; // your own session service
|
|
96
|
+
|
|
97
|
+
async afterModel() {
|
|
98
|
+
if (this.session.isAuthenticated) {
|
|
99
|
+
const el = document.querySelector("wexio-widget");
|
|
100
|
+
el?.identify({
|
|
101
|
+
jwt: this.session.jwt, // host-signed identity token
|
|
102
|
+
name: this.session.user.name,
|
|
103
|
+
email: this.session.user.email,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Service helper
|
|
111
|
+
|
|
112
|
+
The package exports a `WexioWidgetService` class you can extend to register as a proper Ember service:
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
// app/services/wexio-widget.js
|
|
116
|
+
import { WexioWidgetService } from "@wexio/messenger-widget-ember";
|
|
117
|
+
export default class extends WexioWidgetService {}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Inject anywhere:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import Component from "@glimmer/component";
|
|
124
|
+
import { action } from "@ember/object";
|
|
125
|
+
import { inject as service } from "@ember/service";
|
|
126
|
+
|
|
127
|
+
export default class LoginComponent extends Component {
|
|
128
|
+
@service wexioWidget;
|
|
129
|
+
|
|
130
|
+
@action onLogin(token, user) {
|
|
131
|
+
this.wexioWidget.identify({ jwt: token, name: user.name, email: user.email });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@action onLogout() {
|
|
135
|
+
this.wexioWidget.shutdown();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Service API:
|
|
141
|
+
|
|
142
|
+
| Method | Effect |
|
|
143
|
+
| ------------------------------- | --------------------------------------------------------------------- |
|
|
144
|
+
| `identify(user \| null)` | Log a known user in / out (`null` logs out). |
|
|
145
|
+
| `prefill({ name, email, phone })` | Update unverified prechat prefill (via global `window.Wexio()` API). |
|
|
146
|
+
| `show()` | Show the widget panel. |
|
|
147
|
+
| `hide()` | Hide the widget panel. |
|
|
148
|
+
| `shutdown()` | Clear identity (log out). |
|
|
149
|
+
|
|
150
|
+
## Types
|
|
151
|
+
|
|
152
|
+
### VisitorIdentity
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
interface VisitorIdentity {
|
|
156
|
+
googleIdToken?: string; // Google FedCM id_token (preferred)
|
|
157
|
+
jwt?: string; // Host-signed JWT
|
|
158
|
+
userId?: string; // Legacy HMAC pair…
|
|
159
|
+
userHash?: string; // …(HMAC-SHA256(userId, integrationSecret))
|
|
160
|
+
name?: string;
|
|
161
|
+
email?: string;
|
|
162
|
+
phone?: string;
|
|
163
|
+
attributes?: Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### VisitorPrefill
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
interface VisitorPrefill {
|
|
171
|
+
name?: string;
|
|
172
|
+
email?: string;
|
|
173
|
+
phone?: string;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Browser support
|
|
178
|
+
|
|
179
|
+
Modern evergreen browsers — anything that supports Shadow DOM and ES2020. Internet Explorer is not supported.
|
|
180
|
+
|
|
181
|
+
## Use with other frameworks
|
|
182
|
+
|
|
183
|
+
The underlying widget runtime is a Web Component, so it works in any modern framework:
|
|
184
|
+
|
|
185
|
+
- [`@wexio/messenger-widget-react`](https://www.npmjs.com/package/@wexio/messenger-widget-react) — React
|
|
186
|
+
- [`@wexio/messenger-widget-vue`](https://www.npmjs.com/package/@wexio/messenger-widget-vue) — Vue 3
|
|
187
|
+
- [`@wexio/messenger-widget-angular`](https://www.npmjs.com/package/@wexio/messenger-widget-angular) — Angular
|
|
188
|
+
|
|
189
|
+
## Author
|
|
190
|
+
|
|
191
|
+
👤 **Wexio** ([https://wexio.io](https://wexio.io))
|
|
192
|
+
|
|
193
|
+
## Show your support
|
|
194
|
+
|
|
195
|
+
Give a ⭐️ if this package helped you!
|
|
196
|
+
|
|
197
|
+
## 📝 License
|
|
198
|
+
|
|
199
|
+
This project is [MIT](./LICENSE) licensed.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
_Created with ❤️ by [Wexio](https://wexio.io)_
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Known-user identity proof. Provide ONE of `googleIdToken`, `jwt`,
|
|
2
|
+
* or the legacy `userId` + `userHash` pair. */
|
|
3
|
+
export interface VisitorIdentity {
|
|
4
|
+
googleIdToken?: string;
|
|
5
|
+
jwt?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
userHash?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
email?: string;
|
|
10
|
+
phone?: string;
|
|
11
|
+
attributes?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Unverified prechat prefill values. */
|
|
15
|
+
export interface VisitorPrefill {
|
|
16
|
+
name?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
phone?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Optional helper that wraps the underlying `<wexio-widget>` element's
|
|
23
|
+
* imperative API. Register as an Ember service:
|
|
24
|
+
*
|
|
25
|
+
* // app/services/wexio-widget.js
|
|
26
|
+
* import { WexioWidgetService } from "@wexio/messenger-widget-ember";
|
|
27
|
+
* export default class extends WexioWidgetService {}
|
|
28
|
+
*/
|
|
29
|
+
export declare class WexioWidgetService {
|
|
30
|
+
/** First `<wexio-widget>` element in the document, or `null`. */
|
|
31
|
+
readonly element: HTMLElement | null;
|
|
32
|
+
|
|
33
|
+
/** Log a known user in. Pass `null` to log out. */
|
|
34
|
+
identify(user: VisitorIdentity | null): void;
|
|
35
|
+
|
|
36
|
+
/** Update unverified prechat prefill values. */
|
|
37
|
+
prefill(values: VisitorPrefill): void;
|
|
38
|
+
|
|
39
|
+
/** Show the widget panel. */
|
|
40
|
+
show(): void;
|
|
41
|
+
|
|
42
|
+
/** Hide the widget panel. */
|
|
43
|
+
hide(): void;
|
|
44
|
+
|
|
45
|
+
/** Clear identity (log out). */
|
|
46
|
+
shutdown(): void;
|
|
47
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@wexio/messenger-widget-ember` — Ember integration for the Wexio
|
|
3
|
+
* web messenger.
|
|
4
|
+
*
|
|
5
|
+
* Importing this module SIDE-EFFECT registers `<wexio-widget>` as a
|
|
6
|
+
* global custom element. Ember 4+/Glimmer renders unknown HTML tags as
|
|
7
|
+
* native DOM elements, so once the element is registered you can use
|
|
8
|
+
* `<wexio-widget>` directly in any `.hbs` template — no Ember
|
|
9
|
+
* component wrapper required.
|
|
10
|
+
*
|
|
11
|
+
* // app/routes/application.js (or any module loaded at app boot)
|
|
12
|
+
* import "@wexio/messenger-widget-ember";
|
|
13
|
+
*
|
|
14
|
+
* // app/templates/application.hbs
|
|
15
|
+
* <wexio-widget
|
|
16
|
+
* public-key="pk_live_..."
|
|
17
|
+
* {{on "wexio:resize" this.onResize}}
|
|
18
|
+
* {{on "wexio:close" this.onClose}}
|
|
19
|
+
* ></wexio-widget>
|
|
20
|
+
*
|
|
21
|
+
* For imperative identity / prefill control, the package also exports
|
|
22
|
+
* a `WexioWidgetService` class consumers can register as an Ember
|
|
23
|
+
* service. It wraps the underlying element's `identify()` method and
|
|
24
|
+
* the global `window.Wexio()` helper for prefill / show / hide.
|
|
25
|
+
*
|
|
26
|
+
* The wrapper is intentionally thin — Ember's template engine handles
|
|
27
|
+
* attribute binding + event handlers natively, so a heavyweight
|
|
28
|
+
* addon-style component would add boilerplate without value. If you
|
|
29
|
+
* need richer integration (auto-injection of identity from an
|
|
30
|
+
* `@service session`, lifecycle hooks for engine transitions, etc.)
|
|
31
|
+
* build it on top of this in your app's services layer.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import "./widget.js";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Optional service helper. Register in your Ember app as:
|
|
38
|
+
*
|
|
39
|
+
* // app/services/wexio-widget.js
|
|
40
|
+
* import { WexioWidgetService } from "@wexio/messenger-widget-ember";
|
|
41
|
+
* export default class extends WexioWidgetService {}
|
|
42
|
+
*
|
|
43
|
+
* Then inject anywhere:
|
|
44
|
+
*
|
|
45
|
+
* import { service } from "@ember/service";
|
|
46
|
+
* export default class FooComponent extends Component {
|
|
47
|
+
* @service wexioWidget;
|
|
48
|
+
* @action login() {
|
|
49
|
+
* this.wexioWidget.identify({ jwt: this.session.jwt });
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
*/
|
|
53
|
+
export class WexioWidgetService {
|
|
54
|
+
/** Returns the first `<wexio-widget>` element in the document, or
|
|
55
|
+
* `null` if none mounted. */
|
|
56
|
+
get element() {
|
|
57
|
+
if (typeof document === "undefined") return null;
|
|
58
|
+
return document.querySelector("wexio-widget");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Log a known user in. Pass `null` to log out. */
|
|
62
|
+
identify(user) {
|
|
63
|
+
this.element?.identify?.(user ?? null);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Update unverified prechat prefill values via the global
|
|
67
|
+
* `window.Wexio()` API. No-op when no widget is mounted. */
|
|
68
|
+
prefill(values) {
|
|
69
|
+
if (typeof window === "undefined") return;
|
|
70
|
+
window.Wexio?.("prefill", values);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Show the widget panel. */
|
|
74
|
+
show() {
|
|
75
|
+
if (typeof window === "undefined") return;
|
|
76
|
+
window.Wexio?.("show");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Hide the widget panel. */
|
|
80
|
+
hide() {
|
|
81
|
+
if (typeof window === "undefined") return;
|
|
82
|
+
window.Wexio?.("hide");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Clear identity (log out). */
|
|
86
|
+
shutdown() {
|
|
87
|
+
if (typeof window === "undefined") return;
|
|
88
|
+
window.Wexio?.("shutdown");
|
|
89
|
+
}
|
|
90
|
+
}
|