@helpway/react 0.4.0 → 0.4.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 CHANGED
@@ -1,129 +1,112 @@
1
1
  # @helpway/react
2
2
 
3
- Official React SDK for [Helpway](https://helpway.ai) — AI-powered customer support in a single component.
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
- ## Drop-in
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 RootLayout({ children }: { children: React.ReactNode }) {
18
+ export default function App() {
31
19
  return (
32
- <html>
33
- <body>
34
- {children}
35
- <HelpwayWidget apiKey="pk_live_XXXXXXXX" />
36
- </body>
37
- </html>
20
+ <>
21
+ <YourApp />
22
+ <HelpwayWidget apiKey="pk_live_xxx" />
23
+ </>
38
24
  );
39
25
  }
40
26
  ```
41
27
 
42
- ```tsx
43
- // main.tsx (Vite / CRA)
44
- import { HelpwayWidget } from "@helpway/react";
45
- import { StrictMode } from "react";
46
- import { createRoot } from "react-dom/client";
47
- import App from "./App";
48
-
49
- createRoot(document.getElementById("root")!).render(
50
- <StrictMode>
51
- <App />
52
- <HelpwayWidget apiKey="pk_live_XXXXXXXX" />
53
- </StrictMode>,
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
- The component injects the Helpway widget loader script into `document.body`, handles StrictMode double-mounts, and removes the script on unmount.
58
+ TypeScript users get full auto-complete — the package augments `Window` automatically.
58
59
 
59
- ### Props
60
+ ## Props
60
61
 
61
- | Prop | Type | Default | Description |
62
- | -------- | -------- | ------------------------------------ | --------------------------------------------- |
63
- | `apiKey` | `string` | — | Public key from the dashboard. Required. |
64
- | `src` | `string` | `https://api.helpway.ai/widget.js` | Override for staging / self-hosted setups. |
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
- ### Identifying logged-in users
74
+ ## Custom launcher
67
75
 
68
- After your user signs in, call the global `Helpway` identify function so the dashboard sees their real name and email instead of `Anonymous`:
76
+ ```tsx
77
+ <HelpwayWidget
78
+ apiKey="pk_live_xxx"
79
+ hideLauncher
80
+ customLauncherSelector="#my-btn"
81
+ />
69
82
 
70
- ```ts
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
- If you want to render your own chat UI (custom bubbles, different layout, embedded in your app instead of a floating button), use the provider + hooks:
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 ChatSurface() {
86
- const { conversations, activeConversationId, setActive } = useConversations();
87
- const { items } = useTimeline();
88
- const { draft, setDraft, send } = useComposer();
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
- export default function App() {
98
- return (
99
- <SupportProvider apiKey="pk_live_XXXXXXXX">
100
- <ChatSurface />
101
- </SupportProvider>
102
- );
103
- }
100
+ <SupportProvider apiKey="pk_live_xxx">
101
+ <Chat />
102
+ </SupportProvider>
104
103
  ```
105
104
 
106
- Exported hooks:
105
+ Available hooks: `useWidget`, `useConversations`, `useTimeline`, `useComposer`, `usePresence`, `useUnread`, `useRealtime`.
107
106
 
108
- - `useWidget()` — global state, openers/closers
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
- The headless hooks have no styles — bring your own.
109
+ Full documentation: [helpway.ai/docs](https://helpway.ai/docs)
127
110
 
128
111
  ## License
129
112
 
package/dist/index.js CHANGED
@@ -898,9 +898,6 @@ function SupportProvider({
898
898
  }
899
899
  };
900
900
  const api2 = createHelpwayAPI({ store: store2, emitter: emitter2, identify: identify2, apiKey });
901
- if (typeof window !== "undefined") {
902
- window.Helpway = api2;
903
- }
904
901
  initRef.current = { client: client2, store: store2, ws: ws2, identify: identify2, api: api2, emitter: emitter2 };
905
902
  }
906
903
  const { client, store, ws, identify, api, emitter } = initRef.current;
@@ -1060,6 +1057,8 @@ function SupportProvider({
1060
1057
  };
1061
1058
  }, [customLauncherSelector, api]);
1062
1059
  useEffect(() => {
1060
+ if (typeof window === "undefined") return;
1061
+ window.Helpway = api;
1063
1062
  return () => {
1064
1063
  if (window.Helpway === api) {
1065
1064
  window.Helpway = void 0;