@onedeskpro/chatbot-react 0.3.1 → 0.4.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 +12 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -50,7 +50,8 @@ function SupportPanel() {
|
|
|
50
50
|
sendMessage,
|
|
51
51
|
submitIdentify,
|
|
52
52
|
requestHuman,
|
|
53
|
-
|
|
53
|
+
cancelHumanRequest,
|
|
54
|
+
startNewConversation,
|
|
54
55
|
} = useChatbot();
|
|
55
56
|
|
|
56
57
|
if (!isReady) return null;
|
|
@@ -74,12 +75,18 @@ function SupportPanel() {
|
|
|
74
75
|
{m.message.type}: {m.message.content}
|
|
75
76
|
</p>
|
|
76
77
|
))}
|
|
77
|
-
{mode === 'waiting' &&
|
|
78
|
+
{mode === 'waiting' && (
|
|
79
|
+
<p>
|
|
80
|
+
Waiting for a human agent… <button onClick={cancelHumanRequest}>Cancel request</button>
|
|
81
|
+
</p>
|
|
82
|
+
)}
|
|
78
83
|
<button onClick={() => sendMessage('Hello')} disabled={isLoading || mode === 'closed'}>
|
|
79
84
|
Send
|
|
80
85
|
</button>
|
|
81
86
|
{mode === 'ai' && <button onClick={requestHuman}>Talk to a person</button>}
|
|
82
|
-
|
|
87
|
+
<button onClick={startNewConversation} disabled={isLoading}>
|
|
88
|
+
New conversation
|
|
89
|
+
</button>
|
|
83
90
|
</div>
|
|
84
91
|
);
|
|
85
92
|
}
|
|
@@ -100,6 +107,8 @@ function SupportPanel() {
|
|
|
100
107
|
| `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
108
|
| `sendVoice(recording)` | Sends a voice note recorded with `VoiceRecorder` from `@onedeskpro/chatbot-core`. |
|
|
102
109
|
| `requestHuman()` | Escalates to a human agent. Does nothing unless `mode` is `'ai'` and a conversation has started. |
|
|
110
|
+
| `cancelHumanRequest()` | Withdraws a pending human request so the AI answers again. Does nothing unless `mode` is `'waiting'`. |
|
|
111
|
+
| `startNewConversation()` | Ends the current conversation in any mode and starts a fresh one; `messages` is cleared and `mode` returns to `'ai'`. |
|
|
103
112
|
| `resetSession()` | Clears a `closed` conversation. Does nothing in any other mode. |
|
|
104
113
|
| `open()`, `close()`, `toggle()` | Control the built-in widget's panel. |
|
|
105
114
|
| `sessionId` | Deprecated alias of `visitorToken`. |
|
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,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.
|
|
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.cancelHumanRequest(),[e]),u=(0,c.useCallback)(()=>e.startNewConversation(),[e]),d=(0,c.useCallback)(()=>e.open(),[e]),p=(0,c.useCallback)(()=>e.close(),[e]),m=(0,c.useCallback)(()=>e.toggle(),[e]),h=(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,cancelHumanRequest:l,startNewConversation:u,open:d,close:p,toggle:m,resetSession:h}}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
|
@@ -96,6 +96,10 @@ export declare interface UseChatbotReturn {
|
|
|
96
96
|
}) => Promise<void>;
|
|
97
97
|
/** Escalate the open AI ticket to a human agent (no-op unless mode is `ai`). */
|
|
98
98
|
requestHuman: () => Promise<void>;
|
|
99
|
+
/** Withdraw a pending human request so the AI answers again (no-op unless mode is `waiting`). */
|
|
100
|
+
cancelHumanRequest: () => Promise<void>;
|
|
101
|
+
/** End the current conversation in any mode and start a fresh one (clears `messages`). */
|
|
102
|
+
startNewConversation: () => Promise<void>;
|
|
99
103
|
open: () => void;
|
|
100
104
|
close: () => void;
|
|
101
105
|
toggle: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,10 @@ export declare interface UseChatbotReturn {
|
|
|
96
96
|
}) => Promise<void>;
|
|
97
97
|
/** Escalate the open AI ticket to a human agent (no-op unless mode is `ai`). */
|
|
98
98
|
requestHuman: () => Promise<void>;
|
|
99
|
+
/** Withdraw a pending human request so the AI answers again (no-op unless mode is `waiting`). */
|
|
100
|
+
cancelHumanRequest: () => Promise<void>;
|
|
101
|
+
/** End the current conversation in any mode and start a fresh one (clears `messages`). */
|
|
102
|
+
startNewConversation: () => Promise<void>;
|
|
99
103
|
open: () => void;
|
|
100
104
|
close: () => void;
|
|
101
105
|
toggle: () => void;
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function p() {
|
|
|
28
28
|
let t = e.on("state-change", (e) => i({ ...e }));
|
|
29
29
|
return i({ ...e.getState() }), t;
|
|
30
30
|
}, [e]);
|
|
31
|
-
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.
|
|
31
|
+
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.cancelHumanRequest(), [e]), p = t(() => e.startNewConversation(), [e]), m = t(() => e.open(), [e]), h = t(() => e.close(), [e]), g = t(() => e.toggle(), [e]), _ = t(() => e.resetSession(), [e]);
|
|
32
32
|
return {
|
|
33
33
|
messages: n.messages,
|
|
34
34
|
isOpen: n.isOpen,
|
|
@@ -46,10 +46,12 @@ function p() {
|
|
|
46
46
|
sendVoice: c,
|
|
47
47
|
submitIdentify: l,
|
|
48
48
|
requestHuman: u,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
cancelHumanRequest: f,
|
|
50
|
+
startNewConversation: p,
|
|
51
|
+
open: m,
|
|
52
|
+
close: h,
|
|
53
|
+
toggle: g,
|
|
54
|
+
resetSession: _
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
// src/chatbot-widget.tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onedeskpro/chatbot-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React SDK for the Onedesk Pro Chatbot",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Typetech IT <support@onedeskpro.com>",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"react-dom": ">=18.0.0"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@onedeskpro/chatbot-core": "0.
|
|
54
|
-
"@onedeskpro/chatbot-types": "0.
|
|
53
|
+
"@onedeskpro/chatbot-core": "0.4.0",
|
|
54
|
+
"@onedeskpro/chatbot-types": "0.4.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@microsoft/api-extractor": "^7.
|
|
57
|
+
"@microsoft/api-extractor": "^7.60.0",
|
|
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",
|