tevrocsdk 0.1.72 → 0.1.74
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 +96 -7
- package/tevroc-sdk.cjs.js.map +4 -4
- package/tevroc-sdk.esm.js +96 -7
- 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,15 +47323,19 @@ 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",
|
|
47328
|
+
style: request.style,
|
|
47317
47329
|
actions: [
|
|
47318
|
-
|
|
47319
|
-
|
|
47330
|
+
...request.kind === "agent_message" ? [] : [
|
|
47331
|
+
{ id: "accept", title: "Accept" },
|
|
47332
|
+
{ id: "reject", title: "Reject" }
|
|
47333
|
+
],
|
|
47334
|
+
{ id: "open", title: "Open" },
|
|
47320
47335
|
{ id: "reply", title: "Reply", input: true }
|
|
47321
47336
|
]
|
|
47322
47337
|
});
|
|
47323
|
-
const check = async ({ appId = client.appId } = {}) => {
|
|
47338
|
+
const check = async ({ appId = client.appId, notificationStyle } = {}) => {
|
|
47324
47339
|
const sessions = toList(await client.entities.ChatSession.query({ filter: { appId, status: "escalated" }, limit: 100 }));
|
|
47325
47340
|
for (const session of sessions) {
|
|
47326
47341
|
const sessionId = getSessionId(session);
|
|
@@ -47331,17 +47346,44 @@ function createAgentNotificationService(client) {
|
|
|
47331
47346
|
seen.set(sessionId, fingerprint);
|
|
47332
47347
|
const request = {
|
|
47333
47348
|
sessionId,
|
|
47349
|
+
kind: "agent_request",
|
|
47334
47350
|
title: `Support request from ${session.visitor_name || "a visitor"}`,
|
|
47335
47351
|
body: latest?.content || "A visitor is requesting a human agent.",
|
|
47336
47352
|
latestMessage: latest,
|
|
47337
|
-
session
|
|
47353
|
+
session,
|
|
47354
|
+
style: notificationStyle
|
|
47338
47355
|
};
|
|
47339
47356
|
await showNative(request);
|
|
47340
47357
|
notify({ type: "request", ...request });
|
|
47341
47358
|
}
|
|
47359
|
+
if (client.agentIdentity) {
|
|
47360
|
+
const active = toList(await client.entities.ChatSession.query({ filter: { appId, status: "agent_active", agent_email: client.agentIdentity }, limit: 100 }));
|
|
47361
|
+
for (const session of active) {
|
|
47362
|
+
const sessionId = getSessionId(session);
|
|
47363
|
+
if (!sessionId) continue;
|
|
47364
|
+
const messages = await getMessages(sessionId, appId);
|
|
47365
|
+
const latestVisitor = latestByTime(messages.filter((message2) => message2?.role === "visitor" || message2?.role === "user"));
|
|
47366
|
+
if (!latestVisitor) continue;
|
|
47367
|
+
const fingerprint = `message:${latestVisitor.id || latestVisitor.createdAt || latestVisitor.content}`;
|
|
47368
|
+
if (seen.get(`message:${sessionId}`) === fingerprint) continue;
|
|
47369
|
+
seen.set(`message:${sessionId}`, fingerprint);
|
|
47370
|
+
const request = {
|
|
47371
|
+
sessionId,
|
|
47372
|
+
kind: "agent_message",
|
|
47373
|
+
title: `New message from ${session.visitor_name || "visitor"}`,
|
|
47374
|
+
body: latestVisitor.content || "The visitor sent an attachment.",
|
|
47375
|
+
latestMessage: latestVisitor,
|
|
47376
|
+
session,
|
|
47377
|
+
style: notificationStyle
|
|
47378
|
+
};
|
|
47379
|
+
await showNative(request);
|
|
47380
|
+
notify({ type: "message", ...request });
|
|
47381
|
+
}
|
|
47382
|
+
}
|
|
47342
47383
|
};
|
|
47343
47384
|
const start = async ({ pollMs = 8e3, agentIdentity, ...options } = {}) => {
|
|
47344
47385
|
if (agentIdentity) client.agentIdentity = agentIdentity;
|
|
47386
|
+
if (options.appId) client.appId = options.appId;
|
|
47345
47387
|
stopped = false;
|
|
47346
47388
|
await check(options);
|
|
47347
47389
|
clearInterval(timer);
|
|
@@ -47357,7 +47399,9 @@ function createAgentNotificationService(client) {
|
|
|
47357
47399
|
return () => listeners2.delete(listener);
|
|
47358
47400
|
};
|
|
47359
47401
|
client.notifications.onAction(({ action, data, reply: text }) => {
|
|
47360
|
-
if (data?.sessionId
|
|
47402
|
+
if (data?.sessionId && String(data.kind || "").startsWith("agent_")) {
|
|
47403
|
+
dispatchAction({ action, sessionId: data.sessionId, reply: text }).catch((error) => notify({ type: "error", error }));
|
|
47404
|
+
}
|
|
47361
47405
|
});
|
|
47362
47406
|
return { start, stop, check, onEvent, accept, reject, reply, dispatchAction };
|
|
47363
47407
|
}
|
|
@@ -47430,7 +47474,8 @@ function createNotificationService() {
|
|
|
47430
47474
|
data: options.data || {},
|
|
47431
47475
|
actions: options.actions || [],
|
|
47432
47476
|
silent: Boolean(options.silent),
|
|
47433
|
-
channel: options.channel || "general"
|
|
47477
|
+
channel: options.channel || "general",
|
|
47478
|
+
style: options.style || {}
|
|
47434
47479
|
};
|
|
47435
47480
|
const plugin = appPlugin();
|
|
47436
47481
|
if (plugin?.show) {
|
|
@@ -47486,6 +47531,49 @@ function createNotificationService() {
|
|
|
47486
47531
|
return { permission, requestPermission, show, schedule, cancel, cancelAll, onAction };
|
|
47487
47532
|
}
|
|
47488
47533
|
|
|
47534
|
+
// src/services/chatNotifications.js
|
|
47535
|
+
function createChatNotificationService(client) {
|
|
47536
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
47537
|
+
const emit2 = (event) => listeners2.forEach((listener) => listener(event));
|
|
47538
|
+
const showMessage = async ({ sessionId, title = "New chat message", body = "", data = {}, style } = {}) => {
|
|
47539
|
+
if (!sessionId) return null;
|
|
47540
|
+
return client.notifications.show({
|
|
47541
|
+
id: `chat-message-${sessionId}-${Date.now()}`,
|
|
47542
|
+
title,
|
|
47543
|
+
body,
|
|
47544
|
+
data: { ...data, sessionId, kind: "chat_message" },
|
|
47545
|
+
channel: "chat_messages",
|
|
47546
|
+
style,
|
|
47547
|
+
actions: [
|
|
47548
|
+
{ id: "open", title: "Open chat" },
|
|
47549
|
+
{ id: "reply", title: "Reply", input: true }
|
|
47550
|
+
]
|
|
47551
|
+
});
|
|
47552
|
+
};
|
|
47553
|
+
const showStatus = async ({ sessionId, title = "Chat update", body = "", data = {}, style } = {}) => {
|
|
47554
|
+
if (!sessionId) return null;
|
|
47555
|
+
return client.notifications.show({
|
|
47556
|
+
id: `chat-status-${sessionId}-${Date.now()}`,
|
|
47557
|
+
title,
|
|
47558
|
+
body,
|
|
47559
|
+
data: { ...data, sessionId, kind: "chat_status" },
|
|
47560
|
+
channel: "chat_messages",
|
|
47561
|
+
style,
|
|
47562
|
+
actions: [{ id: "open", title: "Open chat" }]
|
|
47563
|
+
});
|
|
47564
|
+
};
|
|
47565
|
+
const onEvent = (listener) => {
|
|
47566
|
+
listeners2.add(listener);
|
|
47567
|
+
return () => listeners2.delete(listener);
|
|
47568
|
+
};
|
|
47569
|
+
client.notifications.onAction(({ action, data, reply }) => {
|
|
47570
|
+
if (data?.sessionId && ["chat_message", "chat_status"].includes(data.kind)) {
|
|
47571
|
+
emit2({ type: action === "reply" ? "reply" : action, action, sessionId: data.sessionId, reply: reply || "", data });
|
|
47572
|
+
}
|
|
47573
|
+
});
|
|
47574
|
+
return { showMessage, showStatus, onEvent };
|
|
47575
|
+
}
|
|
47576
|
+
|
|
47489
47577
|
// src/index.js
|
|
47490
47578
|
init_usePlatform();
|
|
47491
47579
|
|
|
@@ -48607,6 +48695,7 @@ var TevrocClient = class {
|
|
|
48607
48695
|
this.commerce = createCommerceApi(this);
|
|
48608
48696
|
this.realtime = createRealtimeApi(this);
|
|
48609
48697
|
this.notifications = createNotificationService();
|
|
48698
|
+
this.chatNotifications = createChatNotificationService(this);
|
|
48610
48699
|
this.agentNotifications = createAgentNotificationService(this);
|
|
48611
48700
|
this.shiplogic = createShiplogicApi(this);
|
|
48612
48701
|
this.platform = createPlatformApi(this);
|