# 宝塔面板/云安全监控 - 如何配置Telegram告警通知

**宝塔站长群** [**https://TG.HostCLi.COM**](https://tg.hostcli.com)

**自建Telegram BOT机器人告警通知服务，Telegram对话框内的效果截图：**

<figure><img src="https://1335146840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5FHc2JaRj2pmxKLktJe4%2Fuploads%2F2f50bUOR4PjPrNg7Zyc2%2FTelegram%E5%91%8A%E8%AD%A6.png?alt=media&#x26;token=cc24714b-e236-45f2-a8e0-7e944438b20f" alt="宝塔面板Telegram BOT机器人告警通知" width="375"><figcaption></figcaption></figure>

### Telegram告警通知，支持的告警类型众多 <a href="#alarm-type" id="alarm-type"></a>

<figure><img src="https://1335146840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5FHc2JaRj2pmxKLktJe4%2Fuploads%2FuMQJpgHXSVcXE4m5riIF%2FTelegram%E5%91%8A%E8%AD%A6-1.png?alt=media&#x26;token=e98938c6-98bf-4343-9d79-ebafb83abe11" alt=""><figcaption><p>添加告警任务时，需要勾选上Telegram，再提交添加任务</p></figcaption></figure>

### 支持服务停止后重启 <a href="#alarm-reboot-service" id="alarm-reboot-service"></a>

<figure><img src="https://1335146840-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5FHc2JaRj2pmxKLktJe4%2Fuploads%2FonXNSJ1dcVQiDbnSCVgP%2FTelegram%E5%91%8A%E8%AD%A6-2.png?alt=media&#x26;token=c005ad12-3eae-40fd-9e80-f8e29f754bc3" alt=""><figcaption><p>选择 服务停止告警 后，就会出现通知类型，可以选择各个安装了的模块，并且选择自动重启等条件选项。</p></figcaption></figure>

### 前言 <a href="#intro" id="intro"></a>

Telegram机器人的发送信息功能需要指定聊天窗口ID，接下来介绍的则是如何利用机器人获取Telegram的个人ID及群组ID。

### 一、注册机器人并获取Token <a href="#register-telegram-bot" id="register-telegram-bot"></a>

与官方机器人 [@BotFather](https://t.me/botfather) 对话，注册并获取机器人Token；点击以下链接查看教程

{% content-ref url="register-new-telegram-bot" %}
[register-new-telegram-bot](https://support.hostcli.com/telegram-bot/register-new-telegram-bot)
{% endcontent-ref %}

### 二、获取对话ID 和 获取群组ID <a href="#get-my-id" id="get-my-id"></a>

将另外一个机器人 [@TGHelp](https://t.me/tghelp) 拉入新创建的用于接收宝塔告警通知的Telegram群组；

机器人进群的时候就会自动发出当前的 **对话ID** 以及 **群组ID**：

```
Your user ID: 888888888
Current chat ID: -1002386971866
```

获取完这两行信息，即可将该机器人踢出本群。

### 三、配置宝塔面板的告警通知模块为Telegram / 配置宝塔云控的告警方式为Telegram <a href="#config-telegram-bot-notification" id="config-telegram-bot-notification"></a>

示例链接：

<pre><code>https://api.telegram.org/bot<a data-footnote-ref href="#user-content-fn-1">&#x3C;你的机器人TOKEN></a>/sendMessage?chat_id=<a data-footnote-ref href="#user-content-fn-2">对话ID</a>
</code></pre>

3.1、将[@BotFather](https://t.me/BotFather) 分配的机器人TOKEN替换到上面这个示例链接中&#x7684;**<你的机器人TOKEN>**；

⚠️注意：<https://api.telegram.org/bot> 网址后的这bot三个字母要保留，示例：

<pre><code>https://api.telegram.org/bot<a data-footnote-ref href="#user-content-fn-3">7276021111:AAEMqcAAA_EzAUzJPFPiQnhLVqUR3SDji_U</a>/sendMessage?chat_id=<a data-footnote-ref href="#user-content-fn-4">-100239149666</a>
</code></pre>

3.2、将上述示例链接最后的数字ID替换为[第二步中获取的/需要接收消息的**对话ID**](#get-my-id)，ID可能带有 - 减号；

{% hint style="info" %}
chat\_id 可以是个人ID，也可以是私密群组ID 或 公开群组的ID，<mark style="color:orange;">只能填写其中一种ID</mark>；

Your user ID: 个人对话ID，如需告警通知直接由机器人发给自己，示例链接内请使用 Your user ID后的数字ID进行拼接；<mark style="color:orange;">需要与自己创建的BOT机器人进行对话才能接收通知消息</mark>；

Current chat ID: 群组对话ID，如需告警通知发送到Telegram群 \[私密群(历史记录对新成员可见)或公开群]，示例链接内请使用 Current chat ID 进行拼接；<mark style="color:orange;">可能需要给予自己创建的BOT机器人设置为群组管理员权限</mark>。
{% endhint %}

3.3、将机器人Token和接收告警消息的对话ID按照上述格式进行拼凑，然后复制粘贴到 【宝塔面板-面板设置-告警通知- Telegram】 或 【宝塔云监控-告警设置-Telegram】。

添加成功后，系统会自动发送测试通知到您配置的这个Telegram对话里；

### 四、FAQ <a href="#faq" id="faq"></a>

Q1：宝塔面板 和 宝塔云安全监控 可以共用一个机器人BOT通知到一个群组吗？

A1：经测试，可以！

**宝塔站长群** [**https://TG.HostCLi.COM**](https://tg.hostcli.com)

End.

[^1]: 包括尖括号一起替换成你的token，不要保留尖括号

[^2]: chat\_id 可以是个人ID，也可以是私密群组ID 或 公开群组的ID，只能填写其中一种ID；

    Your user ID: 个人对话ID，如需告警通知直接由机器人发给自己，示例链接内请使用 Your user ID后的数字ID进行拼接；需要与自己创建的BOT机器人进行对话才能接收通知消息；

    Current chat ID: 群组对话ID，如需告警通知发送到Telegram群 \[私密群(历史记录对新成员可见)或公开群]，示例链接内请使用 Current chat ID 进行拼接；可能需要给予自己创建的BOT机器人设置为群组管理员权限。

[^3]: 示例token

[^4]: 示例私密群ID，历史消息对新成员：可见


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.hostcli.com/telegram-bot/telegram-bot-notification.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
