agent.ts
7.44 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import http, { type ApiResponse } from './client';
/* ---------- Agent CRUD ---------- */
export interface CreateAgentPayload {
name: string;
description?: string;
position_ids: number[];
skill_codes: string[];
managed_user_id: string;
status?: 'enable' | 'disable';
is_steward?: boolean;
}
export interface CreateAgentResult {
agent_id: number;
name: string;
}
export async function createAgent(payload: CreateAgentPayload): Promise<CreateAgentResult> {
const res = await http.post<ApiResponse<CreateAgentResult>>('/agents', payload);
return res.data.data;
}
/* ---------- Steward Check ---------- */
export interface StewardCheckResult {
exists: boolean;
agent_id: number | null;
name: string | null;
}
export async function checkStewardExists(): Promise<StewardCheckResult> {
const res = await http.get<ApiResponse<StewardCheckResult>>('/agents/steward/check');
return res.data.data;
}
/* ---------- Position Tags ---------- */
export interface PositionTagItem {
tag_id: number;
name: string;
code: string;
agent_count: number;
description?: string | null;
created_at: string;
}
export interface PositionTagListData {
total: number;
list: PositionTagItem[];
}
export async function getPositionTags(pageSize = 100): Promise<PositionTagItem[]> {
const res = await http.get<ApiResponse<PositionTagListData>>('/position-tags', {
params: { page: 1, page_size: pageSize },
});
return res.data.data.list;
}
/* ---------- Skills ---------- */
export interface SkillItem {
skill_code: string;
skill_name: string;
description?: string | null;
}
export interface SkillListData {
total: number;
list: SkillItem[];
}
export async function getSkills(pageSize = 100): Promise<SkillItem[]> {
const res = await http.get<ApiResponse<SkillListData>>('/skills', {
params: { page: 1, page_size: pageSize },
});
return res.data.data.list;
}
/* ---------- Employee Mounts ---------- */
export interface EmployeeItem {
employee_id: string;
employee_name: string;
wechat_user_id: string;
agent_count: number;
}
export interface EmployeeMountsData {
employee_count: number;
employees: EmployeeItem[];
}
export async function getEmployeeMounts(): Promise<EmployeeItem[]> {
const res = await http.get<ApiResponse<EmployeeMountsData>>('/agent-group/employees/mounts');
return res.data.data.employees;
}
/* ---------- Bot QR Code ---------- */
export interface BotQrcodeItem {
bot_id: string;
bot_name: string;
has_qrcode: boolean;
qrcode_url: string | null;
}
export interface BotQrcodeListData {
total: number;
bots: BotQrcodeItem[];
}
export async function listBotsQrcode(): Promise<BotQrcodeItem[]> {
const res = await http.get<ApiResponse<BotQrcodeListData>>('/agent-group/bots');
return res.data.data.bots;
}
export interface UploadMediaResult {
file_url: string;
cdn_url: string;
file_type: string;
file_size: number;
width?: number | null;
height?: number | null;
}
export async function uploadMedia(file: File): Promise<UploadMediaResult> {
const form = new FormData();
form.append('usage_type', 'agent_icon');
form.append('file', file);
const res = await http.post<ApiResponse<UploadMediaResult>>('/official-site/upload', form);
return res.data.data;
}
export interface SaveQrcodeResult {
employee_id: string;
qrcode_url: string;
updated_at: string;
}
export async function saveEmployeeQrcode(employeeId: string, qrcodeUrl: string): Promise<SaveQrcodeResult> {
const res = await http.put<ApiResponse<SaveQrcodeResult>>(
`/agent-group/employee/${employeeId}/qrcode`,
{ qrcode_url: qrcodeUrl },
);
return res.data.data;
}
/* ---------- Skill ---------- */
export interface SkillDetailResult {
skill_code: string;
skill_name: string;
description?: string | null;
doc_markdown?: string | null;
}
export async function createSkill(payload: CreateSkillPayload): Promise<SkillDetailResult> {
const res = await http.post<ApiResponse<SkillDetailResult>>('/skills', payload);
return res.data.data;
}
export interface CreateSkillPayload {
skill_code: string;
skill_name: string;
description?: string;
doc_markdown?: string;
priority?: number;
}
/** 上传 zip 创建 Skill(zip 内文件夹名 = skill_code) */
export async function uploadSkillZip(
file: File,
skillName: string,
priority: number,
): Promise<SkillDetailResult> {
const form = new FormData();
form.append('file', file);
form.append('skill_name', skillName);
form.append('priority', String(priority));
const res = await http.post<ApiResponse<SkillDetailResult>>('/skills/upload', form);
return res.data.data;
}
/* ---------- Scan Skills ---------- */
export interface ScanSkillResult {
skill_code: string;
skill_name: string;
status: 'imported' | 'skipped';
}
export interface ScanSkillsResponse {
total: number;
scanned: number;
imported: number;
skipped: number;
results: ScanSkillResult[];
}
/** 扫描 skills/ 目录,同步未入库的 skill */
export async function scanSkills(): Promise<ScanSkillsResponse> {
const res = await http.post<ApiResponse<ScanSkillsResponse>>('/skills/scan');
return res.data.data;
}
/* ---------- Customer Groups ---------- */
export interface CustomerGroupItem {
id: number;
customer_contact_id: string;
customer_name: string | null;
bot_id: string;
bot_code: string;
bot_name: string | null;
group_id: string | null;
group_name: string | null;
group_status: string;
member_bot_ids: string[];
member_bot_names: string[];
is_deleted: boolean;
created_at: string;
updated_at: string;
}
export interface CustomerGroupListData {
total: number;
page: number;
page_size: number;
list: CustomerGroupItem[];
status_counts: Record<string, number>;
}
export async function listCustomerGroups(params: {
page?: number;
page_size?: number;
keyword?: string;
status?: string;
}): Promise<CustomerGroupListData> {
const res = await http.get<ApiResponse<CustomerGroupListData>>('/customer-groups', { params });
return res.data.data;
}
/** 软删除客户群记录 */
export async function deleteCustomerGroup(id: number): Promise<void> {
await http.delete(`/customer-groups/${id}`);
}
/* ---------- Group Messages ---------- */
export interface GroupMessageItem {
id: number;
msg_id: string;
msg_time: string;
msg_type: string | null;
msg_content: string | null;
sender_id: string | null;
sender_name: string | null;
session_title: string | null;
bot_send: boolean;
bot_id: string;
bot_code: string;
created_at: string;
}
export async function listGroupMessages(
groupId: number,
params: { page?: number; page_size?: number } = {},
): Promise<GroupMessageItem[]> {
const res = await http.get<ApiResponse<GroupMessageItem[]>>(`/customer-groups/${groupId}/messages`, { params });
return res.data.data;
}
/* ---------- Customer Group Stats ---------- */
export interface DailyCount {
date: string;
count: number;
}
export interface ActiveGroupRank {
group_id: number;
group_name: string | null;
bot_id: string;
message_count: number;
}
export interface CustomerGroupStats {
total_groups: number;
total_messages: number;
total_active_groups: number;
daily_message_counts: DailyCount[];
daily_new_groups: DailyCount[];
top_active_groups: ActiveGroupRank[];
}
export async function getCustomerGroupStats(days: number = 30): Promise<CustomerGroupStats> {
const res = await http.get<ApiResponse<CustomerGroupStats>>('/customer-groups/stats', { params: { days } });
return res.data.data;
}