Skip to content

Commit 90cc4de

Browse files
author
lrhh123
committed
feat: 优化各个平台的独立配置功能;添加关闭自动回复,只使用关键词回复的功能;添加延时随机时间
1 parent a9130bc commit 90cc4de

File tree

27 files changed

+965
-520
lines changed

27 files changed

+965
-520
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module.exports = {
2828
'@typescript-eslint/no-unused-vars': 'error',
2929
'no-console': 'off',
3030
'max-classes-per-file': 'off',
31+
'no-continue': 'off',
32+
'no-plusplus': 'off',
3133
},
3234
parserOptions: {
3335
ecmaVersion: 2022,

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@
118118
- [x] 支持千牛平台的基础聊天功能
119119
- [x] 支持京麦平台的基础聊天功能
120120
- [ ] 支持多平台文章自动发送功能
121-
- [ ] 添加关闭自动回复,只使用关键词回复的功能
122-
- [ ] 添加延时随机时间
123-
- [ ] 优化各个平台的独立配置功能
121+
- [x] 添加关闭自动回复,只使用关键词回复的功能
122+
- [x] 添加延时随机时间
123+
- [x] 优化各个平台的独立配置功能
124124
- [x] 支持 Excel 导入回复内容
125-
- [ ] 支持导出回复内容到 Excel
125+
- [x] 支持导出回复内容到 Excel
126126
- [ ] 支持导出聊天记录到 Excel
127-
- [ ] 添加中文路径的支持
127+
- [x] 添加中文路径的支持
128+
- [ ] 实现小红书回复后,自动私聊的功能
128129
- [ ] 优化微信平台的回复速度
129130
- [ ] 支持企业微信外部群聊天功能
130131
- [ ] 支持企业微信自动加人功能

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"@emotion/styled": "^11.11.0",
102102
"@hw-hmscore/analytics-web": "6.9.9-301",
103103
"@tanstack/react-query": "4.36.1",
104+
"@types/lodash": "^4.17.1",
104105
"ansi-styles": "^6.2.1",
105106
"axios": "^1.6.7",
106107
"body-parser": "^1.20.2",

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/backend/backend.ts

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ class BKServer {
6868
transports: ['websocket'],
6969
});
7070

71-
this.messageService = new MessageService(
72-
configController,
73-
messageController,
74-
autoReplyController,
75-
);
7671
this.configService = new ConfigService(
7772
configController,
7873
platformConfigController,
7974
);
75+
76+
this.messageService = new MessageService(
77+
this.configService,
78+
messageController,
79+
autoReplyController,
80+
);
81+
8082
this.broadcastService = new BroadcastService(mainWindow);
8183
this.strategyService = new StrategyService(this.io);
8284
this.sessionService = new SessionService(
@@ -173,22 +175,20 @@ class BKServer {
173175

174176
// 获取平台设置
175177
this.app.get(
176-
'/api/v1/base/platform/settings',
178+
'/api/v1/base/platform/setting',
177179
asyncHandler(async (req, res) => {
178-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
179-
const { total, data } = await platformConfigController.list({
180-
page: 1,
181-
pageSize: 100,
182-
});
183-
res.json({ success: true, data });
180+
const { platformId } = req.query;
181+
// @ts-ignore
182+
const obj = await platformConfigController.getByPlatformId(platformId);
183+
res.json({ success: true, data: obj.settings });
184184
}),
185185
);
186186

187187
this.app.post(
188-
'/api/v1/base/platform/settings',
188+
'/api/v1/base/platform/setting',
189189
asyncHandler(async (req, res) => {
190-
const { platform_id: platformId, config } = req.body;
191-
await platformConfigController.updateByPlatformId(platformId, config);
190+
const { platformId, settings } = req.body;
191+
await platformConfigController.updateByPlatformId(platformId, settings);
192192
res.json({ success: true });
193193
}),
194194
);
@@ -198,6 +198,7 @@ class BKServer {
198198
const {
199199
is_paused: isPaused,
200200
is_keyword_match: isKeywordMatch,
201+
is_use_gpt: isUseGptReply,
201202
ids,
202203
} = req.body;
203204
try {
@@ -212,7 +213,7 @@ class BKServer {
212213
}
213214

214215
if (isKeywordMatch) {
215-
this.messageService.updateKeywordMatch(isKeywordMatch);
216+
this.messageService.updateKeywordMatch(isKeywordMatch, isUseGptReply);
216217
}
217218

218219
await this.strategyService.updateStrategies(ids);
@@ -229,6 +230,8 @@ class BKServer {
229230
this.app.get('/api/v1/base/settings', async (req, res) => {
230231
try {
231232
const config = await configController.getConfig();
233+
// @ts-ignore 兼容性处理
234+
config.reply_speed = [config.reply_speed, config.reply_random_speed];
232235
res.json({ success: true, data: config });
233236
} catch (error) {
234237
if (error instanceof Error) {
@@ -240,9 +243,44 @@ class BKServer {
240243
// Endpoint to update configuration settings
241244
this.app.post('/api/v1/base/settings', async (req, res) => {
242245
try {
243-
const cfg = req.body;
244-
await configController.updateConfig(1, cfg); // Assuming the ID is known and static
245-
// globalVariable.merged_message_num = cfg.merged_message_num;
246+
const cfg = req.body as {
247+
extract_phone: boolean; // 提取手机号
248+
extract_product: boolean; // 提取商品
249+
save_path?: string; // 保存路径
250+
default_reply?: string; // 默认回复
251+
reply_speed: number[]; // 回复速度
252+
context_count: number; // 合并消息数量
253+
wait_humans_time: number; // 等待人工时间
254+
gpt_base_url?: string; // GPT服务地址
255+
gpt_key?: string; // GPT服务key
256+
gpt_model?: string; // GPT服务模型
257+
gpt_temperature?: number; // GPT服务温度
258+
gpt_top_p?: number; // GPT服务top_p
259+
stream?: boolean; // 是否开启stream
260+
use_dify?: boolean; // 是否使用 Dify 百宝箱
261+
};
262+
263+
if (!cfg.reply_speed || cfg.reply_speed.length !== 2) {
264+
cfg.reply_speed = [0, 0];
265+
}
266+
267+
await configController.updateConfig(1, {
268+
extract_phone: cfg.extract_phone,
269+
extract_product: cfg.extract_product,
270+
default_reply: cfg.default_reply,
271+
save_path: cfg.save_path,
272+
reply_speed: cfg.reply_speed[0],
273+
reply_random_speed: cfg.reply_speed[1],
274+
context_count: cfg.context_count,
275+
wait_humans_time: cfg.wait_humans_time,
276+
gpt_base_url: cfg.gpt_base_url,
277+
gpt_key: cfg.gpt_key,
278+
gpt_model: cfg.gpt_model,
279+
gpt_temperature: cfg.gpt_temperature,
280+
gpt_top_p: cfg.gpt_top_p,
281+
stream: cfg.stream,
282+
use_dify: cfg.use_dify,
283+
});
246284
res.json({ success: true });
247285
} catch (error) {
248286
if (error instanceof Error) {

src/main/backend/controllers/configController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export class ConfigController {
1515
extract_product: true,
1616
save_path: '',
1717
reply_speed: 0,
18-
merged_message_num: 7,
18+
reply_random_speed: 0,
19+
default_reply: '',
1920
wait_humans_time: 60,
21+
context_count: 1,
2022
gpt_base_url: 'https://api.openai.com/v1',
2123
gpt_key: 'your-key',
2224
gpt_model: 'gpt-3.5-turbo',

src/main/backend/controllers/platformConfigController.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@ import { PlatformConfig } from '../entities/platformConfig';
33
export class PlatformConfigController {
44
async updateByPlatformId(
55
platformId: string,
6-
platformConfigData: Partial<PlatformConfig>,
6+
settings: any,
77
): Promise<PlatformConfig> {
88
const platformConfig = await PlatformConfig.findOne({
99
where: { platform_id: platformId },
1010
});
1111

12+
const active = settings && settings.active ? settings.active : false;
13+
1214
if (platformConfig) {
1315
// @ts-ignore
14-
return this.update(platformConfig.id, platformConfigData);
16+
return this.update(platformConfig.id, { settings, active });
1517
}
18+
1619
return this.create({
1720
platform_id: platformId,
18-
...platformConfigData,
21+
settings,
22+
active,
1923
});
2024
}
2125

2226
async getByPlatformId(platformId: string) {
23-
const data = await PlatformConfig.findOne({
27+
let data = await PlatformConfig.findOne({
2428
where: { platform_id: platformId },
2529
});
2630

2731
if (!data) {
28-
throw new Error('PlatformConfig not found');
32+
// 创建一个对象
33+
data = await PlatformConfig.create({
34+
platform_id: platformId,
35+
active: false,
36+
settings: {},
37+
});
2938
}
3039

3140
return data;
@@ -40,9 +49,11 @@ export class PlatformConfigController {
4049
const platformConfig = await PlatformConfig.findOne({
4150
where: { id },
4251
});
43-
// @ts-ignore
44-
const data = Object.assign(platformConfig, platformConfigData);
45-
return data;
52+
if (!platformConfig) {
53+
return;
54+
}
55+
56+
await platformConfig.update(platformConfigData);
4657
}
4758

4859
async delete(id: number): Promise<void> {
@@ -54,18 +65,4 @@ export class PlatformConfigController {
5465
}
5566
await platformConfig.destroy();
5667
}
57-
58-
async list(page: { page: number; pageSize: number }): Promise<{
59-
total: number;
60-
data: PlatformConfig[];
61-
}> {
62-
const data = await PlatformConfig.findAll({
63-
limit: page.pageSize,
64-
offset: (page.page - 1) * page.pageSize,
65-
});
66-
67-
const total = await PlatformConfig.count();
68-
69-
return { total, data };
70-
}
7168
}

0 commit comments

Comments
 (0)