@softtynet/zplus-worker 1.0.0 → 1.0.3
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 +27 -55
- package/dist/cli.js +1 -1408
- package/package.json +3 -3
- package/dist/automation/HeadlessAutomationEngine.d.ts +0 -12
- package/dist/automation/HeadlessAutomationEngine.js +0 -34
- package/dist/channels/ChannelRunnerRegistry.d.ts +0 -14
- package/dist/channels/ChannelRunnerRegistry.js +0 -65
- package/dist/channels/IChannelRunner.d.ts +0 -10
- package/dist/channels/IChannelRunner.js +0 -2
- package/dist/channels/index.d.ts +0 -6
- package/dist/channels/index.js +0 -22
- package/dist/channels/runners/FacebookChannelRunner.d.ts +0 -19
- package/dist/channels/runners/FacebookChannelRunner.js +0 -47
- package/dist/channels/runners/TelegramChannelRunner.d.ts +0 -19
- package/dist/channels/runners/TelegramChannelRunner.js +0 -47
- package/dist/channels/runners/WhatsAppChannelRunner.d.ts +0 -19
- package/dist/channels/runners/WhatsAppChannelRunner.js +0 -47
- package/dist/channels/runners/ZaloChannelRunner.d.ts +0 -22
- package/dist/channels/runners/ZaloChannelRunner.js +0 -50
- package/dist/cli.d.ts +0 -6
- package/dist/config/WorkerConfig.d.ts +0 -16
- package/dist/config/WorkerConfig.js +0 -21
- package/dist/engine/WorkerEngine.d.ts +0 -38
- package/dist/engine/WorkerEngine.js +0 -157
- package/dist/index.d.ts +0 -9
- package/dist/lock/DistributedLockManager.d.ts +0 -40
- package/dist/lock/DistributedLockManager.js +0 -113
- package/dist/notifications/PushNotificationDispatcher.d.ts +0 -14
- package/dist/notifications/PushNotificationDispatcher.js +0 -31
- package/dist/server/WorkerHttpServer.d.ts +0 -25
- package/dist/server/WorkerHttpServer.js +0 -205
- package/dist/sync/CloudPendingMessageQueue.d.ts +0 -27
- package/dist/sync/CloudPendingMessageQueue.js +0 -69
- package/dist/sync/CloudSyncWorker.d.ts +0 -19
- package/dist/sync/CloudSyncWorker.js +0 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softtynet/zplus-worker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "ZPlus 24/7 Headless Automation & Omnichannel Worker Engine",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"dist"
|
|
14
|
+
"dist/cli.js"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc && npm run bundle",
|
|
18
|
-
"bundle": "esbuild src/cli.ts --bundle --platform=node --target=node18 --outfile=dist/cli.js",
|
|
18
|
+
"bundle": "esbuild src/cli.ts --bundle --minify --platform=node --target=node18 --outfile=dist/cli.js",
|
|
19
19
|
"typecheck": "tsc --noEmit",
|
|
20
20
|
"test": "vitest run",
|
|
21
21
|
"start": "node dist/cli.js",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "@zplus/core";
|
|
2
|
-
import { AutomationRule, DripCampaign, UnifiedMessage } from "@zplus/contracts";
|
|
3
|
-
export declare class HeadlessAutomationEngine {
|
|
4
|
-
private readonly logger;
|
|
5
|
-
private readonly campaigns;
|
|
6
|
-
private readonly rules;
|
|
7
|
-
constructor(logger?: ILogger);
|
|
8
|
-
registerCampaign(campaign: DripCampaign): void;
|
|
9
|
-
registerRule(rule: AutomationRule): void;
|
|
10
|
-
evaluateIncomingMessage(message: UnifiedMessage): Promise<string | null>;
|
|
11
|
-
clear(): void;
|
|
12
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HeadlessAutomationEngine = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class HeadlessAutomationEngine {
|
|
6
|
-
logger;
|
|
7
|
-
campaigns = new Map();
|
|
8
|
-
rules = new Map();
|
|
9
|
-
constructor(logger) {
|
|
10
|
-
this.logger = logger || (0, core_1.createLogger)("HeadlessAutomationEngine");
|
|
11
|
-
}
|
|
12
|
-
registerCampaign(campaign) {
|
|
13
|
-
this.campaigns.set(campaign.id, campaign);
|
|
14
|
-
this.logger.info(`Loaded campaign ${campaign.id} (${campaign.name})`);
|
|
15
|
-
}
|
|
16
|
-
registerRule(rule) {
|
|
17
|
-
this.rules.set(rule.id, rule);
|
|
18
|
-
this.logger.info(`Loaded automation rule ${rule.id} (${rule.name})`);
|
|
19
|
-
}
|
|
20
|
-
async evaluateIncomingMessage(message) {
|
|
21
|
-
if (message.senderType === "customer") {
|
|
22
|
-
this.logger.debug(`Evaluating automation triggers for incoming customer message ${message.id}`);
|
|
23
|
-
// Kiểm tra các kịch bản hoặc trả về câu trực đêm mặc định
|
|
24
|
-
const defaultNightReply = "Cảm ơn bạn đã nhắn tin. Hiện tại đang trong khung giờ trực đêm, tin nhắn của bạn đã được ghi nhận và nhân viên sẽ hỗ trợ ngay khi mở ca làm việc!";
|
|
25
|
-
return defaultNightReply;
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
clear() {
|
|
30
|
-
this.campaigns.clear();
|
|
31
|
-
this.rules.clear();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.HeadlessAutomationEngine = HeadlessAutomationEngine;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IChannelRunner } from "./IChannelRunner";
|
|
2
|
-
import { ILogger } from "@zplus/core";
|
|
3
|
-
export declare class ChannelRunnerRegistry {
|
|
4
|
-
private readonly runners;
|
|
5
|
-
private readonly logger;
|
|
6
|
-
constructor(logger?: ILogger);
|
|
7
|
-
register(runner: IChannelRunner): void;
|
|
8
|
-
unregister(platform: string, accountId: string): boolean;
|
|
9
|
-
get(platform: string, accountId: string): IChannelRunner | undefined;
|
|
10
|
-
getAll(): IChannelRunner[];
|
|
11
|
-
getCount(): number;
|
|
12
|
-
startAll(): Promise<void>;
|
|
13
|
-
stopAll(): Promise<void>;
|
|
14
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChannelRunnerRegistry = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class ChannelRunnerRegistry {
|
|
6
|
-
runners = new Map();
|
|
7
|
-
logger;
|
|
8
|
-
constructor(logger) {
|
|
9
|
-
this.logger = logger || (0, core_1.createLogger)("ChannelRunnerRegistry");
|
|
10
|
-
}
|
|
11
|
-
register(runner) {
|
|
12
|
-
const key = `${runner.platform}:${runner.accountId}`;
|
|
13
|
-
if (this.runners.has(key)) {
|
|
14
|
-
this.logger.warn(`Overwriting existing runner for ${key}`);
|
|
15
|
-
}
|
|
16
|
-
this.runners.set(key, runner);
|
|
17
|
-
this.logger.info(`Registered runner for ${key}`);
|
|
18
|
-
}
|
|
19
|
-
unregister(platform, accountId) {
|
|
20
|
-
const key = `${platform}:${accountId}`;
|
|
21
|
-
const runner = this.runners.get(key);
|
|
22
|
-
if (runner) {
|
|
23
|
-
runner.stop().catch((err) => {
|
|
24
|
-
this.logger.error(`Error stopping runner ${key} during unregister`, err);
|
|
25
|
-
});
|
|
26
|
-
this.runners.delete(key);
|
|
27
|
-
this.logger.info(`Unregistered runner for ${key}`);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
get(platform, accountId) {
|
|
33
|
-
return this.runners.get(`${platform}:${accountId}`);
|
|
34
|
-
}
|
|
35
|
-
getAll() {
|
|
36
|
-
return Array.from(this.runners.values());
|
|
37
|
-
}
|
|
38
|
-
getCount() {
|
|
39
|
-
return this.runners.size;
|
|
40
|
-
}
|
|
41
|
-
async startAll() {
|
|
42
|
-
this.logger.info(`Starting all ${this.runners.size} registered channel runners...`);
|
|
43
|
-
for (const [key, runner] of this.runners.entries()) {
|
|
44
|
-
try {
|
|
45
|
-
await runner.start();
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
this.logger.error(`Failed to start runner ${key}:`, err);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async stopAll() {
|
|
53
|
-
this.logger.info(`Stopping all ${this.runners.size} channel runners...`);
|
|
54
|
-
for (const [key, runner] of this.runners.entries()) {
|
|
55
|
-
try {
|
|
56
|
-
await runner.stop();
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
this.logger.error(`Failed to stop runner ${key}:`, err);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
this.runners.clear();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.ChannelRunnerRegistry = ChannelRunnerRegistry;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AccountStatus, PlatformType, UnifiedMessage } from "@zplus/contracts";
|
|
2
|
-
export interface IChannelRunner {
|
|
3
|
-
readonly accountId: string;
|
|
4
|
-
readonly platform: PlatformType;
|
|
5
|
-
start(): Promise<void>;
|
|
6
|
-
stop(): Promise<void>;
|
|
7
|
-
getStatus(): AccountStatus;
|
|
8
|
-
sendMessage(message: UnifiedMessage): Promise<boolean>;
|
|
9
|
-
onMessage?(handler: (message: UnifiedMessage) => void): void;
|
|
10
|
-
}
|
package/dist/channels/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from "./IChannelRunner";
|
|
2
|
-
export * from "./ChannelRunnerRegistry";
|
|
3
|
-
export * from "./runners/ZaloChannelRunner";
|
|
4
|
-
export * from "./runners/FacebookChannelRunner";
|
|
5
|
-
export * from "./runners/TelegramChannelRunner";
|
|
6
|
-
export * from "./runners/WhatsAppChannelRunner";
|
package/dist/channels/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./IChannelRunner"), exports);
|
|
18
|
-
__exportStar(require("./ChannelRunnerRegistry"), exports);
|
|
19
|
-
__exportStar(require("./runners/ZaloChannelRunner"), exports);
|
|
20
|
-
__exportStar(require("./runners/FacebookChannelRunner"), exports);
|
|
21
|
-
__exportStar(require("./runners/TelegramChannelRunner"), exports);
|
|
22
|
-
__exportStar(require("./runners/WhatsAppChannelRunner"), exports);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IChannelRunner } from "../IChannelRunner";
|
|
2
|
-
import { AccountStatus, PlatformType, UnifiedMessage } from "@zplus/contracts";
|
|
3
|
-
import { ILogger } from "@zplus/core";
|
|
4
|
-
export declare class FacebookChannelRunner implements IChannelRunner {
|
|
5
|
-
readonly accountId: string;
|
|
6
|
-
private readonly sessionData?;
|
|
7
|
-
private readonly proxyData?;
|
|
8
|
-
readonly platform: PlatformType;
|
|
9
|
-
private status;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private messageHandler?;
|
|
12
|
-
constructor(accountId: string, sessionData?: Record<string, any> | undefined, proxyData?: Record<string, any> | undefined, logger?: ILogger);
|
|
13
|
-
onMessage(handler: (message: UnifiedMessage) => void): void;
|
|
14
|
-
start(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
getStatus(): AccountStatus;
|
|
17
|
-
sendMessage(message: UnifiedMessage): Promise<boolean>;
|
|
18
|
-
receiveIncomingMessage(message: UnifiedMessage): void;
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FacebookChannelRunner = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class FacebookChannelRunner {
|
|
6
|
-
accountId;
|
|
7
|
-
sessionData;
|
|
8
|
-
proxyData;
|
|
9
|
-
platform = "facebook";
|
|
10
|
-
status = "offline";
|
|
11
|
-
logger;
|
|
12
|
-
messageHandler;
|
|
13
|
-
constructor(accountId, sessionData, proxyData, logger) {
|
|
14
|
-
this.accountId = accountId;
|
|
15
|
-
this.sessionData = sessionData;
|
|
16
|
-
this.proxyData = proxyData;
|
|
17
|
-
this.logger = logger || (0, core_1.createLogger)(`FacebookRunner:${accountId}`);
|
|
18
|
-
}
|
|
19
|
-
onMessage(handler) {
|
|
20
|
-
this.messageHandler = handler;
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
const proxyInfo = this.proxyData
|
|
24
|
-
? ` via resident proxy ${this.proxyData.host || this.proxyData.ip || "configured"}`
|
|
25
|
-
: " (direct)";
|
|
26
|
-
this.logger.info(`Starting 24/7 headless Facebook runner for account ${this.accountId}${proxyInfo}...`);
|
|
27
|
-
this.status = "active";
|
|
28
|
-
}
|
|
29
|
-
async stop() {
|
|
30
|
-
this.logger.info(`Stopping headless Facebook runner for account ${this.accountId}...`);
|
|
31
|
-
this.status = "offline";
|
|
32
|
-
}
|
|
33
|
-
getStatus() {
|
|
34
|
-
return this.status;
|
|
35
|
-
}
|
|
36
|
-
async sendMessage(message) {
|
|
37
|
-
this.logger.info(`Headless Facebook runner sending message ${message.id} to thread ${message.threadId}`);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
receiveIncomingMessage(message) {
|
|
41
|
-
if (this.status !== "active")
|
|
42
|
-
return;
|
|
43
|
-
this.logger.debug(`Facebook runner received message ${message.id} from sender ${message.senderId}`);
|
|
44
|
-
this.messageHandler?.(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.FacebookChannelRunner = FacebookChannelRunner;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IChannelRunner } from "../IChannelRunner";
|
|
2
|
-
import { AccountStatus, PlatformType, UnifiedMessage } from "@zplus/contracts";
|
|
3
|
-
import { ILogger } from "@zplus/core";
|
|
4
|
-
export declare class TelegramChannelRunner implements IChannelRunner {
|
|
5
|
-
readonly accountId: string;
|
|
6
|
-
private readonly sessionData?;
|
|
7
|
-
private readonly proxyData?;
|
|
8
|
-
readonly platform: PlatformType;
|
|
9
|
-
private status;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private messageHandler?;
|
|
12
|
-
constructor(accountId: string, sessionData?: Record<string, any> | undefined, proxyData?: Record<string, any> | undefined, logger?: ILogger);
|
|
13
|
-
onMessage(handler: (message: UnifiedMessage) => void): void;
|
|
14
|
-
start(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
getStatus(): AccountStatus;
|
|
17
|
-
sendMessage(message: UnifiedMessage): Promise<boolean>;
|
|
18
|
-
receiveIncomingMessage(message: UnifiedMessage): void;
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TelegramChannelRunner = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class TelegramChannelRunner {
|
|
6
|
-
accountId;
|
|
7
|
-
sessionData;
|
|
8
|
-
proxyData;
|
|
9
|
-
platform = "telegram";
|
|
10
|
-
status = "offline";
|
|
11
|
-
logger;
|
|
12
|
-
messageHandler;
|
|
13
|
-
constructor(accountId, sessionData, proxyData, logger) {
|
|
14
|
-
this.accountId = accountId;
|
|
15
|
-
this.sessionData = sessionData;
|
|
16
|
-
this.proxyData = proxyData;
|
|
17
|
-
this.logger = logger || (0, core_1.createLogger)(`TelegramRunner:${accountId}`);
|
|
18
|
-
}
|
|
19
|
-
onMessage(handler) {
|
|
20
|
-
this.messageHandler = handler;
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
const proxyInfo = this.proxyData
|
|
24
|
-
? ` via resident proxy ${this.proxyData.host || this.proxyData.ip || "configured"}`
|
|
25
|
-
: " (direct)";
|
|
26
|
-
this.logger.info(`Starting 24/7 headless Telegram runner for account ${this.accountId}${proxyInfo}...`);
|
|
27
|
-
this.status = "active";
|
|
28
|
-
}
|
|
29
|
-
async stop() {
|
|
30
|
-
this.logger.info(`Stopping headless Telegram runner for account ${this.accountId}...`);
|
|
31
|
-
this.status = "offline";
|
|
32
|
-
}
|
|
33
|
-
getStatus() {
|
|
34
|
-
return this.status;
|
|
35
|
-
}
|
|
36
|
-
async sendMessage(message) {
|
|
37
|
-
this.logger.info(`Headless Telegram runner sending message ${message.id} to thread ${message.threadId}`);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
receiveIncomingMessage(message) {
|
|
41
|
-
if (this.status !== "active")
|
|
42
|
-
return;
|
|
43
|
-
this.logger.debug(`Telegram runner received message ${message.id} from sender ${message.senderId}`);
|
|
44
|
-
this.messageHandler?.(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.TelegramChannelRunner = TelegramChannelRunner;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IChannelRunner } from "../IChannelRunner";
|
|
2
|
-
import { AccountStatus, PlatformType, UnifiedMessage } from "@zplus/contracts";
|
|
3
|
-
import { ILogger } from "@zplus/core";
|
|
4
|
-
export declare class WhatsAppChannelRunner implements IChannelRunner {
|
|
5
|
-
readonly accountId: string;
|
|
6
|
-
private readonly sessionData?;
|
|
7
|
-
private readonly proxyData?;
|
|
8
|
-
readonly platform: PlatformType;
|
|
9
|
-
private status;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private messageHandler?;
|
|
12
|
-
constructor(accountId: string, sessionData?: Record<string, any> | undefined, proxyData?: Record<string, any> | undefined, logger?: ILogger);
|
|
13
|
-
onMessage(handler: (message: UnifiedMessage) => void): void;
|
|
14
|
-
start(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
getStatus(): AccountStatus;
|
|
17
|
-
sendMessage(message: UnifiedMessage): Promise<boolean>;
|
|
18
|
-
receiveIncomingMessage(message: UnifiedMessage): void;
|
|
19
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WhatsAppChannelRunner = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class WhatsAppChannelRunner {
|
|
6
|
-
accountId;
|
|
7
|
-
sessionData;
|
|
8
|
-
proxyData;
|
|
9
|
-
platform = "whatsapp";
|
|
10
|
-
status = "offline";
|
|
11
|
-
logger;
|
|
12
|
-
messageHandler;
|
|
13
|
-
constructor(accountId, sessionData, proxyData, logger) {
|
|
14
|
-
this.accountId = accountId;
|
|
15
|
-
this.sessionData = sessionData;
|
|
16
|
-
this.proxyData = proxyData;
|
|
17
|
-
this.logger = logger || (0, core_1.createLogger)(`WhatsAppRunner:${accountId}`);
|
|
18
|
-
}
|
|
19
|
-
onMessage(handler) {
|
|
20
|
-
this.messageHandler = handler;
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
const proxyInfo = this.proxyData
|
|
24
|
-
? ` via resident proxy ${this.proxyData.host || this.proxyData.ip || "configured"}`
|
|
25
|
-
: " (direct)";
|
|
26
|
-
this.logger.info(`Starting 24/7 headless WhatsApp runner for account ${this.accountId}${proxyInfo}...`);
|
|
27
|
-
this.status = "active";
|
|
28
|
-
}
|
|
29
|
-
async stop() {
|
|
30
|
-
this.logger.info(`Stopping headless WhatsApp runner for account ${this.accountId}...`);
|
|
31
|
-
this.status = "offline";
|
|
32
|
-
}
|
|
33
|
-
getStatus() {
|
|
34
|
-
return this.status;
|
|
35
|
-
}
|
|
36
|
-
async sendMessage(message) {
|
|
37
|
-
this.logger.info(`Headless WhatsApp runner sending message ${message.id} to thread ${message.threadId}`);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
receiveIncomingMessage(message) {
|
|
41
|
-
if (this.status !== "active")
|
|
42
|
-
return;
|
|
43
|
-
this.logger.debug(`WhatsApp runner received message ${message.id} from sender ${message.senderId}`);
|
|
44
|
-
this.messageHandler?.(message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.WhatsAppChannelRunner = WhatsAppChannelRunner;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { IChannelRunner } from "../IChannelRunner";
|
|
2
|
-
import { AccountStatus, PlatformType, UnifiedMessage } from "@zplus/contracts";
|
|
3
|
-
import { ILogger } from "@zplus/core";
|
|
4
|
-
export declare class ZaloChannelRunner implements IChannelRunner {
|
|
5
|
-
readonly accountId: string;
|
|
6
|
-
private readonly sessionData?;
|
|
7
|
-
private readonly proxyData?;
|
|
8
|
-
readonly platform: PlatformType;
|
|
9
|
-
private status;
|
|
10
|
-
private readonly logger;
|
|
11
|
-
private messageHandler?;
|
|
12
|
-
constructor(accountId: string, sessionData?: Record<string, any> | undefined, proxyData?: Record<string, any> | undefined, logger?: ILogger);
|
|
13
|
-
onMessage(handler: (message: UnifiedMessage) => void): void;
|
|
14
|
-
start(): Promise<void>;
|
|
15
|
-
stop(): Promise<void>;
|
|
16
|
-
getStatus(): AccountStatus;
|
|
17
|
-
sendMessage(message: UnifiedMessage): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Hook nhận tin nhắn từ socket WSS (zca-js/zocial) và bắn qua pipeline
|
|
20
|
-
*/
|
|
21
|
-
receiveIncomingMessage(message: UnifiedMessage): void;
|
|
22
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ZaloChannelRunner = void 0;
|
|
4
|
-
const core_1 = require("@zplus/core");
|
|
5
|
-
class ZaloChannelRunner {
|
|
6
|
-
accountId;
|
|
7
|
-
sessionData;
|
|
8
|
-
proxyData;
|
|
9
|
-
platform = "zalo";
|
|
10
|
-
status = "offline";
|
|
11
|
-
logger;
|
|
12
|
-
messageHandler;
|
|
13
|
-
constructor(accountId, sessionData, proxyData, logger) {
|
|
14
|
-
this.accountId = accountId;
|
|
15
|
-
this.sessionData = sessionData;
|
|
16
|
-
this.proxyData = proxyData;
|
|
17
|
-
this.logger = logger || (0, core_1.createLogger)(`ZaloRunner:${accountId}`);
|
|
18
|
-
}
|
|
19
|
-
onMessage(handler) {
|
|
20
|
-
this.messageHandler = handler;
|
|
21
|
-
}
|
|
22
|
-
async start() {
|
|
23
|
-
const proxyInfo = this.proxyData
|
|
24
|
-
? ` via resident proxy ${this.proxyData.host || this.proxyData.ip || "configured"}`
|
|
25
|
-
: " (direct)";
|
|
26
|
-
this.logger.info(`Starting 24/7 headless Zalo runner for account ${this.accountId}${proxyInfo}...`);
|
|
27
|
-
this.status = "active";
|
|
28
|
-
}
|
|
29
|
-
async stop() {
|
|
30
|
-
this.logger.info(`Stopping headless Zalo runner for account ${this.accountId}...`);
|
|
31
|
-
this.status = "offline";
|
|
32
|
-
}
|
|
33
|
-
getStatus() {
|
|
34
|
-
return this.status;
|
|
35
|
-
}
|
|
36
|
-
async sendMessage(message) {
|
|
37
|
-
this.logger.info(`Headless Zalo runner sending message ${message.id} to thread ${message.threadId}`);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Hook nhận tin nhắn từ socket WSS (zca-js/zocial) và bắn qua pipeline
|
|
42
|
-
*/
|
|
43
|
-
receiveIncomingMessage(message) {
|
|
44
|
-
if (this.status !== "active")
|
|
45
|
-
return;
|
|
46
|
-
this.logger.debug(`Zalo runner received message ${message.id} from sender ${message.senderId}`);
|
|
47
|
-
this.messageHandler?.(message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.ZaloChannelRunner = ZaloChannelRunner;
|
package/dist/cli.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 🏛️ Worker Configuration Loader
|
|
3
|
-
*/
|
|
4
|
-
export interface WorkerEnvironmentConfig {
|
|
5
|
-
workerId: string;
|
|
6
|
-
port: number;
|
|
7
|
-
appwriteEndpoint?: string;
|
|
8
|
-
appwriteProjectId?: string;
|
|
9
|
-
appwriteApiKey?: string;
|
|
10
|
-
databaseId?: string;
|
|
11
|
-
heartbeatIntervalMs: number;
|
|
12
|
-
logLevel: "debug" | "info" | "warn" | "error";
|
|
13
|
-
}
|
|
14
|
-
export declare class WorkerConfig {
|
|
15
|
-
static loadFromEnv(): WorkerEnvironmentConfig;
|
|
16
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* 🏛️ Worker Configuration Loader
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.WorkerConfig = void 0;
|
|
7
|
-
class WorkerConfig {
|
|
8
|
-
static loadFromEnv() {
|
|
9
|
-
return {
|
|
10
|
-
workerId: process.env.WORKER_ID || `worker_${process.pid}`,
|
|
11
|
-
port: Number(process.env.PORT || 8080),
|
|
12
|
-
appwriteEndpoint: process.env.APPWRITE_ENDPOINT,
|
|
13
|
-
appwriteProjectId: process.env.APPWRITE_PROJECT_ID,
|
|
14
|
-
appwriteApiKey: process.env.APPWRITE_API_KEY,
|
|
15
|
-
databaseId: process.env.APPWRITE_DATABASE_ID || "zplus_app",
|
|
16
|
-
heartbeatIntervalMs: Number(process.env.HEARTBEAT_INTERVAL_MS || 30000),
|
|
17
|
-
logLevel: process.env.LOG_LEVEL || "info",
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.WorkerConfig = WorkerConfig;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 🏛️ ZPlus Headless Worker Engine
|
|
3
|
-
* Quản lý vòng đời chạy ngầm 24/7 (WSS listeners, HTTP Ingress, Distributed Lock, Delta Sync, AI automation, Heartbeats)
|
|
4
|
-
*/
|
|
5
|
-
import { WorkerMetrics, ChannelAccount, UnifiedMessage } from "@zplus/contracts";
|
|
6
|
-
import { WorkerEnvironmentConfig } from "../config/WorkerConfig";
|
|
7
|
-
import { ChannelRunnerRegistry } from "../channels/ChannelRunnerRegistry";
|
|
8
|
-
import { DistributedLockManager } from "../lock/DistributedLockManager";
|
|
9
|
-
import { CloudPendingMessageQueue } from "../sync/CloudPendingMessageQueue";
|
|
10
|
-
import { HeadlessAutomationEngine } from "../automation/HeadlessAutomationEngine";
|
|
11
|
-
import { PushNotificationDispatcher } from "../notifications/PushNotificationDispatcher";
|
|
12
|
-
import { WorkerHttpServer } from "../server/WorkerHttpServer";
|
|
13
|
-
import { IChannelRunner } from "../channels/IChannelRunner";
|
|
14
|
-
export declare class WorkerEngine {
|
|
15
|
-
private config;
|
|
16
|
-
private logger;
|
|
17
|
-
readonly channelRunnerRegistry: ChannelRunnerRegistry;
|
|
18
|
-
readonly lockManager: DistributedLockManager;
|
|
19
|
-
readonly deltaQueue: CloudPendingMessageQueue;
|
|
20
|
-
readonly automationEngine: HeadlessAutomationEngine;
|
|
21
|
-
readonly pushDispatcher: PushNotificationDispatcher;
|
|
22
|
-
readonly httpServer: WorkerHttpServer;
|
|
23
|
-
private status;
|
|
24
|
-
private startTime;
|
|
25
|
-
private activeAccounts;
|
|
26
|
-
private messagesProcessed;
|
|
27
|
-
private heartbeatTimer?;
|
|
28
|
-
constructor(config: WorkerEnvironmentConfig);
|
|
29
|
-
start(): Promise<void>;
|
|
30
|
-
stop(): Promise<void>;
|
|
31
|
-
registerRunner(runner: IChannelRunner): void;
|
|
32
|
-
registerAccount(account: ChannelAccount): void;
|
|
33
|
-
unregisterAccount(accountId: string): void;
|
|
34
|
-
recordMessageProcessed(): void;
|
|
35
|
-
handleIncomingMessage(message: UnifiedMessage, runner?: IChannelRunner): Promise<void>;
|
|
36
|
-
getMetrics(): WorkerMetrics;
|
|
37
|
-
private sendHeartbeat;
|
|
38
|
-
}
|