fangyuanjian 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -0
- package/dist/index.js +18314 -0
- package/dist/setup-entry.js +18305 -0
- package/examples/config.example.jsonc +52 -0
- package/examples/inbound-payload.example.json +9 -0
- package/examples/outbound-request.example.json +6 -0
- package/examples/webhook-payload.example.json +9 -0
- package/openclaw.plugin.json +43 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# fyj Extension
|
|
2
|
+
|
|
3
|
+
`@openclaw/fyj` is a template extension to connect your own IM system to OpenClaw.
|
|
4
|
+
|
|
5
|
+
## What To Replace For Your IM
|
|
6
|
+
|
|
7
|
+
The two key integration points are:
|
|
8
|
+
|
|
9
|
+
1. `src/send.ts`
|
|
10
|
+
- Replace the outbound `fetch` URL, headers, and JSON body with your IM send-message API.
|
|
11
|
+
|
|
12
|
+
2. `src/monitor.ts`
|
|
13
|
+
- Replace websocket subscription URL, subscribe payload, and inbound payload mapping with your IM protocol.
|
|
14
|
+
|
|
15
|
+
## 中文说明
|
|
16
|
+
|
|
17
|
+
你需要重点替换两处与真实 IM 协议绑定的实现:
|
|
18
|
+
|
|
19
|
+
1. `src/send.ts`
|
|
20
|
+
- 把出站 `fetch` 的 URL、鉴权头、请求体字段改成你们 IM 的发送接口。
|
|
21
|
+
|
|
22
|
+
2. `src/monitor.ts`
|
|
23
|
+
- 把 websocket 连接地址、订阅请求体、入站消息字段映射改成你们 IM 的协议。
|
|
24
|
+
|
|
25
|
+
## Example Config
|
|
26
|
+
|
|
27
|
+
See `examples/config.example.jsonc`.
|
|
28
|
+
|
|
29
|
+
Main fields:
|
|
30
|
+
- `channels.fyj.baseUrl`: your IM HTTP API base URL
|
|
31
|
+
- `channels.fyj.sendPath`: send endpoint path
|
|
32
|
+
- `channels.fyj.botToken`: outbound + websocket auth token
|
|
33
|
+
- `channels.fyj.wsUrl`: websocket subscription URL (preferred)
|
|
34
|
+
- `channels.fyj.wsPath`: fallback path if wsUrl is not set
|
|
35
|
+
- `channels.fyj.wsSubscribePayload`: initial subscribe message body
|
|
36
|
+
- `channels.fyj.wsHeartbeatIntervalSec`: websocket heartbeat interval (seconds)
|
|
37
|
+
|
|
38
|
+
## 示例配置字段(中文)
|
|
39
|
+
|
|
40
|
+
主要字段含义:
|
|
41
|
+
- `channels.fyj.baseUrl`:你们 IM 的 HTTP API 基础地址
|
|
42
|
+
- `channels.fyj.sendPath`:发送接口路径
|
|
43
|
+
- `channels.fyj.botToken`:出站 + websocket 鉴权 token
|
|
44
|
+
- `channels.fyj.wsUrl`:websocket 订阅地址(优先使用)
|
|
45
|
+
- `channels.fyj.wsPath`:未配置 wsUrl 时,使用 baseUrl + wsPath 推导
|
|
46
|
+
- `channels.fyj.wsSubscribePayload`:建连后发送的订阅请求体
|
|
47
|
+
- `channels.fyj.wsHeartbeatIntervalSec`:websocket 心跳间隔(秒)
|
|
48
|
+
|
|
49
|
+
## Example Inbound Payload
|
|
50
|
+
|
|
51
|
+
See `examples/inbound-payload.example.json`.
|
|
52
|
+
|
|
53
|
+
Expected shape in this template:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"messageId": "msg_123",
|
|
58
|
+
"conversationId": "conv_abc",
|
|
59
|
+
"chatType": "direct",
|
|
60
|
+
"senderId": "u_1001",
|
|
61
|
+
"senderName": "Alice",
|
|
62
|
+
"text": "hello",
|
|
63
|
+
"timestamp": 1742100000000
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Example Outbound Request
|
|
68
|
+
|
|
69
|
+
See `examples/outbound-request.example.json`.
|
|
70
|
+
|
|
71
|
+
This template currently sends:
|
|
72
|
+
- `Authorization: Bearer <botToken>`
|
|
73
|
+
- body with `conversationId`, `text`, `replyToMessageId`, `mediaUrl`
|
|
74
|
+
|
|
75
|
+
Update those fields to match your IM API.
|
|
76
|
+
|
|
77
|
+
## 示例出站(中文)
|
|
78
|
+
|
|
79
|
+
模板默认会发送:
|
|
80
|
+
- `Authorization: Bearer <botToken>`
|
|
81
|
+
- body 字段:`conversationId`、`text`、`replyToMessageId`、`mediaUrl`
|
|
82
|
+
|
|
83
|
+
接入你们 IM 时,请按真实接口协议替换字段名。
|
|
84
|
+
|
|
85
|
+
## File Logic Map
|
|
86
|
+
|
|
87
|
+
- `index.ts`: plugin register entry, injects runtime, registers channel plugin.
|
|
88
|
+
- `setup-entry.ts`: setup runtime entry export.
|
|
89
|
+
- `src/channel.setup.ts`: setup plugin alias.
|
|
90
|
+
- `src/runtime.ts`: plugin runtime store getter/setter.
|
|
91
|
+
- `src/types.ts`: shared type contracts for config/account/websocket/send.
|
|
92
|
+
- `src/config-schema.ts`: zod schema + dmPolicy/open validation.
|
|
93
|
+
- `src/accounts.ts`: account merge + token source resolution + websocket URL resolution.
|
|
94
|
+
- `src/normalize.ts`: target normalization and id detection.
|
|
95
|
+
- `src/send.ts`: outbound HTTP sender mapping to your IM API.
|
|
96
|
+
- `src/monitor.ts`: websocket connect/subscribe/heartbeat/reconnect/payload parse.
|
|
97
|
+
- `src/inbound.ts`: policy checks, session routing, reply dispatch and outbound callback.
|
|
98
|
+
- `src/channel.ts`: ChannelPlugin orchestration (config/security/outbound/status/gateway).
|
|
99
|
+
- `examples/config.example.jsonc`: sample channel config.
|
|
100
|
+
- `examples/inbound-payload.example.json`: sample inbound payload shape.
|
|
101
|
+
- `examples/outbound-request.example.json`: sample outbound API payload.
|
|
102
|
+
- `openclaw.plugin.json`: plugin manifest metadata.
|
|
103
|
+
- `package.json`: extension package metadata and OpenClaw extension declaration.
|
|
104
|
+
|
|
105
|
+
## 文件实现逻辑总览(中文)
|
|
106
|
+
|
|
107
|
+
- `index.ts`:插件注册入口,保存 runtime 并注册 fyj 渠道。
|
|
108
|
+
- `setup-entry.ts`:setup 模式入口导出。
|
|
109
|
+
- `src/channel.setup.ts`:setup 插件别名。
|
|
110
|
+
- `src/runtime.ts`:插件 runtime 存取器。
|
|
111
|
+
- `src/types.ts`:配置、账号、websocket、发送结果等类型定义。
|
|
112
|
+
- `src/config-schema.ts`:fyj 配置校验与策略联动校验。
|
|
113
|
+
- `src/accounts.ts`:账号配置合并、botToken 来源解析与 websocket URL 推导。
|
|
114
|
+
- `src/normalize.ts`:目标地址规范化与识别。
|
|
115
|
+
- `src/send.ts`:出站发送 HTTP 映射到你们 IM 接口。
|
|
116
|
+
- `src/monitor.ts`:websocket 建连、订阅、心跳、重连与入站分发。
|
|
117
|
+
- `src/inbound.ts`:权限门禁、会话路由、回复调度与回发。
|
|
118
|
+
- `src/channel.ts`:渠道能力、配置、安全、状态、gateway 生命周期总编排。
|
|
119
|
+
- `examples/config.example.jsonc`:配置示例模板。
|
|
120
|
+
- `examples/inbound-payload.example.json`:入站 payload 示例。
|
|
121
|
+
- `examples/outbound-request.example.json`:出站请求示例。
|
|
122
|
+
- `openclaw.plugin.json`:插件清单元信息。
|
|
123
|
+
- `package.json`:扩展包元信息与 OpenClaw 扩展声明。
|
|
124
|
+
|
|
125
|
+
Note: `*.json` files do not support comments in strict JSON syntax. Their implementation logic is documented here.
|
|
126
|
+
|
|
127
|
+
<!-- 文件实现逻辑:
|
|
128
|
+
1) 说明如何把模板映射替换为真实 IM 协议。
|
|
129
|
+
2) 提供逐文件职责总览,方便后续维护。
|
|
130
|
+
3) 为无法写注释的 JSON 文件集中提供逻辑说明。
|
|
131
|
+
-->
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Local End-to-End (With bot-event-service)
|
|
135
|
+
|
|
136
|
+
1. Start Java service in `C:\Users\CFG\Desktop\fyj\bot-event-service`.
|
|
137
|
+
2. Use `examples/config.example.jsonc` for fyj channel config.
|
|
138
|
+
3. Call `POST /api/fyj/events/publish` to push inbound messages.
|
|
139
|
+
4. Verify OpenClaw receives and processes fyj inbound events.
|