@astralibx/call-log-engine 0.2.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 +157 -0
- package/dist/index.cjs +2500 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +445 -0
- package/dist/index.d.ts +445 -0
- package/dist/index.mjs +2454 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# @astralibx/call-log-engine
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@astralibx/call-log-engine)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Call log engine with pipelines, timeline-based notes, contact adapters, follow-up worker, analytics, export, and shared agent support.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @astralibx/call-log-engine
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Peer Dependencies
|
|
15
|
+
|
|
16
|
+
| Package | Required |
|
|
17
|
+
|---------|----------|
|
|
18
|
+
| `express` | Yes |
|
|
19
|
+
| `mongoose` | Yes |
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install express mongoose
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
MongoDB is **mandatory** for call-log-engine. It stores pipelines, call logs (with embedded timelines), and settings.
|
|
28
|
+
|
|
29
|
+
There is no Redis dependency -- the follow-up worker polls MongoDB directly.
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createCallLogEngine } from '@astralibx/call-log-engine';
|
|
35
|
+
import mongoose from 'mongoose';
|
|
36
|
+
import express from 'express';
|
|
37
|
+
|
|
38
|
+
const app = express();
|
|
39
|
+
app.use(express.json());
|
|
40
|
+
|
|
41
|
+
const connection = mongoose.createConnection('mongodb://localhost:27017/myapp');
|
|
42
|
+
|
|
43
|
+
const engine = createCallLogEngine({
|
|
44
|
+
db: { connection, collectionPrefix: '' },
|
|
45
|
+
adapters: {
|
|
46
|
+
lookupContact: async (query) => {
|
|
47
|
+
// Look up contact by phone/email/externalId
|
|
48
|
+
return null;
|
|
49
|
+
},
|
|
50
|
+
authenticateAgent: async (token) => {
|
|
51
|
+
// Verify JWT/session token, return { adminUserId, displayName } or null
|
|
52
|
+
return null;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Mount REST routes
|
|
58
|
+
app.use('/api/call-log', engine.routes);
|
|
59
|
+
|
|
60
|
+
app.listen(3000);
|
|
61
|
+
|
|
62
|
+
// Graceful shutdown -- stops the follow-up worker
|
|
63
|
+
process.on('SIGTERM', async () => {
|
|
64
|
+
await engine.destroy();
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Full Setup with Agent Sharing
|
|
69
|
+
|
|
70
|
+
When running alongside `@astralibx/chat-engine`, both engines share the same agent collection by default (`chatagents`). See [Agent Sharing](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/agent-sharing.md).
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const engine = createCallLogEngine({
|
|
74
|
+
db: { connection },
|
|
75
|
+
agents: {
|
|
76
|
+
collectionName: 'chatagents', // default -- same collection chat-engine uses
|
|
77
|
+
resolveAgent: async (agentId) => {
|
|
78
|
+
const agent = await AgentModel.findById(agentId);
|
|
79
|
+
return agent ? { agentId: agent._id.toString(), displayName: agent.name } : null;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
adapters: {
|
|
83
|
+
lookupContact: async (query) => {
|
|
84
|
+
const contact = await ContactModel.findOne(query);
|
|
85
|
+
return contact
|
|
86
|
+
? { externalId: contact._id.toString(), displayName: contact.name, phone: contact.phone }
|
|
87
|
+
: null;
|
|
88
|
+
},
|
|
89
|
+
addContact: async (data) => {
|
|
90
|
+
const contact = await ContactModel.create(data);
|
|
91
|
+
return { externalId: contact._id.toString(), displayName: contact.displayName };
|
|
92
|
+
},
|
|
93
|
+
authenticateAgent: async (token) => {
|
|
94
|
+
const user = await verifyJWT(token);
|
|
95
|
+
return user ? { adminUserId: user.id, displayName: user.name } : null;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
hooks: {
|
|
99
|
+
onCallCreated: (callLog) => console.log('New call:', callLog.callLogId),
|
|
100
|
+
onStageChanged: (callLog, from, to) => console.log(`Stage: ${from} -> ${to}`),
|
|
101
|
+
onCallClosed: (callLog) => console.log('Call closed:', callLog.callLogId),
|
|
102
|
+
onFollowUpDue: async (callLog) => notifyAgent(callLog),
|
|
103
|
+
onMetric: (metric) => prometheus.observe(metric.name, metric.value, metric.labels),
|
|
104
|
+
},
|
|
105
|
+
options: {
|
|
106
|
+
maxTimelineEntries: 200, // default
|
|
107
|
+
followUpCheckIntervalMs: 60_000, // default: 1 minute
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Features
|
|
113
|
+
|
|
114
|
+
- **Pipeline management** -- CRUD pipelines with configurable stages, default/terminal flags, and stage reordering. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
115
|
+
- **Call log lifecycle** -- Create, update, change stage, assign, close, reopen calls with automatic timeline tracking. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
116
|
+
- **Timeline** -- Append-only audit trail per call with notes, stage changes, assignments, follow-up events. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
117
|
+
- **Contact timeline** -- Merged cross-call timeline for a contact. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
118
|
+
- **Follow-up worker** -- Background worker polls for due follow-ups and fires `onFollowUpDue` hook. Starts automatically, stops via `engine.destroy()`. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/hooks.md)
|
|
119
|
+
- **Analytics** -- Dashboard stats, agent stats, leaderboard, pipeline stats/funnel, team stats, daily/weekly/overall reports. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
120
|
+
- **Export** -- Bulk call export, single call export, pipeline report export in JSON or CSV. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
121
|
+
- **Settings** -- Runtime-mutable tags, categories, priority levels, follow-up defaults. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
122
|
+
- **Bulk operations** -- Bulk stage change for multiple call logs at once. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
123
|
+
- **Contact adapters** -- Pluggable contact lookup and creation. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/adapters.md)
|
|
124
|
+
- **Agent sharing** -- Reuse chat-engine's agent collection. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/agent-sharing.md)
|
|
125
|
+
- **Lifecycle hooks** -- 6 hooks for call events, follow-ups, and metrics. [Details](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/hooks.md)
|
|
126
|
+
- **Error classes** -- Typed errors with codes for every failure scenario.
|
|
127
|
+
|
|
128
|
+
## Architecture
|
|
129
|
+
|
|
130
|
+
The library exposes an Express router from a single factory call:
|
|
131
|
+
|
|
132
|
+
| Export | Purpose | Access |
|
|
133
|
+
|--------|---------|--------|
|
|
134
|
+
| `engine.routes` | REST API -- pipelines, calls, contacts, analytics, settings, export | Protected (via `authenticateAgent` adapter) |
|
|
135
|
+
| `engine.destroy()` | Stops follow-up worker, cleans up resources | Call on shutdown |
|
|
136
|
+
|
|
137
|
+
All services are also available programmatically via the returned `engine` object: `pipelines`, `callLogs`, `timeline`, `analytics`, `settings`, `export`, `models`.
|
|
138
|
+
|
|
139
|
+
## Getting Started Guide
|
|
140
|
+
|
|
141
|
+
1. [Configuration](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/configuration.md) -- Set up database, agents, adapters, and options
|
|
142
|
+
2. [Adapters](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/adapters.md) -- Implement contact lookup, authentication, and agent resolution
|
|
143
|
+
3. [Hooks](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/hooks.md) -- Wire up notifications, analytics, and monitoring
|
|
144
|
+
|
|
145
|
+
Guides: [Agent Sharing](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/agent-sharing.md)
|
|
146
|
+
|
|
147
|
+
Reference: [API Routes](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/docs/api-routes.md)
|
|
148
|
+
|
|
149
|
+
## Links
|
|
150
|
+
|
|
151
|
+
- [GitHub](https://github.com/Hariprakash1997/astralib/tree/main/packages/call-log/call-log-engine)
|
|
152
|
+
- [call-log-types](https://github.com/Hariprakash1997/astralib/tree/main/packages/call-log/call-log-types)
|
|
153
|
+
- [CHANGELOG](https://github.com/Hariprakash1997/astralib/blob/main/packages/call-log/call-log-engine/CHANGELOG.md)
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|