From 3ffe923e4f09065fb4e0cce47df6eb6664f764fa Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 21 Dec 2022 19:32:24 +0800 Subject: [PATCH] feat: support for automatically obtaining Telegram chat ID --- README.md | 2 ++ web/src/components/PushSetting.js | 37 ++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fff353..bdc4670 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ _✨ 搭建专属于你的消息推送服务,支持多种消息推送方式, + 钉钉群机器人, + Bark App, + WebSocket 客户端([官方客户端](https://github.com/songquanpeng/personal-assistant),[接入文档](./docs/API.md#websocket-客户端)), + + Telegram 机器人, 2. 多种用户登录注册方式: + 邮箱登录注册以及通过邮箱进行密码重置。 + [GitHub 开放授权](https://github.com/settings/applications/new)。 @@ -158,6 +159,7 @@ proxy_send_timeout 300s; 6. `ding`:通过钉钉群机器人进行推送。 7. `bark`:通过 Bark 进行推送。 8. `client`:通过 WebSocket 客户端进行推送。 + 9. `telegram`:通过 Telegram 机器人进行推送(`description` 或 `content` 字段均可,支持 Markdown 的子集)。 5. `token`:如果你在后台设置了推送 token,则此项必填。另外可以通过设置 HTTP `Authorization` 头部设置此项。 3. `POST` 请求方式:字段与上面 `GET` 请求方式保持一致。 + 注意:请求体编码格式为 `application/json`。 diff --git a/web/src/components/PushSetting.js b/web/src/components/PushSetting.js index aaab55b..555b225 100644 --- a/web/src/components/PushSetting.js +++ b/web/src/components/PushSetting.js @@ -8,6 +8,7 @@ import { Message, } from 'semantic-ui-react'; import { API, removeTrailingSlash, showError, showSuccess } from '../helpers'; +import axios from 'axios'; const PushSetting = () => { let [inputs, setInputs] = useState({ @@ -141,6 +142,30 @@ const PushSetting = () => { } }; + const getTelegramChatId = async () => { + if (inputs.telegram_bot_token === '') { + showError('请先输入 Telegram 机器人令牌!'); + return; + } + let res = await axios.get( + `https://api.telegram.org/bot${inputs.telegram_bot_token}/getUpdates` + ); + const { ok } = res.data; + if (ok) { + let result = res.data.result; + if (result.length === 0) { + showError(`请先向你的机器人发送一条任意消息!`); + } else { + let id = result[0]?.message?.chat?.id; + id = id.toString(); + setInputs((inputs) => ({ ...inputs, telegram_chat_id: id })); + showSuccess('会话 ID 获取成功,请点击保存按钮保存!'); + } + } else { + showError(`发生错误:${res.description}`); + } + }; + return ( @@ -489,7 +514,14 @@ const PushSetting = () => {
Telegram 机器人设置(telegram) - 通过 Telegram 机器人进行消息推送。 + 通过 Telegram 机器人进行消息推送。首先向 + + {' '} + Bot Father{' '} + + 申请创建一个新的机器人,之后在下方输入获取到的令牌,然后点击你的机器人,随便发送一条消息,之后点击下方的「获取会话 + ID」按钮,系统将自动为你填写会话 + ID,最后点击保存按钮保存设置即可。
@@ -512,6 +544,9 @@ const PushSetting = () => { placeholder='在此设置 Telegram 会话 ID' /> +