botforje 0.0.1
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/LICENSE +21 -0
- package/README.md +381 -0
- package/dist/action/action.js +44 -0
- package/dist/action/catalog.js +40 -0
- package/dist/action/cooldown.js +60 -0
- package/dist/action/executor.js +23 -0
- package/dist/action/template.js +13 -0
- package/dist/action/types.js +2 -0
- package/dist/action/webhook.js +36 -0
- package/dist/actions/action.js +26 -0
- package/dist/actions/cooldown.js +66 -0
- package/dist/actions/request.js +40 -0
- package/dist/api/routes/auth.js +56 -0
- package/dist/api/routes/bots.js +51 -0
- package/dist/api/routes/config.js +24 -0
- package/dist/api/routes/health.js +15 -0
- package/dist/api/routes/index.js +14 -0
- package/dist/api/routes/messages.js +69 -0
- package/dist/api/routes/sessions.js +97 -0
- package/dist/api/routes/status.js +38 -0
- package/dist/api/server.js +153 -0
- package/dist/auth/service.js +102 -0
- package/dist/boot/fleet.js +207 -0
- package/dist/bot/bot.js +30 -0
- package/dist/bot/fleet.js +211 -0
- package/dist/bot/fuzzy.js +20 -0
- package/dist/bot/mapper.js +47 -0
- package/dist/bot/types.js +2 -0
- package/dist/bot/validation.js +38 -0
- package/dist/bot.js +31 -0
- package/dist/cli/create-bot.js +84 -0
- package/dist/cli.js +138 -0
- package/dist/commands/auth.js +200 -0
- package/dist/commands/create-bot.js +64 -0
- package/dist/commands/guide.js +563 -0
- package/dist/commands/lock.js +73 -0
- package/dist/commands/status.js +145 -0
- package/dist/commands/unlock.js +88 -0
- package/dist/commands/validate.js +19 -0
- package/dist/config/mapper.js +152 -0
- package/dist/config/schema.js +2 -0
- package/dist/config/validation.js +705 -0
- package/dist/config/watcher.js +145 -0
- package/dist/config/yaml.js +197 -0
- package/dist/fleet.js +247 -0
- package/dist/flow/executor.js +286 -0
- package/dist/flow/flow.js +2 -0
- package/dist/flow/mapper.js +72 -0
- package/dist/flow/state.js +115 -0
- package/dist/flow/types.js +2 -0
- package/dist/graph/executor.js +294 -0
- package/dist/graph/graph.js +2 -0
- package/dist/graph/state.js +118 -0
- package/dist/helpers/data.js +42 -0
- package/dist/helpers/fuzzy.js +30 -0
- package/dist/helpers/logger.js +89 -0
- package/dist/helpers/validation.js +38 -0
- package/dist/index.js +92 -0
- package/dist/messages/contracts.js +2 -0
- package/dist/messages/inbox.js +58 -0
- package/dist/messages/outbox.js +136 -0
- package/dist/services/auto-response.js +62 -0
- package/dist/services/cooldown.js +60 -0
- package/dist/services/fleet.js +207 -0
- package/dist/services/flow-executor.js +195 -0
- package/dist/services/flow-state.js +118 -0
- package/dist/services/inbox.js +50 -0
- package/dist/services/message-handler.js +78 -0
- package/dist/services/message-queue.js +138 -0
- package/dist/services/outbox.js +138 -0
- package/dist/services/session.js +118 -0
- package/dist/services/webhook.js +87 -0
- package/dist/utils/logger.js +89 -0
- package/dist/utils/webhook.js +36 -0
- package/dist/validation/validate.js +592 -0
- package/dist/whatsapp/client.js +293 -0
- package/dist/whatsapp/session.js +158 -0
- package/dist/whatsapp/types.js +109 -0
- package/dist/whatsapp/whatsapp.js +109 -0
- package/package.json +97 -0
- package/scripts/postinstall.js +45 -0
- package/scripts/preuninstall.js +48 -0
- package/scripts/setup-systemd.js +91 -0
- package/service/botforje.service.template +25 -0
|
@@ -0,0 +1,145 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runStatus = runStatus;
|
|
37
|
+
const http = __importStar(require("http"));
|
|
38
|
+
const yaml_1 = require("../config/yaml");
|
|
39
|
+
async function getApiBase(configPath) {
|
|
40
|
+
try {
|
|
41
|
+
if (configPath)
|
|
42
|
+
(0, yaml_1.setConfigPath)(configPath);
|
|
43
|
+
const config = await (0, yaml_1.loadConfig)(configPath);
|
|
44
|
+
const apiPort = config.port || 3000;
|
|
45
|
+
return `http://localhost:${apiPort}`;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return 'http://localhost:3000';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function apiGet(path, apiBase) {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const urlObj = new URL(path, apiBase);
|
|
54
|
+
const options = {
|
|
55
|
+
hostname: urlObj.hostname,
|
|
56
|
+
port: urlObj.port,
|
|
57
|
+
path: urlObj.pathname,
|
|
58
|
+
method: 'GET',
|
|
59
|
+
};
|
|
60
|
+
const req = http.request(options, (res) => {
|
|
61
|
+
let data = '';
|
|
62
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
63
|
+
res.on('end', () => {
|
|
64
|
+
try {
|
|
65
|
+
resolve({ status: res.statusCode, data: JSON.parse(data) });
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
resolve({ status: res.statusCode, data });
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
req.on('error', (err) => {
|
|
73
|
+
if (err.code === 'ECONNREFUSED') {
|
|
74
|
+
reject(new Error('Daemon is not running. Start it with: botforje daemon'));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
reject(err);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
req.end();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function stateToSymbol(state) {
|
|
84
|
+
switch (state) {
|
|
85
|
+
case 'connected': return '\u{1F7E2}';
|
|
86
|
+
case 'qr_received': return '\u{1F7E0}';
|
|
87
|
+
case 'pending': return '\u{1F535}';
|
|
88
|
+
case 'disconnected': return '\u{1F534}';
|
|
89
|
+
case 'auth_failure': return '\u{1F534}';
|
|
90
|
+
default: return '\u26AA';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function stateLabel(state) {
|
|
94
|
+
switch (state) {
|
|
95
|
+
case 'connected': return 'connected';
|
|
96
|
+
case 'qr_received': return 'awaiting QR';
|
|
97
|
+
case 'pending': return 'pending';
|
|
98
|
+
case 'disconnected': return 'disconnected';
|
|
99
|
+
case 'auth_failure': return 'auth failed';
|
|
100
|
+
default: return 'unknown';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function runStatus(configPath) {
|
|
104
|
+
try {
|
|
105
|
+
if (configPath)
|
|
106
|
+
(0, yaml_1.setConfigPath)(configPath);
|
|
107
|
+
const apiBase = await getApiBase(configPath);
|
|
108
|
+
const result = await apiGet('/api/status', apiBase);
|
|
109
|
+
if (result.status !== 200) {
|
|
110
|
+
console.error(`Error: ${result.data?.error || 'Unknown error'}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
const bots = result.data?.bots || [];
|
|
114
|
+
if (bots.length === 0) {
|
|
115
|
+
console.log('No bots configured.');
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
console.log('\nBot Status:');
|
|
119
|
+
console.log('─'.repeat(60));
|
|
120
|
+
for (const bot of bots) {
|
|
121
|
+
const session = bot.session;
|
|
122
|
+
const state = session?.state || 'none';
|
|
123
|
+
const symbol = stateToSymbol(state);
|
|
124
|
+
const label = stateLabel(state);
|
|
125
|
+
const phone = bot.phone || session?.phone || '-';
|
|
126
|
+
const graph = bot.graph || '-';
|
|
127
|
+
console.log(` ${symbol} ${bot.id}`);
|
|
128
|
+
console.log(` State: ${label}`);
|
|
129
|
+
console.log(` Phone: ${phone}`);
|
|
130
|
+
console.log(` Graph: ${graph}`);
|
|
131
|
+
console.log('');
|
|
132
|
+
}
|
|
133
|
+
console.log(`Total: ${bots.length} bot(s) configured`);
|
|
134
|
+
console.log('');
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error.message?.includes('Daemon is not running')) {
|
|
138
|
+
console.error(`\n${error.message}`);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
console.error(`\nError: ${error.message || error}`);
|
|
142
|
+
}
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.runUnlock = runUnlock;
|
|
37
|
+
const readline = __importStar(require("readline"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const service_1 = require("../auth/service");
|
|
41
|
+
const yaml_1 = require("../config/yaml");
|
|
42
|
+
const data_1 = require("../helpers/data");
|
|
43
|
+
function promptHidden(query) {
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout,
|
|
47
|
+
});
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
rl.question(query, (answer) => {
|
|
50
|
+
rl.close();
|
|
51
|
+
resolve(answer);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function runUnlock(key, configPath) {
|
|
56
|
+
try {
|
|
57
|
+
if (configPath)
|
|
58
|
+
(0, yaml_1.setConfigPath)(configPath);
|
|
59
|
+
await (0, yaml_1.loadConfig)(configPath);
|
|
60
|
+
const dataDir = (0, data_1.getDataDir)();
|
|
61
|
+
fs.mkdirSync(dataDir, { recursive: true });
|
|
62
|
+
const dbPath = path.join(dataDir, 'botforje.db');
|
|
63
|
+
const auth = new service_1.AuthService(dbPath);
|
|
64
|
+
if (!auth.isLocked()) {
|
|
65
|
+
console.log('Botforje is not locked. Nothing to do.');
|
|
66
|
+
process.exit(0);
|
|
67
|
+
}
|
|
68
|
+
const providedKey = key || await promptHidden('Enter current auth key: ');
|
|
69
|
+
if (!providedKey) {
|
|
70
|
+
console.error('Key is required.');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
const success = auth.unlock(providedKey);
|
|
74
|
+
if (success) {
|
|
75
|
+
console.log('\nBotforje unlocked successfully. Auth is no longer required.');
|
|
76
|
+
console.log('All active sessions have been invalidated.\n');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.error('\nInvalid key. Unlock failed.\n');
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error(`\nError: ${error.message || error}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runValidate = runValidate;
|
|
4
|
+
const validation_1 = require("../config/validation");
|
|
5
|
+
const yaml_1 = require("../config/yaml");
|
|
6
|
+
async function runValidate(configPath) {
|
|
7
|
+
if (configPath)
|
|
8
|
+
(0, yaml_1.setConfigPath)(configPath);
|
|
9
|
+
const result = await (0, validation_1.validateConfig)(configPath);
|
|
10
|
+
if (result.valid) {
|
|
11
|
+
console.log('Config OK');
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
for (const err of result.errors) {
|
|
15
|
+
const location = err.line ? `${err.file}:${err.line}` : err.file;
|
|
16
|
+
console.log(`${location}: ${err.message}`);
|
|
17
|
+
}
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapActionCatalog = mapActionCatalog;
|
|
4
|
+
exports.mapGraphCatalog = mapGraphCatalog;
|
|
5
|
+
exports.mapBotsFromConfig = mapBotsFromConfig;
|
|
6
|
+
exports.mapConfigToBot = mapConfigToBot;
|
|
7
|
+
exports.mapSettings = mapSettings;
|
|
8
|
+
const bot_1 = require("../bot");
|
|
9
|
+
const validation_1 = require("./validation");
|
|
10
|
+
function mapActionCatalog(config) {
|
|
11
|
+
const catalog = new Map();
|
|
12
|
+
for (const [id, actionConfig] of Object.entries(config)) {
|
|
13
|
+
catalog.set(id, mapAction(id, actionConfig));
|
|
14
|
+
}
|
|
15
|
+
return catalog;
|
|
16
|
+
}
|
|
17
|
+
function mapAction(id, config) {
|
|
18
|
+
const hasSteps = (config.steps?.length ?? 0) > 0;
|
|
19
|
+
const hasOnBlocked = (config.guards?.cooldown?.on_blocked?.length ?? 0) > 0;
|
|
20
|
+
if (!hasSteps && !hasOnBlocked) {
|
|
21
|
+
throw new Error(`Action "${id}" must define steps or a cooldown guard with on_blocked`);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
id,
|
|
25
|
+
guards: config.guards ? mapGuards(config.guards) : undefined,
|
|
26
|
+
steps: (config.steps ?? []).map(mapStep),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mapStep(config) {
|
|
30
|
+
if (config.message)
|
|
31
|
+
return { message: mapMessage(config.message) };
|
|
32
|
+
if (config.request)
|
|
33
|
+
return { request: mapRequestStep(config.request) };
|
|
34
|
+
return { location: mapLocationAction(config.location) };
|
|
35
|
+
}
|
|
36
|
+
function mapMessage(config) {
|
|
37
|
+
return {
|
|
38
|
+
body: config.body,
|
|
39
|
+
to: config.to,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function mapGuards(config) {
|
|
43
|
+
const result = {};
|
|
44
|
+
if (config.cooldown) {
|
|
45
|
+
result.cooldown = {
|
|
46
|
+
duration: config.cooldown.duration,
|
|
47
|
+
onBlocked: config.cooldown.on_blocked?.map(mapStep),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function mapRequestStep(config) {
|
|
53
|
+
return {
|
|
54
|
+
name: config.name,
|
|
55
|
+
url: config.url,
|
|
56
|
+
method: config.method ?? 'POST',
|
|
57
|
+
headers: config.headers ?? {},
|
|
58
|
+
timeout: config.timeout ?? 5000,
|
|
59
|
+
retries: config.retry ?? 3,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function mapLocationAction(config) {
|
|
63
|
+
return {
|
|
64
|
+
latitude: config.latitude,
|
|
65
|
+
longitude: config.longitude,
|
|
66
|
+
name: config.name,
|
|
67
|
+
address: config.address,
|
|
68
|
+
url: config.url,
|
|
69
|
+
description: config.description,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function mapGraphCatalog(config) {
|
|
73
|
+
const catalog = new Map();
|
|
74
|
+
for (const [id, graphConfig] of Object.entries(config)) {
|
|
75
|
+
catalog.set(id, mapGraph(id, graphConfig));
|
|
76
|
+
}
|
|
77
|
+
return catalog;
|
|
78
|
+
}
|
|
79
|
+
function mapGraph(id, config) {
|
|
80
|
+
if (!config.nodes[config.root]) {
|
|
81
|
+
throw new Error(`Graph "${id}" root node "${config.root}" not found`);
|
|
82
|
+
}
|
|
83
|
+
const nodes = {};
|
|
84
|
+
for (const [nodeId, nodeConfig] of Object.entries(config.nodes)) {
|
|
85
|
+
nodes[nodeId] = mapNode(nodeConfig);
|
|
86
|
+
}
|
|
87
|
+
if (config.fallback && !nodes[config.fallback]) {
|
|
88
|
+
throw new Error(`Graph "${id}" fallback node "${config.fallback}" not found`);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
id,
|
|
92
|
+
root: config.root,
|
|
93
|
+
timeout: config.timeout,
|
|
94
|
+
fallbackNode: config.fallback,
|
|
95
|
+
nodes,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function mapNode(config) {
|
|
99
|
+
return {
|
|
100
|
+
action: config.action,
|
|
101
|
+
edges: (config.edges || []).map(mapEdge),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function mapEdge(config) {
|
|
105
|
+
return {
|
|
106
|
+
match: config.match ? mapMatch(config.match) : undefined,
|
|
107
|
+
fuzzyThreshold: config.fuzzy_threshold,
|
|
108
|
+
goto: config.goto,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function mapMatch(match) {
|
|
112
|
+
if (typeof match === 'string') {
|
|
113
|
+
return splitPhrases(match);
|
|
114
|
+
}
|
|
115
|
+
return match.flatMap(splitPhrases);
|
|
116
|
+
}
|
|
117
|
+
function splitPhrases(value) {
|
|
118
|
+
return value
|
|
119
|
+
.split(',')
|
|
120
|
+
.map(s => s.trim())
|
|
121
|
+
.filter(s => s.length > 0);
|
|
122
|
+
}
|
|
123
|
+
function mapBotsFromConfig(configs) {
|
|
124
|
+
return Object.entries(configs).map(([id, config]) => mapConfigToBot(id, config));
|
|
125
|
+
}
|
|
126
|
+
function mapConfigToBot(id, config) {
|
|
127
|
+
(0, validation_1.validateId)(id, 'Bot');
|
|
128
|
+
const settings = config.settings ? mapSettings(config.settings) : (0, bot_1.createDefaultSettings)();
|
|
129
|
+
const graph = config.graph ?? '';
|
|
130
|
+
return (0, bot_1.createBot)({
|
|
131
|
+
id,
|
|
132
|
+
settings,
|
|
133
|
+
graph,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function mapSettings(config) {
|
|
137
|
+
if (config.typing_delay !== undefined) {
|
|
138
|
+
(0, validation_1.validateTypingDelay)(config.typing_delay);
|
|
139
|
+
}
|
|
140
|
+
if (config.queue_delay !== undefined) {
|
|
141
|
+
(0, validation_1.validateQueueDelay)(config.queue_delay);
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
simulateTyping: config.simulate_typing ?? true,
|
|
145
|
+
typingDelay: config.typing_delay ?? 1000,
|
|
146
|
+
queueDelay: config.queue_delay ?? 1000,
|
|
147
|
+
readReceipts: config.read_receipts ?? true,
|
|
148
|
+
ignoreGroups: config.ignore_groups ?? true,
|
|
149
|
+
allowedSenders: (config.allowed_senders || []).map(String),
|
|
150
|
+
ignoredSenders: (config.ignored_senders || []).map(String),
|
|
151
|
+
};
|
|
152
|
+
}
|