Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for rsspush webhook #35

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ curl -X POST 'http://<HOST>/push' --data-raw '{
- [使用 Heimdallr 接收群晖DSM推送](docs/example/DSM.md)
- [使用 Heimdallr 接收威联通推送](docs/example/QNAP.md)
- [使用 Heimdallr 接收 GitHub star webhook](docs/example/GitHubStar.md)
- [使用 Heimdallr 接收 RSS 推送](docs/example/Rsspush.md)

# 更新日志

Expand Down
124 changes: 7 additions & 117 deletions docs/Api.md
Original file line number Diff line number Diff line change
@@ -1,134 +1,24 @@
<h1>接口文档</h1>

> 接口文档有 [在线版](https://service-epwdrzxg-1255787947.gz.apigw.tencentcs.com/release/docs) ,本文档更新可能较在线版晚
接口文档见[这里](https://heimdallr.zeabur.app/docs)。

# 通用

## channel 取值

目前支持以下通知渠道

- `bark` - [Bark](https://github.com/Finb/Bark)
- `wecom-app` - [企业微信应用消息](https://developer.work.weixin.qq.com/document/path/90236)
- `wecom-webhook` - [企业微信机器人webhook](https://developer.work.weixin.qq.com/document/path/91770)
- `pushover` - [Pushover](https://pushover.net/api)
- `pushdeer` - [PushDeer](http://pushdeer.com)
- `chanify` - [Chanify](https://github.com/chanify/chanify)
- `email`- 邮件

### <div id="multi-channel">推送到多个渠道</div>

> `v0.1.3` 后支持推送到多个渠道

需要推送到多个渠道时,`channel` 参数传入多个渠道,以 `+` 分隔,如 `bark+wecom-app+wecom-webhook` 。

# 接口

## Path Variable Style
`/{channel}/{title}/{body}/{key}`

> `GET` / `POST`

- `channel` 为推送的渠道,可以是 `bark`、`wecom-webhook`、`wecom-app` 等。
- `title` 为推送的标题,可以是任意字符串。(可以不填)
- `body` 为推送的内容,可以是任意字符串。
- `key` 为环境变量中设置的key,当设置了环境变量时必填。

## Get Param Style

`/{channel}?title={title}&body={body}&key={key}`

> `GET`

- `channel` 为推送的渠道,可以是 `bark`、`wecom-webhook`、`wecom-app` 等。
- `title` 为推送的标题,可以是任意字符串。(可以不填)
- `body` 为推送的内容,可以是任意字符串。
- `key` 为环境变量中设置的key,当设置了环境变量时必填。

## JSON

`/send`

> `POST`

请求参数

```json
{
"channel": "string",
"title": "",
"body": "",
"key": ""
}
```

## Form

`/sendForm`

> `POST`

- `channel` 为推送的渠道,可以是 `bark`、`wecom-webhook`、`wecom-app` 等。
- `title` 为推送的标题,可以是任意字符串。(可以不填)
- `body` 为推送的内容,可以是任意字符串。
- `key` 为环境变量中设置的key,当设置了环境变量时必填。

## Echo

`/echo/{channel}`

> `POST`

- `channel` 为推送的渠道,可以是 `bark`、`wecom-webhook`、`wecom-app` 等。
- POST 请求的 body 会原样返回。

## Wecom

`/wecom-app` `/wecom-webhook`

> `POST`

请求参数
## 返回示例

```json
{
"title": "",
"body": "",
"msg_type": "text"
}
```

- `msg_type` 取值可以是 `text` 或 `markdown`,默认为 `text` 。使用`markdown` 时,`body` 可以传入 Markdown 格式的文本。

# 返回示例

## 成功
### 成功
```json
{"code": 0, "message": "success"}
```

## 错误
### 错误

### 通知渠道返回错误信息
#### 通知渠道返回错误信息

```json
{"code": 1, "message": "{channel} return {msg}"}
```

### 不支持的渠道

```json
{"code": 2, "message": "{channel} is not supported"}
```

### 运行错误

```json
{"code": 3, "message": "xxx"}
```

### 认证错误
#### 认证错误

```json
{"code": -1, "message": "key not authorized"}
{"code": -1, "message": "key is invalid"}
```
4 changes: 4 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 更新日志
## v2.0.4
- 支持 [rsspush](https://github.com/easychen/rsspush) webhook 通知。
## v2.0.3
- 通知渠道新增钉钉
## v2.0.2
- 通知渠道新增 飞书/Lark Webhook
## v2.0.1
Expand Down
2 changes: 1 addition & 1 deletion docs/example/DSM.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
名称随意选择即可,测试网址填入在腾讯云 Serverless中获取的url,【测试网址】按照如下复制即可。如果使用 bark ,第一个地方填bark,若使用其他,填其他方式,具体见 [接口文档](/docs/Api.md) 。

```
https://SERVERLESS_URL/bark?phone=123&title=hi&body=hello+world
https://example.com/key?phone=123&title=hi&body=hello+world
```

![](http://img.ameow.xyz/202205290618022.png)
Expand Down
4 changes: 2 additions & 2 deletions docs/example/GitHubStar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

进入 GitHub 仓库的 Settings -> Webhooks -> Add webhook。

Payload URL 填入通知服务的地址,加上路径参数,其中 `{channel}` 为通知渠道
Payload URL 填入通知服务的地址,加上路径参数,其中 `{key}` 为通知渠道的 `token`

```
https://example.org/github/star/{channel}
https://example.com/webhook/github/star/{key}
```

Content type 选择 `application/json`, Secret 留空。
Expand Down
4 changes: 2 additions & 2 deletions docs/example/QNAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
SMS 服务提供商选择 【custom】,别名随意选择即可。【URL 模板】填入以下信息。剩余两项随意填写即可。

```
https://SERVERLESS_URL/CHANNELS?phone=@@PhoneNumber@@&title=Notification+From+QNAP&body=@@Text@@
https://example.com/key?phone=@@PhoneNumber@@&title=Notification+From+QNAP&body=@@Text@@
```
`SERVERLESS_URL` 为你的服务地址,`CHANNELS` 为你的通知渠道,如果使用 bark ,第一个地方填bark,若使用其他,填其他方式,具体见 [接口文档](/docs/Api.md)
`example.com` 替换为你的服务地址,`key` 为你的通知渠道的 `token`


![](http://img.ameow.xyz/202311010122299.png)
Expand Down
16 changes: 16 additions & 0 deletions docs/example/Rsspush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1>使用 Heimdallr 接收 rsspush 推送</h1>

先按照 [rsspush](https://github.com/easychen/rsspush) 文档安装配置好 RSSPush。

在 SendKey 处,填入 Heimdallr 的 webhook,如下。

```
https://example.com/webhook/rsspush/{key}
```

其中 `{key}` 为通知渠道的 `token`。

> 提示:RSSPush 没有提供测试通知渠道的方式,如果需要测试,可以把拉取时间间隔调为1分钟,然后从 [Lorem RSS](https://lorem-rss.herokuapp.com/) 这个网站复制 `https://lorem-rss.herokuapp.com/feed` 到 RSS 订阅处,即可每隔一分钟触发一次。

## 加餐 —— 接收 V2EX 新消息
在 V2EX [提醒系统](https://v2ex.com/notifications) 底部有一个【Atom Feed for Notifications】,复制该地址到 RSSPush 中即可接收 V2EX 新消息推送。
2 changes: 1 addition & 1 deletion heimdallr/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from heimdallr.api import push, webhook

router = APIRouter()
router.include_router(push.push_router)
router.include_router(webhook.webhook_router)
router.include_router(push.push_router)
2 changes: 2 additions & 0 deletions heimdallr/api/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ async def send_push_by_form(
return await serve_channels_async(key, title, body, msg_type=msg_type)


@push_router.get("/{key}")
@push_router.post("/{key}")
@push_router.get("/{key}/{body}")
@push_router.post("/{key}/{body}")
@push_router.get("/{key}/{title}/{body}")
Expand Down
13 changes: 13 additions & 0 deletions heimdallr/api/webhook.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import logging

from fastapi import APIRouter, Request

from heimdallr.api.base import serve_channels_async
from heimdallr.webhook.github_star import GithubStarWebhook

logger = logging.getLogger(__name__)

webhook_router = APIRouter(prefix="/webhook")


Expand All @@ -14,3 +17,13 @@
webhook = GithubStarWebhook(json.loads(body))
title, msg_body, jump_url = webhook.parse()
return await serve_channels_async(key, title, msg_body, jump_url=jump_url)


@webhook_router.post("/rsspush/{key}")
async def rsspush(key: str, req: Request):
form = await req.form()
task_title = form.get("task_title")
title = form.get("title")
desp = form.get("desp")
jump_url = form.get("link")
return await serve_channels_async(key, f"{task_title}", f"{title}\n{desp}", jump_url=jump_url)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.