feat: support for automatically obtaining Telegram chat ID
This commit is contained in:
@@ -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`。
|
||||
|
||||
@@ -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 (
|
||||
<Grid columns={1}>
|
||||
<Grid.Column>
|
||||
@@ -489,7 +514,14 @@ const PushSetting = () => {
|
||||
<Header as='h3'>
|
||||
Telegram 机器人设置(telegram)
|
||||
<Header.Subheader>
|
||||
通过 Telegram 机器人进行消息推送。
|
||||
通过 Telegram 机器人进行消息推送。首先向
|
||||
<a href='https://t.me/botfather' target='_blank'>
|
||||
{' '}
|
||||
Bot Father{' '}
|
||||
</a>
|
||||
申请创建一个新的机器人,之后在下方输入获取到的令牌,然后点击你的机器人,随便发送一条消息,之后点击下方的「获取会话
|
||||
ID」按钮,系统将自动为你填写会话
|
||||
ID,最后点击保存按钮保存设置即可。
|
||||
</Header.Subheader>
|
||||
</Header>
|
||||
<Form.Group widths={2}>
|
||||
@@ -512,6 +544,9 @@ const PushSetting = () => {
|
||||
placeholder='在此设置 Telegram 会话 ID'
|
||||
/>
|
||||
</Form.Group>
|
||||
<Button onClick={getTelegramChatId} loading={loading}>
|
||||
获取会话 ID
|
||||
</Button>
|
||||
<Button onClick={() => submit('telegram')} loading={loading}>
|
||||
保存
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user