@onedeskpro/chatbot-react 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Typetech IT
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,70 @@
1
+ # @onedeskpro/chatbot-react
2
+
3
+ React SDK for the [Onedesk Pro](https://onedeskpro.com) chatbot. Wraps [`@onedeskpro/chatbot-core`](https://www.npmjs.com/package/@onedeskpro/chatbot-core) in a provider, a drop-in widget, and a `useChatbot` hook for fully custom UI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @onedeskpro/chatbot-react
9
+ ```
10
+
11
+ Requires React 18 or later as a peer dependency.
12
+
13
+ ## Usage
14
+
15
+ Wrap your app in `ChatbotProvider` and render `ChatbotWidget`:
16
+
17
+ ```tsx
18
+ import { ChatbotProvider, ChatbotWidget } from '@onedeskpro/chatbot-react';
19
+
20
+ export default function App() {
21
+ return (
22
+ <ChatbotProvider apiKey="your-onedesk-pro-api-key" theme="auto">
23
+ <YourApp />
24
+ <ChatbotWidget />
25
+ </ChatbotProvider>
26
+ );
27
+ }
28
+ ```
29
+
30
+ `ChatbotProvider` accepts every `ChatbotInitOptions` field as a prop — `apiKey`, `apiBaseUrl`, `chatbotName`, `primaryColor`, `theme`, `position`, `welcomeMessage`, `placeholder`, `autoOpen`, `sessionId`. Only `apiKey` is required.
31
+
32
+ The components are client-side; in Next.js App Router they carry `'use client'` already, so importing them from a server component is fine as long as the provider itself renders on the client.
33
+
34
+ ## Custom UI
35
+
36
+ `useChatbot` gives you the whole conversation state and controls:
37
+
38
+ ```tsx
39
+ import { useChatbot } from '@onedeskpro/chatbot-react';
40
+
41
+ function SupportPanel() {
42
+ const { messages, isLoading, isReady, sendMessage, resetSession } = useChatbot();
43
+
44
+ if (!isReady) return null;
45
+
46
+ return (
47
+ <div>
48
+ {messages.map((m) => (
49
+ <p key={m.id}>{m.message.content}</p>
50
+ ))}
51
+ <button onClick={() => sendMessage('Hello')} disabled={isLoading}>
52
+ Send
53
+ </button>
54
+ <button onClick={resetSession}>New conversation</button>
55
+ </div>
56
+ );
57
+ }
58
+ ```
59
+
60
+ `useChatbot` returns `messages`, `isOpen`, `isLoading`, `isReady`, `blockReason`, `error`, `sessionId`, `sendMessage`, `open`, `close`, `toggle`, and `resetSession`.
61
+
62
+ For custom chrome around the built-in behavior, `ChatbotHeadless` takes `renderLauncher` and `renderWindow` render props instead of shipping any markup of its own.
63
+
64
+ ## Exports
65
+
66
+ `ChatbotProvider`, `ChatbotWidget`, `ChatbotHeadless`, `useChatbot`, `ChatbotContext`, plus the `ChatbotInitOptions`, `ChatbotState`, `ChatMessage`, and `ChatbotEventMap` types.
67
+
68
+ ## License
69
+
70
+ MIT © Typetech IT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),t=require("react"),h=require("@onedeskpro/chatbot-core"),b=t.createContext(null);function C(){const e=t.useContext(b);if(!e)throw new Error("useChatbot must be used inside <ChatbotProvider>.");return e}function f({children:e,...s}){const n=t.useRef(null);return n.current||(n.current=new h.ChatbotCore),t.useEffect(()=>{const o=n.current;return o.init(s).catch(r=>{console.error("[onedeskpro-chatbot] Failed to initialise:",r)}),()=>o.destroy()},[]),i.jsx(b.Provider,{value:n.current,children:e})}function g(){const e=C(),[s,n]=t.useState(()=>e.getState());t.useEffect(()=>{const a=e.on("state-change",d=>n({...d}));return n({...e.getState()}),a},[e]);const o=t.useCallback(a=>e.sendMessage(a),[e]),r=t.useCallback(()=>e.open(),[e]),c=t.useCallback(()=>e.close(),[e]),u=t.useCallback(()=>e.toggle(),[e]),l=t.useCallback(()=>e.resetSession(),[e]);return{messages:s.messages,isOpen:s.isOpen,isLoading:s.isLoading,isReady:s.isReady,blockReason:s.blockReason,error:s.error,sessionId:s.sessionId,sendMessage:o,open:r,close:c,toggle:u,resetSession:l}}function x(){const e=C();return t.useEffect(()=>{},[e]),i.jsx("div",{style:{display:"none"},"aria-hidden":"true"})}function p({renderLauncher:e,renderWindow:s}){const{isOpen:n,toggle:o,open:r,close:c,messages:u,sendMessage:l,isLoading:a,error:d}=g();return i.jsxs(i.Fragment,{children:[e({isOpen:n,toggle:o,open:r,close:c}),s({isOpen:n,messages:u,sendMessage:l,isLoading:a,error:d,close:c})]})}exports.ChatbotContext=b;exports.ChatbotHeadless=p;exports.ChatbotProvider=f;exports.ChatbotWidget=x;exports.useChatbot=g;
@@ -0,0 +1,74 @@
1
+ import { ChatbotBlockReason } from '@onedeskpro/chatbot-types';
2
+ import { ChatbotCore } from '@onedeskpro/chatbot-core';
3
+ import { ChatbotEventMap } from '@onedeskpro/chatbot-types';
4
+ import { ChatbotInitOptions } from '@onedeskpro/chatbot-types';
5
+ import { ChatbotState } from '@onedeskpro/chatbot-types';
6
+ import { ChatMessage } from '@onedeskpro/chatbot-types';
7
+ import { Context } from 'react';
8
+ import { default as default_2 } from 'react';
9
+ import { ReactNode } from 'react';
10
+
11
+ export declare const ChatbotContext: Context<ChatbotCore | null>;
12
+
13
+ export { ChatbotEventMap }
14
+
15
+ /**
16
+ * Headless variant — no built-in UI. Supply your own launcher and chat window
17
+ * via render props. All state comes from useChatbot() internally.
18
+ */
19
+ export declare function ChatbotHeadless({ renderLauncher, renderWindow }: ChatbotHeadlessProps): default_2.JSX.Element;
20
+
21
+ export declare interface ChatbotHeadlessProps {
22
+ renderLauncher: (props: {
23
+ isOpen: boolean;
24
+ toggle: () => void;
25
+ open: () => void;
26
+ close: () => void;
27
+ }) => ReactNode;
28
+ renderWindow: (props: {
29
+ isOpen: boolean;
30
+ messages: ReturnType<typeof useChatbot>['messages'];
31
+ sendMessage: (text: string) => Promise<void>;
32
+ isLoading: boolean;
33
+ error: string | null;
34
+ close: () => void;
35
+ }) => ReactNode;
36
+ }
37
+
38
+ export { ChatbotInitOptions }
39
+
40
+ export declare function ChatbotProvider({ children, ...options }: ChatbotProviderProps): default_2.JSX.Element;
41
+
42
+ export declare type ChatbotProviderProps = ChatbotInitOptions & {
43
+ children: ReactNode;
44
+ };
45
+
46
+ export { ChatbotState }
47
+
48
+ /**
49
+ * Default floating widget — delegates rendering to the core Shadow DOM widget
50
+ * that ChatbotCore.init() mounts into document.body. This component just
51
+ * ensures the provider is in scope; the actual UI lives outside React's tree.
52
+ */
53
+ export declare function ChatbotWidget(): default_2.JSX.Element;
54
+
55
+ export { ChatMessage }
56
+
57
+ export declare function useChatbot(): UseChatbotReturn;
58
+
59
+ export declare interface UseChatbotReturn {
60
+ messages: ChatMessage[];
61
+ isOpen: boolean;
62
+ isLoading: boolean;
63
+ isReady: boolean;
64
+ blockReason: ChatbotBlockReason;
65
+ error: string | null;
66
+ sessionId: string | null;
67
+ sendMessage: (text: string) => Promise<void>;
68
+ open: () => void;
69
+ close: () => void;
70
+ toggle: () => void;
71
+ resetSession: () => void;
72
+ }
73
+
74
+ export { }
@@ -0,0 +1,74 @@
1
+ import { ChatbotBlockReason } from '@onedeskpro/chatbot-types';
2
+ import { ChatbotCore } from '@onedeskpro/chatbot-core';
3
+ import { ChatbotEventMap } from '@onedeskpro/chatbot-types';
4
+ import { ChatbotInitOptions } from '@onedeskpro/chatbot-types';
5
+ import { ChatbotState } from '@onedeskpro/chatbot-types';
6
+ import { ChatMessage } from '@onedeskpro/chatbot-types';
7
+ import { Context } from 'react';
8
+ import { default as default_2 } from 'react';
9
+ import { ReactNode } from 'react';
10
+
11
+ export declare const ChatbotContext: Context<ChatbotCore | null>;
12
+
13
+ export { ChatbotEventMap }
14
+
15
+ /**
16
+ * Headless variant — no built-in UI. Supply your own launcher and chat window
17
+ * via render props. All state comes from useChatbot() internally.
18
+ */
19
+ export declare function ChatbotHeadless({ renderLauncher, renderWindow }: ChatbotHeadlessProps): default_2.JSX.Element;
20
+
21
+ export declare interface ChatbotHeadlessProps {
22
+ renderLauncher: (props: {
23
+ isOpen: boolean;
24
+ toggle: () => void;
25
+ open: () => void;
26
+ close: () => void;
27
+ }) => ReactNode;
28
+ renderWindow: (props: {
29
+ isOpen: boolean;
30
+ messages: ReturnType<typeof useChatbot>['messages'];
31
+ sendMessage: (text: string) => Promise<void>;
32
+ isLoading: boolean;
33
+ error: string | null;
34
+ close: () => void;
35
+ }) => ReactNode;
36
+ }
37
+
38
+ export { ChatbotInitOptions }
39
+
40
+ export declare function ChatbotProvider({ children, ...options }: ChatbotProviderProps): default_2.JSX.Element;
41
+
42
+ export declare type ChatbotProviderProps = ChatbotInitOptions & {
43
+ children: ReactNode;
44
+ };
45
+
46
+ export { ChatbotState }
47
+
48
+ /**
49
+ * Default floating widget — delegates rendering to the core Shadow DOM widget
50
+ * that ChatbotCore.init() mounts into document.body. This component just
51
+ * ensures the provider is in scope; the actual UI lives outside React's tree.
52
+ */
53
+ export declare function ChatbotWidget(): default_2.JSX.Element;
54
+
55
+ export { ChatMessage }
56
+
57
+ export declare function useChatbot(): UseChatbotReturn;
58
+
59
+ export declare interface UseChatbotReturn {
60
+ messages: ChatMessage[];
61
+ isOpen: boolean;
62
+ isLoading: boolean;
63
+ isReady: boolean;
64
+ blockReason: ChatbotBlockReason;
65
+ error: string | null;
66
+ sessionId: string | null;
67
+ sendMessage: (text: string) => Promise<void>;
68
+ open: () => void;
69
+ close: () => void;
70
+ toggle: () => void;
71
+ resetSession: () => void;
72
+ }
73
+
74
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import { jsx as g, jsxs as C, Fragment as b } from "react/jsx-runtime";
2
+ import { createContext as p, useContext as m, useRef as x, useEffect as l, useState as R, useCallback as i } from "react";
3
+ import { ChatbotCore as S } from "@onedeskpro/chatbot-core";
4
+ const f = p(null);
5
+ function h() {
6
+ const e = m(f);
7
+ if (!e) throw new Error("useChatbot must be used inside <ChatbotProvider>.");
8
+ return e;
9
+ }
10
+ function L({ children: e, ...t }) {
11
+ const s = x(null);
12
+ return s.current || (s.current = new S()), l(() => {
13
+ const n = s.current;
14
+ return n.init(t).catch((o) => {
15
+ console.error("[onedeskpro-chatbot] Failed to initialise:", o);
16
+ }), () => n.destroy();
17
+ }, []), /* @__PURE__ */ g(f.Provider, { value: s.current, children: e });
18
+ }
19
+ function v() {
20
+ const e = h(), [t, s] = R(() => e.getState());
21
+ l(() => {
22
+ const r = e.on("state-change", (d) => s({ ...d }));
23
+ return s({ ...e.getState() }), r;
24
+ }, [e]);
25
+ const n = i(
26
+ (r) => e.sendMessage(r),
27
+ [e]
28
+ ), o = i(() => e.open(), [e]), a = i(() => e.close(), [e]), c = i(() => e.toggle(), [e]), u = i(() => e.resetSession(), [e]);
29
+ return {
30
+ messages: t.messages,
31
+ isOpen: t.isOpen,
32
+ isLoading: t.isLoading,
33
+ isReady: t.isReady,
34
+ blockReason: t.blockReason,
35
+ error: t.error,
36
+ sessionId: t.sessionId,
37
+ sendMessage: n,
38
+ open: o,
39
+ close: a,
40
+ toggle: c,
41
+ resetSession: u
42
+ };
43
+ }
44
+ function M() {
45
+ const e = h();
46
+ return l(() => {
47
+ }, [e]), /* @__PURE__ */ g("div", { style: { display: "none" }, "aria-hidden": "true" });
48
+ }
49
+ function O({ renderLauncher: e, renderWindow: t }) {
50
+ const { isOpen: s, toggle: n, open: o, close: a, messages: c, sendMessage: u, isLoading: r, error: d } = v();
51
+ return /* @__PURE__ */ C(b, { children: [
52
+ e({ isOpen: s, toggle: n, open: o, close: a }),
53
+ t({ isOpen: s, messages: c, sendMessage: u, isLoading: r, error: d, close: a })
54
+ ] });
55
+ }
56
+ export {
57
+ f as ChatbotContext,
58
+ O as ChatbotHeadless,
59
+ L as ChatbotProvider,
60
+ M as ChatbotWidget,
61
+ v as useChatbot
62
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@onedeskpro/chatbot-react",
3
+ "version": "0.1.0",
4
+ "description": "React SDK for the Onedesk Pro Chatbot",
5
+ "license": "MIT",
6
+ "author": "Typetech IT <support@onedeskpro.com>",
7
+ "homepage": "https://github.com/onedeskpro/onedeskpro-chatbot-sdk#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/onedeskpro/onedeskpro-chatbot-sdk.git",
11
+ "directory": "packages/react"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/onedeskpro/onedeskpro-chatbot-sdk/issues"
15
+ },
16
+ "keywords": [
17
+ "onedeskpro",
18
+ "chatbot",
19
+ "react",
20
+ "chat-widget",
21
+ "customer-support",
22
+ "sdk"
23
+ ],
24
+ "sideEffects": false,
25
+ "type": "module",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "react": ">=18.0.0",
50
+ "react-dom": ">=18.0.0"
51
+ },
52
+ "dependencies": {
53
+ "@onedeskpro/chatbot-core": "0.1.0",
54
+ "@onedeskpro/chatbot-types": "0.1.0"
55
+ },
56
+ "devDependencies": {
57
+ "@testing-library/dom": "^10",
58
+ "@testing-library/jest-dom": "^6",
59
+ "@testing-library/react": "^16",
60
+ "@types/react": "^18.0.0",
61
+ "@types/react-dom": "^18.0.0",
62
+ "@vitejs/plugin-react": "^4.0.0",
63
+ "jsdom": "^25",
64
+ "react": "^18.0.0",
65
+ "react-dom": "^18.0.0",
66
+ "typescript": "^5.5.0",
67
+ "vite": "^5.0.0",
68
+ "vite-plugin-dts": "^4.0.0",
69
+ "vitest": "^2"
70
+ },
71
+ "scripts": {
72
+ "build": "vite build && cp dist/index.d.ts dist/index.d.cts",
73
+ "test": "vitest run",
74
+ "dev": "vite build --watch",
75
+ "type-check": "tsc --noEmit",
76
+ "clean": "rm -rf dist"
77
+ }
78
+ }