@onedeskpro/chatbot-react 0.2.1 → 0.3.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/README.md CHANGED
@@ -89,7 +89,7 @@ function SupportPanel() {
89
89
 
90
90
  | Field | Description |
91
91
  | --- | --- |
92
- | `messages` | The conversation. `message.type` is `'human'` (the visitor), `'ai'`, or `'agent'` (a human agent). |
92
+ | `messages` | The conversation. `message.type` is `'human'` (the visitor), `'ai'`, or `'agent'` (a human agent). A media message carries `message.attachments` (`type`, `url`, `fileName`, `size`). |
93
93
  | `isOpen`, `isLoading`, `isReady` | Panel visibility, a request in flight, and whether the agent can answer. |
94
94
  | `needsIdentify` | `true` until the visitor has identified. `sendMessage` rejects while it is. |
95
95
  | `visitorToken`, `visitorName` | The identified visitor, or `null`. |
@@ -97,6 +97,8 @@ function SupportPanel() {
97
97
  | `blockReason`, `error` | Why the agent cannot answer (for example `server-unavailable` or `no-credits`), and the last error message. |
98
98
  | `submitIdentify({ name, phone, email? })` | Identifies the visitor and unlocks the chat. |
99
99
  | `sendMessage(text)` | Sends a message. |
100
+ | `sendAttachments(files, text?)` | Sends up to 10 files (10 MB each) as one media message, with `text` as the caption. The message appears with `pending: true` and local previews until the uploads finish. |
101
+ | `sendVoice(recording)` | Sends a voice note recorded with `VoiceRecorder` from `@onedeskpro/chatbot-core`. |
100
102
  | `requestHuman()` | Escalates to a human agent. Does nothing unless `mode` is `'ai'` and a conversation has started. |
101
103
  | `resetSession()` | Clears a `closed` conversation. Does nothing in any other mode. |
102
104
  | `open()`, `close()`, `toggle()` | Control the built-in widget's panel. |
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("@onedeskpro/chatbot-core"),u=require("react/jsx-runtime");var d=(0,c.createContext)(null);function f(){let e=(0,c.useContext)(d);if(!e)throw Error(`useChatbot must be used inside <ChatbotProvider>.`);return e}function p({children:e,...t}){let n=(0,c.useRef)(null);return n.current||=new l.ChatbotCore,(0,c.useEffect)(()=>{let e=n.current;return e.init(t).catch(e=>{console.error(`[onedeskpro-chatbot] Failed to initialise:`,e)}),()=>e.destroy()},[]),(0,u.jsx)(d.Provider,{value:n.current,children:e})}function m(){let e=f(),[t,n]=(0,c.useState)(()=>e.getState());(0,c.useEffect)(()=>{let t=e.on(`state-change`,e=>n({...e}));return n({...e.getState()}),t},[e]);let r=(0,c.useCallback)(t=>e.sendMessage(t),[e]),i=(0,c.useCallback)(t=>e.submitIdentify(t),[e]),a=(0,c.useCallback)(()=>e.requestHuman(),[e]),o=(0,c.useCallback)(()=>e.open(),[e]),s=(0,c.useCallback)(()=>e.close(),[e]),l=(0,c.useCallback)(()=>e.toggle(),[e]),u=(0,c.useCallback)(()=>e.resetSession(),[e]);return{messages:t.messages,isOpen:t.isOpen,isLoading:t.isLoading,isReady:t.isReady,needsIdentify:t.needsIdentify,blockReason:t.blockReason,error:t.error,visitorToken:t.visitorToken,visitorName:t.visitorName,mode:t.mode,sessionId:t.visitorToken,sendMessage:r,submitIdentify:i,requestHuman:a,open:o,close:s,toggle:l,resetSession:u}}function h(){let e=f();return(0,c.useEffect)(()=>{},[e]),(0,u.jsx)(`div`,{style:{display:`none`},"aria-hidden":`true`})}function g({renderLauncher:e,renderWindow:t}){let{isOpen:n,toggle:r,open:i,close:a,messages:o,sendMessage:s,isLoading:c,error:l}=m();return(0,u.jsxs)(u.Fragment,{children:[e({isOpen:n,toggle:r,open:i,close:a}),t({isOpen:n,messages:o,sendMessage:s,isLoading:c,error:l,close:a})]})}exports.ChatbotContext=d,exports.ChatbotHeadless=g,exports.ChatbotProvider=p,exports.ChatbotWidget=h,exports.useChatbot=m;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);let l=require("@onedeskpro/chatbot-core"),u=require("react/jsx-runtime");var d=(0,c.createContext)(null);function f(){let e=(0,c.useContext)(d);if(!e)throw Error(`useChatbot must be used inside <ChatbotProvider>.`);return e}function p({children:e,...t}){let n=(0,c.useRef)(null);return n.current||=new l.ChatbotCore,(0,c.useEffect)(()=>{let e=n.current;return e.init(t).catch(e=>{console.error(`[onedeskpro-chatbot] Failed to initialise:`,e)}),()=>e.destroy()},[]),(0,u.jsx)(d.Provider,{value:n.current,children:e})}function m(){let e=f(),[t,n]=(0,c.useState)(()=>e.getState());(0,c.useEffect)(()=>{let t=e.on(`state-change`,e=>n({...e}));return n({...e.getState()}),t},[e]);let r=(0,c.useCallback)(t=>e.sendMessage(t),[e]),i=(0,c.useCallback)((t,n)=>e.sendAttachments(t,n),[e]),a=(0,c.useCallback)(t=>e.sendVoice(t),[e]),o=(0,c.useCallback)(t=>e.submitIdentify(t),[e]),s=(0,c.useCallback)(()=>e.requestHuman(),[e]),l=(0,c.useCallback)(()=>e.open(),[e]),u=(0,c.useCallback)(()=>e.close(),[e]),d=(0,c.useCallback)(()=>e.toggle(),[e]),p=(0,c.useCallback)(()=>e.resetSession(),[e]);return{messages:t.messages,isOpen:t.isOpen,isLoading:t.isLoading,isReady:t.isReady,needsIdentify:t.needsIdentify,blockReason:t.blockReason,error:t.error,visitorToken:t.visitorToken,visitorName:t.visitorName,mode:t.mode,sessionId:t.visitorToken,sendMessage:r,sendAttachments:i,sendVoice:a,submitIdentify:o,requestHuman:s,open:l,close:u,toggle:d,resetSession:p}}function h(){let e=f();return(0,c.useEffect)(()=>{},[e]),(0,u.jsx)(`div`,{style:{display:`none`},"aria-hidden":`true`})}function g({renderLauncher:e,renderWindow:t}){let{isOpen:n,toggle:r,open:i,close:a,messages:o,sendMessage:s,sendAttachments:c,isLoading:l,error:d}=m();return(0,u.jsxs)(u.Fragment,{children:[e({isOpen:n,toggle:r,open:i,close:a}),t({isOpen:n,messages:o,sendMessage:s,sendAttachments:c,isLoading:l,error:d,close:a})]})}exports.ChatbotContext=d,exports.ChatbotHeadless=g,exports.ChatbotProvider=p,exports.ChatbotWidget=h,exports.useChatbot=m;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ChatAttachment } from '@onedeskpro/chatbot-types';
1
2
  import { ChatbotBlockReason } from '@onedeskpro/chatbot-types';
2
3
  import { ChatbotCore } from '@onedeskpro/chatbot-core';
3
4
  import { ChatbotEventMap } from '@onedeskpro/chatbot-types';
@@ -9,6 +10,9 @@ import { Context } from 'react';
9
10
  import { default as default_2 } from 'react';
10
11
  import { ReactNode } from 'react';
11
12
  import { TicketStatusData } from '@onedeskpro/chatbot-types';
13
+ import { VoiceRecording } from '@onedeskpro/chatbot-types';
14
+
15
+ export { ChatAttachment }
12
16
 
13
17
  export declare const ChatbotContext: Context<ChatbotCore | null>;
14
18
 
@@ -31,6 +35,7 @@ export declare interface ChatbotHeadlessProps {
31
35
  isOpen: boolean;
32
36
  messages: ReturnType<typeof useChatbot>['messages'];
33
37
  sendMessage: (text: string) => Promise<void>;
38
+ sendAttachments: (files: File[], text?: string) => Promise<void>;
34
39
  isLoading: boolean;
35
40
  error: string | null;
36
41
  close: () => void;
@@ -77,6 +82,13 @@ export declare interface UseChatbotReturn {
77
82
  /** @deprecated Use visitorToken. */
78
83
  sessionId: string | null;
79
84
  sendMessage: (text: string) => Promise<void>;
85
+ /**
86
+ * Sends files as one media message, with `text` as the caption. The message shows
87
+ * up in `messages` with `pending: true` and local previews until the uploads land.
88
+ */
89
+ sendAttachments: (files: File[], text?: string) => Promise<void>;
90
+ /** Sends a recorded voice note (record one with `VoiceRecorder` from `@onedeskpro/chatbot-core`). */
91
+ sendVoice: (recording: VoiceRecording) => Promise<void>;
80
92
  submitIdentify: (payload: {
81
93
  name: string;
82
94
  phone: string;
@@ -90,4 +102,6 @@ export declare interface UseChatbotReturn {
90
102
  resetSession: () => void;
91
103
  }
92
104
 
105
+ export { VoiceRecording }
106
+
93
107
  export { }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ChatAttachment } from '@onedeskpro/chatbot-types';
1
2
  import { ChatbotBlockReason } from '@onedeskpro/chatbot-types';
2
3
  import { ChatbotCore } from '@onedeskpro/chatbot-core';
3
4
  import { ChatbotEventMap } from '@onedeskpro/chatbot-types';
@@ -9,6 +10,9 @@ import { Context } from 'react';
9
10
  import { default as default_2 } from 'react';
10
11
  import { ReactNode } from 'react';
11
12
  import { TicketStatusData } from '@onedeskpro/chatbot-types';
13
+ import { VoiceRecording } from '@onedeskpro/chatbot-types';
14
+
15
+ export { ChatAttachment }
12
16
 
13
17
  export declare const ChatbotContext: Context<ChatbotCore | null>;
14
18
 
@@ -31,6 +35,7 @@ export declare interface ChatbotHeadlessProps {
31
35
  isOpen: boolean;
32
36
  messages: ReturnType<typeof useChatbot>['messages'];
33
37
  sendMessage: (text: string) => Promise<void>;
38
+ sendAttachments: (files: File[], text?: string) => Promise<void>;
34
39
  isLoading: boolean;
35
40
  error: string | null;
36
41
  close: () => void;
@@ -77,6 +82,13 @@ export declare interface UseChatbotReturn {
77
82
  /** @deprecated Use visitorToken. */
78
83
  sessionId: string | null;
79
84
  sendMessage: (text: string) => Promise<void>;
85
+ /**
86
+ * Sends files as one media message, with `text` as the caption. The message shows
87
+ * up in `messages` with `pending: true` and local previews until the uploads land.
88
+ */
89
+ sendAttachments: (files: File[], text?: string) => Promise<void>;
90
+ /** Sends a recorded voice note (record one with `VoiceRecorder` from `@onedeskpro/chatbot-core`). */
91
+ sendVoice: (recording: VoiceRecording) => Promise<void>;
80
92
  submitIdentify: (payload: {
81
93
  name: string;
82
94
  phone: string;
@@ -90,4 +102,6 @@ export declare interface UseChatbotReturn {
90
102
  resetSession: () => void;
91
103
  }
92
104
 
105
+ export { VoiceRecording }
106
+
93
107
  export { }
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ function p() {
30
30
  let t = e.on("state-change", (e) => i({ ...e }));
31
31
  return i({ ...e.getState() }), t;
32
32
  }, [e]);
33
- let o = t((t) => e.sendMessage(t), [e]), s = t((t) => e.submitIdentify(t), [e]), c = t(() => e.requestHuman(), [e]), l = t(() => e.open(), [e]), u = t(() => e.close(), [e]), f = t(() => e.toggle(), [e]), p = t(() => e.resetSession(), [e]);
33
+ let o = t((t) => e.sendMessage(t), [e]), s = t((t, n) => e.sendAttachments(t, n), [e]), c = t((t) => e.sendVoice(t), [e]), l = t((t) => e.submitIdentify(t), [e]), u = t(() => e.requestHuman(), [e]), f = t(() => e.open(), [e]), p = t(() => e.close(), [e]), m = t(() => e.toggle(), [e]), h = t(() => e.resetSession(), [e]);
34
34
  return {
35
35
  messages: n.messages,
36
36
  isOpen: n.isOpen,
@@ -44,12 +44,14 @@ function p() {
44
44
  mode: n.mode,
45
45
  sessionId: n.visitorToken,
46
46
  sendMessage: o,
47
- submitIdentify: s,
48
- requestHuman: c,
49
- open: l,
50
- close: u,
51
- toggle: f,
52
- resetSession: p
47
+ sendAttachments: s,
48
+ sendVoice: c,
49
+ submitIdentify: l,
50
+ requestHuman: u,
51
+ open: f,
52
+ close: p,
53
+ toggle: m,
54
+ resetSession: h
53
55
  };
54
56
  }
55
57
  //#endregion
@@ -62,7 +64,7 @@ function m() {
62
64
  });
63
65
  }
64
66
  function h({ renderLauncher: e, renderWindow: t }) {
65
- let { isOpen: n, toggle: r, open: i, close: a, messages: o, sendMessage: c, isLoading: u, error: d } = p();
67
+ let { isOpen: n, toggle: r, open: i, close: a, messages: o, sendMessage: c, sendAttachments: u, isLoading: d, error: f } = p();
66
68
  return /* @__PURE__ */ l(s, { children: [e({
67
69
  isOpen: n,
68
70
  toggle: r,
@@ -72,8 +74,9 @@ function h({ renderLauncher: e, renderWindow: t }) {
72
74
  isOpen: n,
73
75
  messages: o,
74
76
  sendMessage: c,
75
- isLoading: u,
76
- error: d,
77
+ sendAttachments: u,
78
+ isLoading: d,
79
+ error: f,
77
80
  close: a
78
81
  })] });
79
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onedeskpro/chatbot-react",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "React SDK for the Onedesk Pro Chatbot",
5
5
  "license": "MIT",
6
6
  "author": "Typetech IT <support@onedeskpro.com>",
@@ -50,26 +50,26 @@
50
50
  "react-dom": ">=18.0.0"
51
51
  },
52
52
  "dependencies": {
53
- "@onedeskpro/chatbot-core": "0.2.1",
54
- "@onedeskpro/chatbot-types": "0.2.1"
53
+ "@onedeskpro/chatbot-core": "0.3.0",
54
+ "@onedeskpro/chatbot-types": "0.3.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@microsoft/api-extractor": "^7.59.4",
58
58
  "@testing-library/dom": "^10.4.2",
59
59
  "@testing-library/jest-dom": "^7.0.1",
60
60
  "@testing-library/react": "^16.3.3",
61
- "@testing-library/user-event": "^14.6.7",
61
+ "@testing-library/user-event": "^14.6.8",
62
62
  "@types/react": "^19.3.0",
63
63
  "@types/react-dom": "^19.3.0",
64
64
  "@vitejs/plugin-react": "^6.1.2",
65
- "jsdom": "^30.1.2",
66
- "msw": "^2.15.0",
67
- "react": "^19.3.0",
68
- "react-dom": "^19.3.0",
65
+ "jsdom": "^30.1.3",
66
+ "msw": "^3.0.3",
67
+ "react": "^19.3.1",
68
+ "react-dom": "^19.3.1",
69
69
  "typescript": "^6",
70
70
  "vite": "^8.3.4",
71
71
  "vite-plugin-dts": "^5.1.2",
72
- "vitest": "^5.0.4"
72
+ "vitest": "^5.0.5"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "vite build && cp dist/index.d.ts dist/index.d.cts",