forked from ChickenAI/multizlogin
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathroutes-api.js
More file actions
83 lines (76 loc) · 2.59 KB
/
routes-api.js
File metadata and controls
83 lines (76 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import express from 'express';
import fs from 'fs';
import { apiKeyAuth } from './middleware.js';
import {
findUser,
getUserInfo,
sendFriendRequest,
undoFriendRequest,
sendMessage,
createGroup,
getGroupInfo,
addUserToGroup,
removeUserFromGroup,
sendImageToUser,
sendImagesToUser,
sendImageToGroup,
sendImagesToGroup,
sendFileToUser
} from './zaloService.js';
import { zaloAccounts } from './api/zalo/zalo.js';
const router = express.Router();
// Áp dụng middleware apiKeyAuth cho tất cả các route API
router.use(apiKeyAuth);
// Lấy danh sách tài khoản đã đăng nhập
router.get('/accounts', (req, res) => {
if (zaloAccounts.length === 0) {
return res.json({ success: true, message: 'Chưa có tài khoản nào đăng nhập' });
}
const data = zaloAccounts.map((acc) => ({
ownId: acc.ownId,
proxy: acc.proxy,
phoneNumber: acc.phoneNumber || 'N/A',
}));
res.json(data);
});
router.post('/findUser', findUser);
router.post('/getUserInfo', getUserInfo);
router.post('/sendFriendRequest', sendFriendRequest);
router.post('/sendmessage', sendMessage);
router.post('/createGroup', createGroup);
router.post('/getGroupInfo', getGroupInfo);
router.post('/addUserToGroup', addUserToGroup);
router.post('/removeUserFromGroup', removeUserFromGroup);
router.post('/sendImageToUser', sendImageToUser);
router.post('/sendImagesToUser', sendImagesToUser);
router.post('/sendImageToGroup', sendImageToGroup);
router.post('/sendImagesToGroup', sendImagesToGroup);
router.post('/sendFileToUser', sendFileToUser);
router.post('/undoFriendRequest', undoFriendRequest);
router.get('/health', (req, res) => {
const data = zaloAccounts.map((acc) => ({
ownId: acc.ownId,
status: acc.api ? 'ONLINE' : 'LOGOUT',
phoneNumber: acc.phoneNumber || 'N/A',
}));
res.json({ success: true, accounts: data });
});
router.post('/updateWebhookByAccount', (req, res) => {
const { ownId, url, settings, pullMode } = req.body;
if (!ownId || !url) {
return res.status(400).json({ error: 'ownId và url là bắt buộc' });
}
const multiWebhookPath = '/app/zalo_data/webhooks.json';
let config = {};
if (fs.existsSync(multiWebhookPath)) {
config = JSON.parse(fs.readFileSync(multiWebhookPath, 'utf8'));
}
config[ownId] = {
url,
settings: settings || { receiveReaction: true, receiveGroupEvent: true },
pullMode: pullMode || false
};
fs.writeFileSync(multiWebhookPath, JSON.stringify(config, null, 4), 'utf8');
res.json({ success: true, message: `Webhook cho ${ownId} đã được cập nhật` });
});
export default router;