Skip to content

Commit

Permalink
Merge pull request #66 from LeslieLeung/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LeslieLeung authored May 4, 2024
2 parents b868d9c + 4d0fa30 commit 701acf8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Heimdallr 是一个非常轻量的通知网关,可以聚合各种推送渠道
- 支持各种常见的推送渠道,如Bark、企业微信等
- 支持 [Apprise](https://github.com/caronc/apprise),从此再也不缺通知渠道(完全列表见[链接](https://github.com/caronc/apprise#supported-notifications)
- 完全兼容 Bark 的路由,任意支持 Bark 的地方,都可以使用 Heimdallr 同时发送到更多渠道
- 提供兼容 [message-pusher](https://github.com/songquanpeng/message-pusher) 的路由。
- 支持发送图片(仅 Apprise)
- 支持多通知渠道和分组配置
- 支持 Serverless 部署,几乎零成本运行
Expand Down Expand Up @@ -42,7 +43,7 @@ Heimdallr 是一个非常轻量的通知网关,可以聚合各种推送渠道

# 部署方式

配置项见 [示例](.env.example)
配置项见 [示例](.env.example)也可以使用[配置生成器](https://heimdallr-configurator.vercel.app/)

具体配置,见 [配置文档](docs/Config.md)

Expand All @@ -67,6 +68,18 @@ Heimdallr 是一个非常轻量的通知网关,可以聚合各种推送渠道

[接口文档](https://heimdallr.zeabur.app/docs)

## 兼容接口

Heimdallr 提供与 Bark 完全兼容的接口以及与 message-pusher 兼容的接口。

### Bark 兼容接口

只需要把 Bark 的服务链接换成 Heimdallr 的服务链接即可。

### message-pusher 兼容接口

message-pusher 的接口形如 `https://<domain>/push/<username>`,替换成 `https://<domain>/competable/message-pusher/push` 即可,token 填 Heimdallr 分组的 token。

## Markdown 支持

在一些支持 Markdown 的服务上,格式化的文本可以以 Markdown 格式呈现。在请求时,通过 query 参数或 json 传入 `msg_type = markdown` 即可。
Expand Down
3 changes: 2 additions & 1 deletion heimdallr/api/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from fastapi import APIRouter

from heimdallr.api import push, webhook
from heimdallr.api import competable, push, webhook

router = APIRouter()
router.include_router(webhook.webhook_router)
router.include_router(competable.competable_router)
router.include_router(push.push_router)
23 changes: 23 additions & 0 deletions heimdallr/api/competable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from fastapi import APIRouter, Form, Query

from heimdallr.api.base import serve_channels_async

competable_router = APIRouter(prefix="/competable")


@competable_router.get("/message-pusher/push")
async def message_pusher_get(
title: str = Query(...),
description: str = Query(...),
token: str = Query(...),
):
return await serve_channels_async(token, title, description)


@competable_router.post("/message-pusher/push")
async def message_pusher_post(
title: str = Form(...),
description: str = Form(...),
token: str = Form(...),
):
return await serve_channels_async(token, title, description)
3 changes: 0 additions & 3 deletions heimdallr/api/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async def send_push_by_form(
msg_type: str = Form(default="text"),
attach: str = Form(default="", description="base64 string, only support image"),
):
print("send push by form")
return await serve_channels_async(key, title, body, msg_type=msg_type, attach=attach)


Expand All @@ -32,7 +31,6 @@ class PostRequest(BaseModel):

@push_router.post("/push")
async def send_push_by_json(request: PostRequest):
print("send push by json")
return await serve_channels_async(
request.key,
request.title,
Expand All @@ -55,5 +53,4 @@ async def send_push(
msg_type: str = "",
attach: str = Query("", description="base64 string, only support image"),
):
print("send push")
return await serve_channels_async(key, title, body, msg_type=msg_type, attach=attach)
6 changes: 3 additions & 3 deletions heimdallr/channel/apprise.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import os
from typing import Tuple
from typing import Tuple, Union

import apprise
import filetype
Expand All @@ -16,11 +16,11 @@ def __init__(
self,
title: str,
body: str,
attach: str,
attach: Union[str, None] = None,
**kwargs,
):
super().__init__(title, body)
self.attach: str = attach
self.attach: Union[str, None] = attach

def render_message(self) -> str:
return self.body
Expand Down

0 comments on commit 701acf8

Please sign in to comment.