mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-24 23:16:53 +00:00
新增撤回消息推送
This commit is contained in:
@@ -74,14 +74,14 @@ GET /api/v1/push/messages
|
|||||||
- 需要先在设置页开启 `HTTP API 服务`
|
- 需要先在设置页开启 `HTTP API 服务`
|
||||||
- 同时需要开启 `主动推送`
|
- 同时需要开启 `主动推送`
|
||||||
- 响应类型为 `text/event-stream`
|
- 响应类型为 `text/event-stream`
|
||||||
- 新消息事件名固定为 `message.new`
|
- 事件名包含 `message.new` 和 `message.revoke`
|
||||||
- 建议接收端按 `messageKey` 去重
|
- 建议接收端按 `event + rawid` 去重
|
||||||
|
|
||||||
### 事件字段
|
### 事件字段
|
||||||
|
|
||||||
- `event`
|
- `event`
|
||||||
- `sessionId`
|
- `sessionId`
|
||||||
- `messageKey`
|
- `rawid`
|
||||||
- `avatarUrl`
|
- `avatarUrl`
|
||||||
- `sourceName`
|
- `sourceName`
|
||||||
- `groupName`(仅群聊)
|
- `groupName`(仅群聊)
|
||||||
@@ -98,7 +98,14 @@ curl -N "http://127.0.0.1:5031/api/v1/push/messages?access_token=YOUR_TOKEN
|
|||||||
|
|
||||||
```text
|
```text
|
||||||
event: message.new
|
event: message.new
|
||||||
data: {"event":"message.new","sessionId":"xxx@chatroom","messageKey":"server:123456:1760000123:1760000123000:321:wxid_member:1","avatarUrl":"https://example.com/group.jpg","sourceName":"李四","groupName":"项目群","content":"[图片]","timestamp":1760000123}
|
data: {"event":"message.new","sessionId":"xxx@chatroom","sessionType":"group","rawid":"1234567890123456789","avatarUrl":"https://example.com/group.jpg","sourceName":"李四","groupName":"项目群","content":"[图片]","timestamp":1760000123}
|
||||||
|
```
|
||||||
|
|
||||||
|
撤回事件示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
event: message.revoke
|
||||||
|
data: {"event":"message.revoke","sessionId":"wxid_xxx","sessionType":"other","rawid":"1234567890123456789","avatarUrl":"https://example.com/avatar.jpg","sourceName":"张三","content":"对方撤回了一条消息(rawid:1234567890123456789) 内容为“你好”","timestamp":1760000180}
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -290,7 +290,8 @@ class HttpService {
|
|||||||
broadcastMessagePush(payload: Record<string, unknown>): void {
|
broadcastMessagePush(payload: Record<string, unknown>): void {
|
||||||
if (!this.running) return
|
if (!this.running) return
|
||||||
const eventId = this.nextMessagePushEventId()
|
const eventId = this.nextMessagePushEventId()
|
||||||
const eventBody = `id: ${eventId}\nevent: message.new\ndata: ${JSON.stringify(payload)}\n\n`
|
const eventName = this.getMessagePushEventName(payload)
|
||||||
|
const eventBody = `id: ${eventId}\nevent: ${eventName}\ndata: ${JSON.stringify(payload)}\n\n`
|
||||||
this.rememberMessagePushEvent(eventId, eventBody)
|
this.rememberMessagePushEvent(eventId, eventBody)
|
||||||
if (this.messagePushClients.size === 0) return
|
if (this.messagePushClients.size === 0) return
|
||||||
|
|
||||||
@@ -308,6 +309,11 @@ class HttpService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getMessagePushEventName(payload: Record<string, unknown>): string {
|
||||||
|
const eventName = String(payload?.event || '').trim()
|
||||||
|
return /^[a-z0-9._-]+$/i.test(eventName) ? eventName : 'message.new'
|
||||||
|
}
|
||||||
|
|
||||||
async autoStart(): Promise<void> {
|
async autoStart(): Promise<void> {
|
||||||
const enabled = this.configService.get('httpApiEnabled')
|
const enabled = this.configService.get('httpApiEnabled')
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -4120,16 +4120,16 @@ function SettingsPage({ onClose }: SettingsPageProps = {}) {
|
|||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label>推送内容</label>
|
<label>推送内容</label>
|
||||||
<span className="form-hint">SSE 事件名为 `message.new`;私聊推送 `avatarUrl/sourceName/content/timestamp`,群聊额外附带 `groupName`,其中 `timestamp` 为秒级 Unix 时间戳</span>
|
<span className="form-hint">SSE 事件名包含 `message.new` 和 `message.revoke`;私聊推送 `rawid/avatarUrl/sourceName/content/timestamp`,群聊额外附带 `groupName`,其中 `timestamp` 为秒级 Unix 时间戳</span>
|
||||||
<div className="api-docs">
|
<div className="api-docs">
|
||||||
<div className="api-item">
|
<div className="api-item">
|
||||||
<div className="api-endpoint">
|
<div className="api-endpoint">
|
||||||
<span className="method get">GET</span>
|
<span className="method get">GET</span>
|
||||||
<code>{`http://${httpApiHost}:${httpApiPort}/api/v1/push/messages`}</code>
|
<code>{`http://${httpApiHost}:${httpApiPort}/api/v1/push/messages`}</code>
|
||||||
</div>
|
</div>
|
||||||
<p className="api-desc">通过 SSE 长连接接收消息事件,建议接收端按 `messageKey` 去重。</p>
|
<p className="api-desc">通过 SSE 长连接接收消息事件,建议接收端按 `event + rawid` 去重。</p>
|
||||||
<div className="api-params">
|
<div className="api-params">
|
||||||
{['event', 'sessionId', 'sessionType', 'messageKey', 'avatarUrl', 'sourceName', 'groupName?', 'content', 'timestamp'].map((param) => (
|
{['event', 'sessionId', 'sessionType', 'rawid', 'avatarUrl', 'sourceName', 'groupName?', 'content', 'timestamp'].map((param) => (
|
||||||
<span key={param} className="param">
|
<span key={param} className="param">
|
||||||
<code>{param}</code>
|
<code>{param}</code>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user