# 飞书机器人应用

***

**特别注意：飞书应用使用的是批量发送消息接口，消息会有一定延迟，且必须要有至少一个飞书用户open\_id或user\_id或union\_ids或部门open\_department\_id，否则无法收取消息**

**创建飞书应用**

打开飞书开放平台，创建飞书企业自建app应用 <https://open.feishu.cn/app/>

![fei](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-1a934929a441d581b0a6ce67de103c23de9f58a7%2Ffsapp%E7%99%BB%E5%BD%95%E5%88%9B%E5%BB%BA%E6%9C%BA%E5%99%A8%E4%BA%BA1.png?alt=media)

![fei2](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-953bae8918a26f56becd357a2d071993a5a66e5d%2Ffsapp%E7%99%BB%E5%BD%95%E5%88%9B%E5%BB%BA%E6%9C%BA%E5%99%A8%E4%BA%BA2.png?alt=media)

创建完成后，选择刚刚创建的应用，进入应用管理后台，选择 应用功能--> 机器人，开启应用的机器人能力

![fei3](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-80f537b48153d530596c33e9f80f361dbec9f3e0%2Ffsapp%E5%90%AF%E7%94%A8%E6%9C%BA%E5%99%A8%E4%BA%BA3.png?alt=media)

继续分配应用权限，选择 权限管理--> 消息与群组，开通以下权限

* 给多个用户批量发消息
* 给一个或多个部门的成员批量发消息
* 获取与发送单聊、群组消息

![fei4](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-90cb0aa8a541581810a6a8ac99191405bc253752%2Ffsapp%E5%88%86%E9%85%8D%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%9D%83%E9%99%904.png?alt=media)

最后发布应用版本，让具有管理员权限的用户去审核申请的权限和发布请求即可

![fei5](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-a9be23f1672e3c29b1b6591c20d492b67d2bf08c%2Ffsapp%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%865.png?alt=media)

审核完成后，获取到飞书应用的 `App ID`和`App Secret`，并配置到PrometheusAlert 的 app.conf配置项目中

![fei6](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-2105121570d3c814dacb74470d0b06be6cec95fe%2Ffsapp6.png?alt=media)

**飞书应用app.conf配置**

```
#---------------------↓飞书机器人应用-----------------------
#是否开启feishuapp告警通道,可同时开始多个通道0为关闭,1为开启
open-feishuapp=1
# APPID
FEISHU_APPID=cli_xxxxxxxxxxxxxxxxxxxxx
# APPSECRET
FEISHU_APPSECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# 可填飞书 用户open_id、user_id、union_ids、部门open_department_id
AT_USER_ID="xxxxxxxxxxx"
```

**如何查找user\_id**

通过飞书管理员登录飞书管理后台，进入 组织架构-->成员与部门-->找到对应的用户，查看成员详情即可

![fei7](https://1024575059-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M8n6Ta3jydOf-smMmDd%2Fuploads%2Fgit-blob-c165327c5a033f6671314018a846a6f221137b80%2Ffsapp7.png?alt=media)

**如何使用**

以Prometheus配合自定义模板为例：

Prometheus配置参考：

```
global:
  resolve_timeout: 5m
route:
  group_by: ['instance']
  group_wait: 10m
  group_interval: 10s
  repeat_interval: 10m
  receiver: 'web.hook.prometheusalert'
receivers:
- name: 'web.hook.prometheusalert'
  webhook_configs:
  - url: 'http://[prometheusalert_url]:8080/prometheusalert?type=fsapp&tpl=prometheus-feishu-app&at=xxxxxxxx,xxxxxx2,xxxxxxx3'
```


---

# 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://feiyu563.gitbook.io/prometheusalert/conf/conf-feishuapp.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.
