tevrocsdk 0.1.72 → 0.1.73
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/package.json +1 -1
- package/tevroc-sdk.cjs.js +87 -4
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +87 -4
- package/tevroc-sdk.esm.js.map +4 -4
package/package.json
CHANGED
package/tevroc-sdk.cjs.js
CHANGED
|
@@ -47266,6 +47266,15 @@ function createAgentNotificationService(client) {
|
|
|
47266
47266
|
connection.publish({ type: "chat_message", sessionId, session_id: sessionId, message: payload, payload });
|
|
47267
47267
|
setTimeout(() => connection.close(), 1e3);
|
|
47268
47268
|
};
|
|
47269
|
+
const publishStatus = (sessionId, status, session) => publish(sessionId, {
|
|
47270
|
+
id: `status_${status}_${Date.now()}`,
|
|
47271
|
+
type: "chat_status",
|
|
47272
|
+
status,
|
|
47273
|
+
sessionId,
|
|
47274
|
+
session_id: sessionId,
|
|
47275
|
+
visitor_name: session?.visitor_name || "",
|
|
47276
|
+
createdAt: Date.now()
|
|
47277
|
+
});
|
|
47269
47278
|
const accept = async (session) => {
|
|
47270
47279
|
const sessionId = getSessionId(session);
|
|
47271
47280
|
await client.entities.ChatSession.update(session.id, {
|
|
@@ -47273,11 +47282,13 @@ function createAgentNotificationService(client) {
|
|
|
47273
47282
|
agent_email: client.agentIdentity || "agent",
|
|
47274
47283
|
updatedAt: Date.now()
|
|
47275
47284
|
});
|
|
47285
|
+
publishStatus(sessionId, "agent_active", session);
|
|
47276
47286
|
notify({ type: "accepted", sessionId, session });
|
|
47277
47287
|
};
|
|
47278
47288
|
const reject = async (session) => {
|
|
47279
47289
|
const sessionId = getSessionId(session);
|
|
47280
47290
|
await client.entities.ChatSession.update(session.id, { status: "agent_rejected", updatedAt: Date.now() });
|
|
47291
|
+
publishStatus(sessionId, "agent_rejected", session);
|
|
47281
47292
|
notify({ type: "rejected", sessionId, session });
|
|
47282
47293
|
};
|
|
47283
47294
|
const reply = async (session, content) => {
|
|
@@ -47312,11 +47323,14 @@ function createAgentNotificationService(client) {
|
|
|
47312
47323
|
id: `agent-request-${request.sessionId}`,
|
|
47313
47324
|
title: request.title,
|
|
47314
47325
|
body: request.body,
|
|
47315
|
-
data: { sessionId: request.sessionId },
|
|
47326
|
+
data: { sessionId: request.sessionId, kind: request.kind || "agent_request" },
|
|
47316
47327
|
channel: "agent_requests",
|
|
47317
47328
|
actions: [
|
|
47318
|
-
|
|
47319
|
-
|
|
47329
|
+
...request.kind === "agent_message" ? [] : [
|
|
47330
|
+
{ id: "accept", title: "Accept" },
|
|
47331
|
+
{ id: "reject", title: "Reject" }
|
|
47332
|
+
],
|
|
47333
|
+
{ id: "open", title: "Open" },
|
|
47320
47334
|
{ id: "reply", title: "Reply", input: true }
|
|
47321
47335
|
]
|
|
47322
47336
|
});
|
|
@@ -47331,6 +47345,7 @@ function createAgentNotificationService(client) {
|
|
|
47331
47345
|
seen.set(sessionId, fingerprint);
|
|
47332
47346
|
const request = {
|
|
47333
47347
|
sessionId,
|
|
47348
|
+
kind: "agent_request",
|
|
47334
47349
|
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
47335
47350
|
body: latest?.content || "A visitor is requesting a human agent.",
|
|
47336
47351
|
latestMessage: latest,
|
|
@@ -47339,9 +47354,33 @@ function createAgentNotificationService(client) {
|
|
|
47339
47354
|
await showNative(request);
|
|
47340
47355
|
notify({ type: "request", ...request });
|
|
47341
47356
|
}
|
|
47357
|
+
if (client.agentIdentity) {
|
|
47358
|
+
const active = toList(await client.entities.ChatSession.query({ filter: { appId, status: "agent_active", agent_email: client.agentIdentity }, limit: 100 }));
|
|
47359
|
+
for (const session of active) {
|
|
47360
|
+
const sessionId = getSessionId(session);
|
|
47361
|
+
if (!sessionId) continue;
|
|
47362
|
+
const messages = await getMessages(sessionId, appId);
|
|
47363
|
+
const latestVisitor = latestByTime(messages.filter((message2) => message2?.role === "visitor" || message2?.role === "user"));
|
|
47364
|
+
if (!latestVisitor) continue;
|
|
47365
|
+
const fingerprint = `message:${latestVisitor.id || latestVisitor.createdAt || latestVisitor.content}`;
|
|
47366
|
+
if (seen.get(`message:${sessionId}`) === fingerprint) continue;
|
|
47367
|
+
seen.set(`message:${sessionId}`, fingerprint);
|
|
47368
|
+
const request = {
|
|
47369
|
+
sessionId,
|
|
47370
|
+
kind: "agent_message",
|
|
47371
|
+
title: `New message from ${session.visitor_name || "visitor"}`,
|
|
47372
|
+
body: latestVisitor.content || "The visitor sent an attachment.",
|
|
47373
|
+
latestMessage: latestVisitor,
|
|
47374
|
+
session
|
|
47375
|
+
};
|
|
47376
|
+
await showNative(request);
|
|
47377
|
+
notify({ type: "message", ...request });
|
|
47378
|
+
}
|
|
47379
|
+
}
|
|
47342
47380
|
};
|
|
47343
47381
|
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
47344
47382
|
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
47383
|
+
if (options.appId) client.appId = options.appId;
|
|
47345
47384
|
stopped = false;
|
|
47346
47385
|
await check(options);
|
|
47347
47386
|
clearInterval(timer);
|
|
@@ -47357,7 +47396,9 @@ function createAgentNotificationService(client) {
|
|
|
47357
47396
|
return () => listeners2.delete(listener);
|
|
47358
47397
|
};
|
|
47359
47398
|
client.notifications.onAction(({ action, data, reply: text }) => {
|
|
47360
|
-
if (data?.sessionId
|
|
47399
|
+
if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
|
|
47400
|
+
dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47401
|
+
}
|
|
47361
47402
|
});
|
|
47362
47403
|
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47363
47404
|
}
|
|
@@ -47486,6 +47527,47 @@ function createNotificationService() {
|
|
|
47486
47527
|
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
47487
47528
|
}
|
|
47488
47529
|
|
|
47530
|
+
// src/services/chatNotifications.js
|
|
47531
|
+
function createChatNotificationService(client) {
|
|
47532
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47533
|
+
const emit2 = (event) => listeners2.forEach((listener) => listener(event));
|
|
47534
|
+
const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {} } = {}) => {
|
|
47535
|
+
if (!sessionId) return null;
|
|
47536
|
+
return client.notifications.show({
|
|
47537
|
+
id: `chat-message-${sessionId}-${Date.now()}`,
|
|
47538
|
+
title,
|
|
47539
|
+
body,
|
|
47540
|
+
data: { ...data, sessionId, kind: "chat_message" },
|
|
47541
|
+
channel: "chat_messages",
|
|
47542
|
+
actions: [
|
|
47543
|
+
{ id: "open", title: "Open chat" },
|
|
47544
|
+
{ id: "reply", title: "Reply", input: true }
|
|
47545
|
+
]
|
|
47546
|
+
});
|
|
47547
|
+
};
|
|
47548
|
+
const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {} } = {}) => {
|
|
47549
|
+
if (!sessionId) return null;
|
|
47550
|
+
return client.notifications.show({
|
|
47551
|
+
id: `chat-status-${sessionId}-${Date.now()}`,
|
|
47552
|
+
title,
|
|
47553
|
+
body,
|
|
47554
|
+
data: { ...data, sessionId, kind: "chat_status" },
|
|
47555
|
+
channel: "chat_messages",
|
|
47556
|
+
actions: [{ id: "open", title: "Open chat" }]
|
|
47557
|
+
});
|
|
47558
|
+
};
|
|
47559
|
+
const onEvent = (listener) => {
|
|
47560
|
+
listeners2.add(listener);
|
|
47561
|
+
return () => listeners2.delete(listener);
|
|
47562
|
+
};
|
|
47563
|
+
client.notifications.onAction(({ action, data, reply }) => {
|
|
47564
|
+
if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
|
|
47565
|
+
emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
|
|
47566
|
+
}
|
|
47567
|
+
});
|
|
47568
|
+
return { showMessage, showStatus, onEvent };
|
|
47569
|
+
}
|
|
47570
|
+
|
|
47489
47571
|
// src/index.js
|
|
47490
47572
|
init_usePlatform();
|
|
47491
47573
|
|
|
@@ -48607,6 +48689,7 @@ var TevrocClient = class {
|
|
|
48607
48689
|
this.commerce = createCommerceApi(this);
|
|
48608
48690
|
this.realtime = createRealtimeApi(this);
|
|
48609
48691
|
this.notifications = createNotificationService();
|
|
48692
|
+
this.chatNotifications = createChatNotificationService(this);
|
|
48610
48693
|
this.agentNotifications = createAgentNotificationService(this);
|
|
48611
48694
|
this.shiplogic = createShiplogicApi(this);
|
|
48612
48695
|
this.platform = createPlatformApi(this);
|