@skippr/live-agent-sdk 0.9.0 → 0.10.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 +10 -4
- package/dist/esm/lib-exports.js +16 -9
- package/dist/skippr-sdk.js +52 -52
- package/dist/types/components/LiveAgent.d.ts +3 -3
- package/dist/types/hooks/useSession.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,9 +17,14 @@ import { LiveAgent } from '@skippr/live-agent-sdk';
|
|
|
17
17
|
import '@skippr/live-agent-sdk/styles';
|
|
18
18
|
|
|
19
19
|
function App() {
|
|
20
|
-
return
|
|
20
|
+
return (
|
|
21
|
+
<LiveAgent
|
|
22
|
+
agentId="your_agent_id"
|
|
23
|
+
appKey="pk_live_your_key"
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
|
|
23
28
|
|
|
24
29
|
## Custom Components
|
|
25
30
|
|
|
@@ -37,7 +42,7 @@ function ConnectionStatus() {
|
|
|
37
42
|
|
|
38
43
|
function App() {
|
|
39
44
|
return (
|
|
40
|
-
<LiveAgent
|
|
45
|
+
<LiveAgent agentId="your_agent_id" appKey="pk_live_your_key">
|
|
41
46
|
<ConnectionStatus />
|
|
42
47
|
</LiveAgent>
|
|
43
48
|
);
|
|
@@ -54,8 +59,9 @@ Self-contained widget component. Renders a floating button that opens a sidebar
|
|
|
54
59
|
|
|
55
60
|
| Prop | Type | Default | Description |
|
|
56
61
|
|------|------|---------|-------------|
|
|
57
|
-
| `organizationId` | `string` | *required* | Organization ID provided by Skippr |
|
|
58
62
|
| `agentId` | `string` | *required* | Agent ID provided by Skippr |
|
|
63
|
+
| `appKey` | `string` | — | Publishable App Key from the admin dashboard |
|
|
64
|
+
| `authToken` | `string` | — | Bearer token for authenticated users |
|
|
59
65
|
| `defaultOpen` | `boolean` | `false` | Whether the panel starts open |
|
|
60
66
|
|
|
61
67
|
---
|
package/dist/esm/lib-exports.js
CHANGED
|
@@ -9,7 +9,14 @@ var LiveAgentContext = createContext(null);
|
|
|
9
9
|
// src/hooks/useSession.ts
|
|
10
10
|
import { useCallback, useState } from "react";
|
|
11
11
|
var API_URL = "https://skipprapi-production.up.railway.app";
|
|
12
|
-
function
|
|
12
|
+
function resolveAuthHeaders(authToken, appKey) {
|
|
13
|
+
if (authToken)
|
|
14
|
+
return { Authorization: `Bearer ${authToken}` };
|
|
15
|
+
if (appKey)
|
|
16
|
+
return { "X-App-Key": appKey };
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
function useSession({ agentId, authToken, appKey }) {
|
|
13
20
|
const [connection, setConnection] = useState(null);
|
|
14
21
|
const [shouldConnect, setShouldConnect] = useState(false);
|
|
15
22
|
const [isStarting, setIsStarting] = useState(false);
|
|
@@ -19,11 +26,11 @@ function useSession({ organizationId, agentId, authToken }) {
|
|
|
19
26
|
setIsStarting(true);
|
|
20
27
|
setError("");
|
|
21
28
|
try {
|
|
22
|
-
const authHeaders = authToken
|
|
29
|
+
const authHeaders = resolveAuthHeaders(authToken, appKey);
|
|
23
30
|
const createResp = await fetch(`${API_URL}/v1/sessions`, {
|
|
24
31
|
method: "POST",
|
|
25
32
|
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
26
|
-
body: JSON.stringify({
|
|
33
|
+
body: JSON.stringify({ agentId })
|
|
27
34
|
});
|
|
28
35
|
if (!createResp.ok) {
|
|
29
36
|
throw new Error(`Failed to create session: ${createResp.status}`);
|
|
@@ -48,10 +55,10 @@ function useSession({ organizationId, agentId, authToken }) {
|
|
|
48
55
|
} finally {
|
|
49
56
|
setIsStarting(false);
|
|
50
57
|
}
|
|
51
|
-
}, [
|
|
58
|
+
}, [agentId, authToken, appKey]);
|
|
52
59
|
const disconnect = useCallback(async () => {
|
|
53
60
|
if (sessionId) {
|
|
54
|
-
const authHeaders = authToken
|
|
61
|
+
const authHeaders = resolveAuthHeaders(authToken, appKey);
|
|
55
62
|
try {
|
|
56
63
|
await fetch(`${API_URL}/v1/sessions/${sessionId}/complete`, {
|
|
57
64
|
method: "POST",
|
|
@@ -64,7 +71,7 @@ function useSession({ organizationId, agentId, authToken }) {
|
|
|
64
71
|
setShouldConnect(false);
|
|
65
72
|
setConnection(null);
|
|
66
73
|
setSessionId(null);
|
|
67
|
-
}, [sessionId, authToken]);
|
|
74
|
+
}, [sessionId, authToken, appKey]);
|
|
68
75
|
return { connection, shouldConnect, isStarting, error, startSession, disconnect };
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -751,16 +758,16 @@ function SidebarTrigger() {
|
|
|
751
758
|
// src/components/LiveAgent.tsx
|
|
752
759
|
import { jsx as jsx12, jsxs as jsxs9, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
753
760
|
function LiveAgent({
|
|
754
|
-
organizationId,
|
|
755
761
|
agentId,
|
|
756
762
|
authToken,
|
|
763
|
+
appKey,
|
|
757
764
|
defaultOpen = false,
|
|
758
765
|
children
|
|
759
766
|
}) {
|
|
760
767
|
const { connection, shouldConnect, isStarting, error, startSession, disconnect } = useSession({
|
|
761
|
-
organizationId,
|
|
762
768
|
agentId,
|
|
763
|
-
authToken
|
|
769
|
+
authToken,
|
|
770
|
+
appKey
|
|
764
771
|
});
|
|
765
772
|
const [isPanelOpen, setIsPanelOpen] = useState5(defaultOpen);
|
|
766
773
|
const openPanel = useCallback5(() => setIsPanelOpen(true), []);
|