Skip to content

Commit 774f0a4

Browse files
author
litongjava
committed
add get hook url form larksuit
1 parent 6731ed2 commit 774f0a4

File tree

1 file changed

+84
-34
lines changed
  • docs/zh/22_tio-utils

1 file changed

+84
-34
lines changed

docs/zh/22_tio-utils/03.md

+84-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Notification
22

3-
### 1. 概述
3+
## 1. 概述
44

55
tio-boot 内置了消息通知组件,用户发送消息到 微信企业群 飞书企业群 等等
66
本文档提供了一个通知组件的使用指南,介绍通过不同的方式发送通知,比如发送文本消息或者发送预警信息。它支持自定义通知方式,用户可以通过实现特定的接口来集成不同的通知服务。
@@ -16,31 +16,33 @@ Notification 依赖 okhttp 发送数据,请手动添加 okhttp 库
1616
</dependency>
1717
```
1818

19-
### 2. 核心组件介绍
19+
## 2. 核心组件介绍
2020

2121
1. **INotification**: 这是一个接口,定义了发送通知的基本方法。任何通知实现类都应该实现这个接口。
2222
2. **INotificationFactory**: 这是一个工厂接口,用于生成`INotification`的实例。
2323
3. **NotificationUtils**: 这是一个工具类,提供了静态方法来发送不同类型的通知。它使用`INotificationFactory`来获取`INotification`的实例。
2424

25-
### 3. 使用说明
25+
## 3. 使用说明
2626

27-
#### 3.1. 配置 WebHook URL
27+
### 发送消息到企业微信群
28+
29+
#### 配置 WebHook URL
2830

2931
`app.properties`文件中配置 WebHook URL:
3032

3133
```properties
3234
notification.webhook.url=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=get key from wecom
3335
```
3436

35-
#### 3.2. 发送文本消息
37+
#### 发送文本消息
3638

3739
要发送文本消息,可以使用`NotificationUtils.sendTextMsg`方法:
3840

3941
```java
4042
NotificationUtils.sendTextMsg("您的消息内容");
4143
```
4244

43-
#### 3.3. 发送预警信息
45+
#### 发送预警信息
4446

4547
要发送预警信息,可以使用`NotificationUtils.sendWarm`方法:
4648

@@ -86,43 +88,55 @@ public class MonitoringNotificationTest {
8688
}
8789
```
8890

89-
### 4. 自定义通知工厂
91+
## 发送消息到飞书群
9092

91-
1. **实现 INotification 接口**: 创建一个新类实现`INotification`接口,并实现其方法,以支持发送通知的具体实现。
93+
### 获取推送地址
9294

93-
```java
94-
public class CustomNotification implements INotification {
95-
// 实现接口中的方法
96-
}
97-
```
95+
[ref](https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot)
9896

99-
2. **实现 INotificationFactory 接口**: 创建一个工厂类来生成自定义通知的实例。
97+
Invite custom robots into the group.
10098

101-
```java
102-
public class CustomNotificationFactory implements INotificationFactory {
103-
@Override
104-
public INotification getNotifaction() {
105-
return new CustomNotification();
106-
}
107-
}
108-
```
99+
- Enter the target group, click the More button in the upper right corner of the group, and click Settings.
100+
- On the Settings interface on the right, click Bots.
101+
- On the Bots interface, click Add Bot.
102+
- In the Add bot dialog box, find and click Custom bot.
103+
- Set the avatar, name and description of the custom robot, and click Add.
109104

110-
3. **配置工厂**: 在程序开始时,配置`NotificationUtils`使用自定义的工厂。
105+
Obtain the webhook address of the custom bot and click Finish.
111106

112-
```java
113-
NotificationUtils.setFactory(new CustomNotificationFactory());
114-
```
107+
- The Webhook URL format corresponding to the robot is as follows
115108

116-
4. **发送通知**: 使用`NotificationUtils`发送通知,它会使用您配置的自定义工厂来获取通知实例,并发送通知。
109+
```
110+
https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxx
111+
```
117112

118-
```java
119-
// 使用自定义通知发送消息
120-
NotificationUtils.sendTextMsg("您的消息内容");
121-
// 或者发送预警信息
122-
NotificationUtils.sendWarm(warningName, level, deviceName, content);
123-
```
113+
Please keep this webhook address properly and do not publish it on publicly accessible websites such as Gitlab and blogs to avoid being maliciously called to send spam messages after the address is leaked.
114+
115+
Later, you can click the robot picture to the right of the group name to enter the custom robot details page and manage the configuration information of the custom robot.
116+
117+
Test calling the webhook address of the custom robot to send a message to the group it belongs to.
118+
119+
Initiate an HTTP POST request to the webhook address in any way.
120+
121+
You need to have a certain server-side development foundation, and call the webhook address through the server-side HTTP POST request. Taking the curl command as an example, the request example is as follows.
124122

125-
### 5. 发送消息到 Larksuite 群
123+
```
124+
POST /open-apis/bot/v2/hook/xxxx HTTP/1.1
125+
Host: open.larksuite.com
126+
Content-Type: application/json
127+
Accept: */*
128+
Host: open.larksuite.com
129+
Connection: keep-alive
130+
131+
{
132+
"msg_type": "text",
133+
"content": {
134+
"text": "request example"
135+
}
136+
}
137+
```
138+
139+
### 发送消息到 Larksuite 群
126140

127141
推送消息到 Larksuite
128142

@@ -185,3 +199,39 @@ public class MonitoringNotificationTest {
185199
}
186200

187201
```
202+
203+
## 5. 自定义通知工厂
204+
205+
1. **实现 INotification 接口**: 创建一个新类实现`INotification`接口,并实现其方法,以支持发送通知的具体实现。
206+
207+
```java
208+
public class CustomNotification implements INotification {
209+
// 实现接口中的方法
210+
}
211+
```
212+
213+
2. **实现 INotificationFactory 接口**: 创建一个工厂类来生成自定义通知的实例。
214+
215+
```java
216+
public class CustomNotificationFactory implements INotificationFactory {
217+
@Override
218+
public INotification getNotifaction() {
219+
return new CustomNotification();
220+
}
221+
}
222+
```
223+
224+
3. **配置工厂**: 在程序开始时,配置`NotificationUtils`使用自定义的工厂。
225+
226+
```java
227+
NotificationUtils.setFactory(new CustomNotificationFactory());
228+
```
229+
230+
4. **发送通知**: 使用`NotificationUtils`发送通知,它会使用您配置的自定义工厂来获取通知实例,并发送通知。
231+
232+
```java
233+
// 使用自定义通知发送消息
234+
NotificationUtils.sendTextMsg("您的消息内容");
235+
// 或者发送预警信息
236+
NotificationUtils.sendWarm(warningName, level, deviceName, content);
237+
```

0 commit comments

Comments
 (0)