156 lines
4.5 KiB
TypeScript
156 lines
4.5 KiB
TypeScript
import { requestClient } from '#/api/request';
|
||
|
||
/**
|
||
* OA 通知模块 API
|
||
* 路由前缀统一为 oa-robot/、oa-scene/、oa-platform/、oa-notify-log/、admin-oa-account/
|
||
* 命名规范:get{Entity}List / get{Entity}Option / get{Entity}Info / create{Entity} / update{Entity} / delete{Entity}
|
||
*/
|
||
const prefix = 'oa-robot/';
|
||
|
||
/**
|
||
* 分页查询机器人列表
|
||
*/
|
||
export async function getOaRobotList(data: any) {
|
||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||
}
|
||
|
||
/**
|
||
* 获取机器人详情(含解密后的 webhook_url 和 secret,用于编辑回显)
|
||
*/
|
||
export async function getOaRobotInfo(id: number) {
|
||
return requestClient.get<any>(`${prefix}detail`, { params: { id } });
|
||
}
|
||
|
||
/**
|
||
* 新增机器人
|
||
*/
|
||
export async function createOaRobot(data: Record<string, any>) {
|
||
return requestClient.post<any>(`${prefix}create`, data);
|
||
}
|
||
|
||
/**
|
||
* 编辑机器人
|
||
*/
|
||
export async function updateOaRobot(data: Record<string, any>) {
|
||
return requestClient.post<any>(`${prefix}update`, data);
|
||
}
|
||
|
||
/**
|
||
* 删除机器人(支持批量)
|
||
*/
|
||
export async function deleteOaRobot(data: Record<string, any>) {
|
||
return requestClient.post<any>(`${prefix}delete`, data);
|
||
}
|
||
|
||
/**
|
||
* 测试发送(验证密钥是否正确,不依赖机器人表)
|
||
*
|
||
* 入参说明:
|
||
* - id:行级测试时传入,后端按 id 自动取已加密的 webhook_url/secret(webhook_url/secret 仍可显式传,用于表单内测试)
|
||
* - test_at_all:是否 @ 全员(按平台自动适配:企微/钉钉走 atMobiles,飞书走 atUserIds)
|
||
* - test_mobiles:要 @ 的手机号列表(企微/钉钉有效,飞书 webhook 不支持手机号 @)
|
||
*/
|
||
export async function testSendOaRobot(data: {
|
||
id?: number;
|
||
platform_code: string;
|
||
webhook_url?: string;
|
||
secret?: string;
|
||
corp_id?: string;
|
||
chat_id?: string;
|
||
agent_id?: number;
|
||
use_platform_credential?: number;
|
||
test_content?: string;
|
||
test_at_all?: boolean;
|
||
test_mobiles?: string[];
|
||
test_userids?: string[];
|
||
/** 应用 API:接收员工 userid */
|
||
test_userid?: string;
|
||
/** 应用 API:本地群聊 id(xk_oa_chat.id) */
|
||
test_chat_id?: number;
|
||
/** 应用 API:客户群确认发送人 */
|
||
test_sender_userid?: string;
|
||
/** 按绑定场景发送(只发场景配置的一种类型) */
|
||
scene_id?: number;
|
||
}) {
|
||
return requestClient.post<any>(`${prefix}test-send`, data);
|
||
}
|
||
|
||
/**
|
||
* 查询机器人已绑定的场景列表(测试发送下拉)
|
||
*/
|
||
export async function getOaRobotBoundScenes(id: number) {
|
||
return requestClient.get<{ id: number; scene_code: string; scene_name: string }[]>(
|
||
`${prefix}list-bound-scenes`,
|
||
{ params: { id } },
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 仅同步机器人-群聊绑定关系(用于「未绑定」link 入口和「绑定群聊」按钮)
|
||
* 与 updateOaRobot 区分:本接口不动 name / status / remark 等基础信息
|
||
*/
|
||
export async function updateOaRobotChatBind(data: {
|
||
id: number;
|
||
chat_ids: number[];
|
||
}) {
|
||
return requestClient.post<any>(`${prefix}bind-chats`, data);
|
||
}
|
||
|
||
/**
|
||
* 仅更新 webhook_url 和 secret(用于「改地址」入口)
|
||
*/
|
||
export async function updateOaRobotWebhook(data: {
|
||
id: number;
|
||
webhook_url: string;
|
||
secret?: string;
|
||
}) {
|
||
return requestClient.post<any>(`${prefix}update-webhook`, data);
|
||
}
|
||
|
||
/**
|
||
* 仅更新应用 API 凭证(corp_id / secret / chat_id / agent_id / use_platform_credential)
|
||
*/
|
||
export async function updateOaRobotAppCredential(data: {
|
||
id: number;
|
||
corp_id?: string;
|
||
secret?: string;
|
||
chat_id: string;
|
||
agent_id?: number;
|
||
use_platform_credential?: number;
|
||
}) {
|
||
return requestClient.post<any>(`${prefix}update-app-credential`, data);
|
||
}
|
||
|
||
/**
|
||
* 克隆机器人(复制平台与凭证策略,不复制场景绑定)
|
||
*/
|
||
export async function cloneOaRobot(data: { id: number; name?: string }) {
|
||
return requestClient.post<any>(`${prefix}clone-robot`, data);
|
||
}
|
||
|
||
/**
|
||
* 按平台分组的机器人下拉(克隆源选择用)
|
||
*/
|
||
export async function getOaRobotGroupedByPlatform() {
|
||
return requestClient.get<Record<string, { id: number; name: string }[]>>(
|
||
`${prefix}list-grouped-by-platform`,
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 手动同步应用群聊成员
|
||
*/
|
||
export async function syncOaRobotChatMembers(data: { id: number }) {
|
||
return requestClient.post<any>(`${prefix}sync-chat-members`, data);
|
||
}
|
||
|
||
/**
|
||
* 查询已缓存群成员(单个 id 或批量 robot_ids)
|
||
*/
|
||
export async function getOaRobotChatMembers(params: {
|
||
id?: number;
|
||
robot_ids?: number[] | string;
|
||
}) {
|
||
return requestClient.get<any>(`${prefix}chat-members`, { params });
|
||
}
|