feat: 支持主动发送消息和附件处理

新增 `sendProactiveC2CMessage` 和 `sendProactiveGroupMessage` API,支持无需 msg_id 的主动消息发送(有月限额)。在网关中增加附件处理逻辑,支持解析图片和普通附件,并将附件信息传递给上下文。同时优化了 `sendText` 的目标地址解析逻辑,支持 `group:` 和 `channel:` 前缀,并新增 `sendProactiveMessage` 方法。
This commit is contained in:
sliverp
2026-01-29 16:17:06 +08:00
parent af31a001e9
commit 869519de7c
4 changed files with 170 additions and 10 deletions

View File

@@ -160,3 +160,31 @@ export async function sendGroupMessage(
...(msgId ? { msg_id: msgId } : {}),
});
}
/**
* 主动发送 C2C 单聊消息(不需要 msg_id每月限 4 条/用户)
*/
export async function sendProactiveC2CMessage(
accessToken: string,
openid: string,
content: string
): Promise<{ id: string; timestamp: number }> {
return apiRequest(accessToken, "POST", `/v2/users/${openid}/messages`, {
content,
msg_type: 0,
});
}
/**
* 主动发送群聊消息(不需要 msg_id每月限 4 条/群)
*/
export async function sendProactiveGroupMessage(
accessToken: string,
groupOpenid: string,
content: string
): Promise<{ id: string; timestamp: string }> {
return apiRequest(accessToken, "POST", `/v2/groups/${groupOpenid}/messages`, {
content,
msg_type: 0,
});
}