import netTool from "../netTool" const API_KEY = "1dfz4wlpbbgiky0" const URL = "https://lark-egg.ai.xiaomi.com/message" /** * 发送消息到指定的 URL。 * @param {object} body - 消息体。 * @returns {Promise} 一个解析为响应的 promise。 */ const message = async (body: any): Promise => { try { const res = await netTool.post(URL, { api_key: API_KEY, ...body, }) return res } catch { return null } } /** * 通过群组 ID 发送消息。 * @param {string} group_id - 群组 ID。 * @param {string} content - 消息内容。 * @returns {Promise} 一个解析为响应的 promise。 */ message.byGroupId = async (group_id: string, content: string): Promise => { return message({ group_id, msg_type: "interactive", content, }) } /** * 通过聊天 ID 发送消息。 * @param {string} chat_id - 聊天 ID。 * @param {string} content - 消息内容。 * @returns {Promise} 一个解析为响应的 promise。 */ message.byChatId = async (chat_id: string, content: string): Promise => { return message({ receive_id: chat_id, receive_id_type: "chat_id", msg_type: "interactive", content, }) } /** * 通过用户 ID 发送消息。 * @param {string} user_id - 用户 ID。 * @param {string} content - 消息内容。 * @returns {Promise} 一个解析为响应的 promise。 */ message.byUserId = async (user_id: string, content: string): Promise => { return message({ receive_id: user_id, receive_id_type: "user_id", msg_type: "interactive", content, }) } /** * 通过用户 ID 列表发送消息。 * @param {string[]} user_id_list - 用户 ID 列表。 * @param {string} content - 消息内容。 * @param {string} [api_key] - 可选的 API 密钥。 * @returns {Promise} 一个解析为响应的 promise。 */ message.byUserIdList = async ( user_id_list: string[], content: string, api_key?: string ): Promise => { return message({ receive_id: user_id_list.join(","), receive_id_type: "user_id", msg_type: "interactive", content, api_key, }) } export default message