39f3774940
统一 sources/templates/channels/rules 列表为分页响应,避免配置增多时全量返回;按钉钉 access_token 限制每分钟发送并在超限时等待下一分钟,降低触发官方封禁风险。 Co-authored-by: Cursor <cursoragent@cursor.com>
397 lines
8.0 KiB
Markdown
397 lines
8.0 KiB
Markdown
# HTTPie 可导入 cURL 集合
|
||
|
||
**推荐:** 直接导入 Postman 集合(一次导入全部)
|
||
|
||
```
|
||
docs/httpie/postman_collection.json
|
||
```
|
||
|
||
HTTPie → Import → Postman → 选择该文件。
|
||
|
||
**单条导入:** Import → cURL → 粘贴下方某一条完整 `curl`。
|
||
|
||
替换占位符:
|
||
|
||
| 占位符 | 说明 |
|
||
|--------|------|
|
||
| `http://localhost:8080` | 服务地址 |
|
||
| `admin-sk-change-me` | `config.yaml` 的 `server.admin_key` |
|
||
| `SOURCE_API_KEY` | 创建 Source 返回的 `api_key` |
|
||
| `:id` / `1` | 资源数字 ID |
|
||
|
||
---
|
||
|
||
## Health
|
||
|
||
### 健康检查
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/health'
|
||
```
|
||
|
||
---
|
||
|
||
## Notify
|
||
|
||
### 发送通知(JSON)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"event": "trade.open",
|
||
"data": {
|
||
"symbol": "BTC",
|
||
"price": 65000
|
||
}
|
||
}'
|
||
```
|
||
|
||
### 发送通知(Regex)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: text/plain' \
|
||
--data-binary 'trade.open BTC 开仓 价格:65000'
|
||
```
|
||
|
||
### 发送通知(Text,event=default)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: text/plain' \
|
||
--data-binary 'BTC 突破 68000,请注意风险'
|
||
```
|
||
|
||
---
|
||
|
||
## Sources
|
||
|
||
### 创建 Source(JSON)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trading-system",
|
||
"parse_mode": "json",
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Source(Regex)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "legacy-monitor",
|
||
"parse_mode": "regex",
|
||
"parse_pattern": "(?P<event>\\w+)\\s+(?P<message>.+)"
|
||
}'
|
||
```
|
||
|
||
### 创建 Source(Text)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "alert-bot",
|
||
"parse_mode": "text"
|
||
}'
|
||
```
|
||
|
||
### 列出 Source
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/sources?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Source
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Source
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trading-system",
|
||
"parse_mode": "json",
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Source
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Templates
|
||
|
||
### 创建 Template
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade_open",
|
||
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
|
||
}'
|
||
```
|
||
|
||
### 列出 Template
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/templates?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Template
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Template
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade_open",
|
||
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
|
||
}'
|
||
```
|
||
|
||
### 删除 Template
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Channels
|
||
|
||
### 创建 Channel(Email)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "email-ops",
|
||
"type": "email",
|
||
"config": {
|
||
"to": ["148516886@qq.com"]
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(钉钉)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "dingtalk-prod",
|
||
"type": "dingtalk",
|
||
"config": {
|
||
"webhook_url": "https://oapi.dingtalk.com/robot/send?access_token=xxx",
|
||
"secret": "SEC..."
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(企业微信)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "wecom-ops",
|
||
"type": "wecom",
|
||
"config": {
|
||
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(Bark)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "bark-phone",
|
||
"type": "bark",
|
||
"config": {
|
||
"url": "https://api.day.app/<device_key>"
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 列出 Channel
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/channels?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Channel
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Channel
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "email-ops",
|
||
"type": "email",
|
||
"config": {
|
||
"to": ["148516886@qq.com"]
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Channel
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Rules
|
||
|
||
### 创建 Rule
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/rules' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"source_name": "trading-system",
|
||
"event": "trade.open",
|
||
"template_name": "trade_open",
|
||
"channels": ["email-ops"],
|
||
"conditions": [
|
||
{"field": "symbol", "op": "exists"},
|
||
{"field": "price", "op": "gt", "value": "0"}
|
||
],
|
||
"enabled": 1
|
||
}'
|
||
```
|
||
|
||
### 列出 Rule
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/rules?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Rule
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Rule
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"source_name": "trading-system",
|
||
"event": "trade.open",
|
||
"template_name": "trade_open",
|
||
"channels": ["email-ops"],
|
||
"enabled": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Rule
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 启用 Rule
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/enable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 禁用 Rule
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/disable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 启用规则下某渠道
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/enable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 禁用规则下某渠道
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/disable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Message Logs
|
||
|
||
### 查询消息记录
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/message-logs?source=trading-system&event=trade.open&status=success&page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|