@helpway/react 0.4.0 → 0.4.2
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 +69 -86
- package/dist/index.d.ts +5 -4
- package/dist/index.js +79 -105
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/themed/styles.css +5 -72
package/README.md
CHANGED
|
@@ -1,129 +1,112 @@
|
|
|
1
1
|
# @helpway/react
|
|
2
2
|
|
|
3
|
-
Official React SDK for [Helpway](https://helpway.ai) — AI-powered customer support
|
|
4
|
-
|
|
5
|
-
Two integration levels in one package:
|
|
6
|
-
|
|
7
|
-
- **Drop-in**: mount `<HelpwayWidget apiKey="..." />` anywhere in your tree and you're done.
|
|
8
|
-
- **Headless**: use `SupportProvider` + hooks (`useWidget`, `useConversations`, `useTimeline`, `useComposer`) to build your own chat UI against the same realtime backend.
|
|
3
|
+
Official React SDK for [Helpway](https://helpway.ai) — AI-powered customer support widget with full programmatic control.
|
|
9
4
|
|
|
10
5
|
## Install
|
|
11
6
|
|
|
12
7
|
```bash
|
|
13
8
|
npm install @helpway/react
|
|
14
|
-
# or
|
|
15
|
-
bun add @helpway/react
|
|
16
|
-
# or
|
|
17
|
-
pnpm add @helpway/react
|
|
18
9
|
```
|
|
19
10
|
|
|
20
11
|
Peer dependencies: `react` ≥ 18 and `react-dom` ≥ 18.
|
|
21
12
|
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
Grab your public API key from the Helpway dashboard → Settings → API keys (format: `pk_live_…`).
|
|
13
|
+
## Quick start
|
|
25
14
|
|
|
26
15
|
```tsx
|
|
27
|
-
// app/layout.tsx (Next.js App Router)
|
|
28
16
|
import { HelpwayWidget } from "@helpway/react";
|
|
29
17
|
|
|
30
|
-
export default function
|
|
18
|
+
export default function App() {
|
|
31
19
|
return (
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
</body>
|
|
37
|
-
</html>
|
|
20
|
+
<>
|
|
21
|
+
<YourApp />
|
|
22
|
+
<HelpwayWidget apiKey="pk_live_xxx" />
|
|
23
|
+
</>
|
|
38
24
|
);
|
|
39
25
|
}
|
|
40
26
|
```
|
|
41
27
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
28
|
+
## Programmatic API (`window.Helpway`)
|
|
29
|
+
|
|
30
|
+
After the widget bootstraps, a type-safe global API is available:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
window.Helpway.open() // open panel
|
|
34
|
+
window.Helpway.close() // close panel
|
|
35
|
+
window.Helpway.toggle() // toggle open/close
|
|
36
|
+
window.Helpway.dismiss() // hide launcher + panel
|
|
37
|
+
window.Helpway.show() // re-show after dismiss
|
|
38
|
+
window.Helpway.shutdown() // full session reset
|
|
39
|
+
|
|
40
|
+
window.Helpway.identify({ // link visitor to contact
|
|
41
|
+
externalId: "u_123",
|
|
42
|
+
email: "jane@acme.com",
|
|
43
|
+
name: "Jane Doe",
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
window.Helpway.newConversation("Help!") // open new conversation
|
|
47
|
+
window.Helpway.openConversation("conv_abc") // open specific conversation
|
|
48
|
+
|
|
49
|
+
window.Helpway.unreadCount // getter: number
|
|
50
|
+
window.Helpway.isOpen // getter: boolean
|
|
51
|
+
|
|
52
|
+
window.Helpway.on("open", () => {}) // subscribe to events
|
|
53
|
+
window.Helpway.on("unreadChange", (n) => {})
|
|
54
|
+
window.Helpway.on("messageReceived", (msg) => {})
|
|
55
|
+
window.Helpway.off("open", handler) // unsubscribe
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
TypeScript users get full auto-complete — the package augments `Window` automatically.
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
## Props
|
|
60
61
|
|
|
61
|
-
| Prop
|
|
62
|
-
|
|
63
|
-
| `apiKey` | `string` | —
|
|
64
|
-
| `
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| `apiKey` | `string` | — | **Required.** Public key from dashboard. |
|
|
65
|
+
| `apiUrl` | `string` | `https://api.helpway.ai` | Override for staging / self-hosted. |
|
|
66
|
+
| `locale` | `string` | auto-detect | Widget language (`"en"`, `"tr"`, `"de"`…). |
|
|
67
|
+
| `hideLauncher` | `boolean` | `false` | Hide the default floating bubble. |
|
|
68
|
+
| `customLauncherSelector` | `string` | — | CSS selector for custom trigger element. |
|
|
69
|
+
| `onReady` | `(api: HelpwayAPI) => void` | — | Full API object after bootstrap. |
|
|
70
|
+
| `onOpen` | `() => void` | — | Panel opened. |
|
|
71
|
+
| `onClose` | `() => void` | — | Panel closed. |
|
|
72
|
+
| `onUnreadChange` | `(count: number) => void` | — | Unread count changed. |
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
## Custom launcher
|
|
67
75
|
|
|
68
|
-
|
|
76
|
+
```tsx
|
|
77
|
+
<HelpwayWidget
|
|
78
|
+
apiKey="pk_live_xxx"
|
|
79
|
+
hideLauncher
|
|
80
|
+
customLauncherSelector="#my-btn"
|
|
81
|
+
/>
|
|
69
82
|
|
|
70
|
-
|
|
71
|
-
window.Helpway("identify", {
|
|
72
|
-
uniqueId: user.id,
|
|
73
|
-
name: user.name,
|
|
74
|
-
email: user.email,
|
|
75
|
-
});
|
|
83
|
+
<button id="my-btn">Support</button>
|
|
76
84
|
```
|
|
77
85
|
|
|
78
|
-
## Headless
|
|
86
|
+
## Headless hooks
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
Build your own chat UI with the same realtime backend:
|
|
81
89
|
|
|
82
90
|
```tsx
|
|
83
91
|
import { SupportProvider, useConversations, useTimeline, useComposer } from "@helpway/react";
|
|
84
92
|
|
|
85
|
-
function
|
|
86
|
-
const { conversations
|
|
87
|
-
const { items } = useTimeline();
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<div>
|
|
92
|
-
{/* render conversations, messages, composer — full control */}
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
93
|
+
function Chat() {
|
|
94
|
+
const { conversations } = useConversations();
|
|
95
|
+
const { items } = useTimeline(conversations[0]?.id);
|
|
96
|
+
const { text, setText, submit } = useComposer(conversations[0]?.id);
|
|
97
|
+
// ...render your own UI
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<ChatSurface />
|
|
101
|
-
</SupportProvider>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
100
|
+
<SupportProvider apiKey="pk_live_xxx">
|
|
101
|
+
<Chat />
|
|
102
|
+
</SupportProvider>
|
|
104
103
|
```
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
Available hooks: `useWidget`, `useConversations`, `useTimeline`, `useComposer`, `usePresence`, `useUnread`, `useRealtime`.
|
|
107
106
|
|
|
108
|
-
|
|
109
|
-
- `useConversations()` — list + active conversation
|
|
110
|
-
- `useTimeline()` — messages + events for the active conversation
|
|
111
|
-
- `useComposer()` — draft state + send/attach
|
|
112
|
-
- `usePresence()` — online team members
|
|
113
|
-
- `useUnread()` — unread counts
|
|
114
|
-
- `useRealtime()` — raw WebSocket event stream
|
|
115
|
-
|
|
116
|
-
Full API docs: [helpway.ai/docs/react](https://helpway.ai/docs/react)
|
|
117
|
-
|
|
118
|
-
## Styling
|
|
119
|
-
|
|
120
|
-
The default themed widget ships opinionated styles. If you use `DefaultWidget`, pull in the stylesheet once:
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
import "@helpway/react/styles.css";
|
|
124
|
-
```
|
|
107
|
+
## Docs
|
|
125
108
|
|
|
126
|
-
|
|
109
|
+
Full documentation: [helpway.ai/docs](https://helpway.ai/docs)
|
|
127
110
|
|
|
128
111
|
## License
|
|
129
112
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as _helpway_widget_core from '@helpway/widget-core';
|
|
3
|
-
import {
|
|
3
|
+
import { HelpwayMethods, WidgetStore } from '@helpway/widget-core';
|
|
4
4
|
export { ConversationSummary, HelpwayAPI, RealtimeEvent, TimelineItem, WidgetEventName, WidgetEvents, WidgetState, WidgetStore, clearVisitorId, formatRelativeTime, formatTime, getInitials, getOrCreateVisitorId } from '@helpway/widget-core';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import react__default, { ReactNode } from 'react';
|
|
@@ -60,7 +60,7 @@ interface HelpwayWidgetProps {
|
|
|
60
60
|
src?: string;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
type HelpwayPublicAPI =
|
|
63
|
+
type HelpwayPublicAPI = HelpwayMethods;
|
|
64
64
|
/**
|
|
65
65
|
* Render this once at the root of your app (e.g. in `_app.tsx`,
|
|
66
66
|
* `layout.tsx`, or `main.tsx`). Unmounting cleanly tears down the
|
|
@@ -84,7 +84,7 @@ interface SupportProviderProps {
|
|
|
84
84
|
apiUrl?: string;
|
|
85
85
|
locale?: string;
|
|
86
86
|
initialConversationId?: string;
|
|
87
|
-
onReady?: (api:
|
|
87
|
+
onReady?: (api: HelpwayMethods) => void;
|
|
88
88
|
customLauncherSelector?: string;
|
|
89
89
|
onOpen?: () => void;
|
|
90
90
|
onClose?: () => void;
|
|
@@ -238,9 +238,10 @@ interface MessageBubbleProps {
|
|
|
238
238
|
sender: "visitor" | "team" | "ai";
|
|
239
239
|
senderName?: string;
|
|
240
240
|
parts?: TimelineItemPart[] | null;
|
|
241
|
+
timestamp?: string;
|
|
241
242
|
}
|
|
242
243
|
/** Single message bubble — Intercom-style, renders text + image/file parts */
|
|
243
|
-
declare function MessageBubble({ text, sender, senderName, parts }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
244
|
+
declare function MessageBubble({ text, sender, senderName, parts, timestamp }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
|
|
244
245
|
|
|
245
246
|
interface MessageListProps {
|
|
246
247
|
items: TimelineItem[];
|