Skip to content

Commit ae85154

Browse files
authored
Merge pull request #81 from flashcatcloud/lm_main
1. slack app default template 2. add template function
2 parents 7357359 + b919b52 commit ae85154

2 files changed

Lines changed: 87 additions & 12 deletions

File tree

flashduty/en/1. On-call/4. Configure On-call/4.7 Templates.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,36 @@ CloseTime | int64 | No | Close time, EndTime is alert recovery time, CloseTime i
247247
{{jsonGet .Labels.rule_note "#(userId==7777)#.instanceId" }}
248248
249249
```
250-
10. **如何使用逻辑与、或等条件进行内容显示判断?**
250+
251+
10. **How to Retrieve the Image URL via the Src Attribute of [Image](#Image)**
252+
- The imageSrcToURL function can be implemented, accepting parameters: $root and Src
253+
- If Src is an image_key from the Image Upload API, it should be converted into a short-term accessible URL
254+
- If Src is an accessible http/https address, the address should be returned directly
255+
- Dingtalk/Slack Apps employ this method to render images
256+
```go
257+
{{ $root := . }}
258+
{{ range $i, $v := .Images }}
259+
{{ $imageURL := imageSrcToURL $root $v.Src }}
260+
{{ if $imageURL }}![]({{$imageURL}}){{ end }}{{end}}
261+
```
262+
263+
11. **How to Convert and Upload Images to a Third-Party Notification Platform**
264+
- The transferImage function can be implemented, accepting parameters: $root and Src
265+
- Src can be an image_key from the Image Upload API or an accessible http/https image URL
266+
- Image size must not exceed 10 MB
267+
- Supported image formats include JPG, JPEG, PNG, WEBP, GIF, BMP, ICO, TIFF, HEIC
268+
- Requires enabling the application permission to access and upload image or file resources
269+
- Lark/Feishu Apps employ this method to render images
270+
271+
```go
272+
{{ $root := . }}
273+
{{ range $i, $v := .Images }}
274+
{{ $transferURL := transferImage $root $v.Src }}
275+
{{ if $transferURL }}![]({{$transferURL}}){{ end }}
276+
{{ end }}
277+
```
278+
279+
12. **How to use logical AND, OR, and other conditions for conditional rendering/content display judgment?**
251280

252281
```
253282
# Supported functions
@@ -280,7 +309,7 @@ CloseTime | int64 | No | Close time, EndTime is alert recovery time, CloseTime i
280309

281310
```
282311

283-
11. **How do I find more functions and their usage examples?**
312+
13. **How do I find more functions and their usage examples?**
284313
- Function list: https://github.com/flashcatcloud/sprig/blob/master/functions.go#L97
285314
- Usage examples: Check corresponding _test.go files, e.g., date function test cases at https://github.com/flashcatcloud/sprig/blob/master/date_test.go
286315

@@ -430,13 +459,22 @@ As shown below:
430459
431460
## Slack App
432461
---
462+
433463
You need to configure `Integration Center-Instant Message-Slack` integration first to send message cards. If custom content is not set, the system default template will be used, rendering only common label information:
434464
435465
```go
436-
{{if .Description}}*description* :{{toHtml .Labels.body_text .Description}}{{end}}
437-
{{if .Labels.resource}}*resource* : {{toHtml (joinAlertLabels . "resource" ", ")}}{{end}}
466+
{{if .Labels.body_text}}{{.Labels.body_text}}{{else if .Description}}{{.Description}}{{end}}
467+
{{if .Labels.resource}}*resource* : {{(joinAlertLabels . "resource" ", ")}}{{end}}
438468
{{range $k, $v := .Labels}}
439-
{{if not (in $k "resource" "body_text")}}*{{$k}}* : {{toHtml $v}}{{end}}{{end}}
469+
{{if not (in $k "resource" "body_text" "body_text_with_table")}}*{{$k}}* : {{$v}}{{end}}{{end}}
470+
{{ $root := . }}
471+
{{ range $i, $v := .Images }}
472+
{{ $imageURL := imageSrcToURL $root $v.Src }}
473+
{{ if $imageURL }}
474+
---
475+
![{{$v.Alt}}]({{$imageURL}})
476+
{{ end }}
477+
{{ end }}
440478
```
441479
442480
As shown below:
@@ -448,6 +486,7 @@ If you want to display only key label information, you can refer to the code seg
448486
- We've listed some common labels, you can add or remove as needed
449487
- Messages can be around 15000 characters long, content beyond this will be truncated
450488
- In Slack app, the system will automatically remove empty rendered lines (due to non-existent labels), so you can configure freely
489+
- To display images, use three consecutive hyphens `---` to separate it from other content. The image syntax must begin with `![` format, as demonstrated in the ​​FAQ​​ section
451490

452491
```go
453492
{{if (index .Labels "resource")}}*resource*:{{toHtml (joinAlertLabels . "resource" ", ")}}{{end}}

flashduty/zh/1. On-call/3. 配置管理/4.7 配置通知模板.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,35 @@ CloseTime | int64 | 否 | 关闭时间,EndTime 为告警恢复时间,CloseTi
247247
{{jsonGet .Labels.rule_note "#(userId==7777)#.instanceId" }}
248248

249249
```
250-
10. **如何使用逻辑与、或等条件进行内容显示判断?**
250+
251+
10. **如何通过图片[Image](#Image)的 Src 属性获取对应的图片 URL**
252+
- imageSrcToURL 可以实现,入参: $root 和 Src
253+
- 若 Src 是 [图片上传](https://developer.flashcat.cloud/api-344943718)接口的 image_key, 则 转换成短时间内可访问的地址
254+
- 若 Src 是 http/https 可访问地址,则直接返回该地址
255+
- 钉钉/Slack App 使用本函数来展示图片
256+
```
257+
{{ $root := . }}
258+
{{ range $i, $v := .Images }}
259+
{{ $imageURL := imageSrcToURL $root $v.Src }}
260+
{{ if $imageURL }}![]({{$imageURL}}){{ end }}{{ end }}
261+
```
262+
263+
11. **如何将图片转换并上传到第三方通知平台**
264+
- transferImage 可以实现,入参: $root 和 Src
265+
- Src 可以是 [图片上传](https://developer.flashcat.cloud/api-344943718) 接口的 image_key 或者 http/https 可访问图片地址
266+
- 图片大小不能超过 10 MB
267+
- 支持上传 JPG、JPEG、PNG、WEBP、GIF、BMP、ICO、TIFF、HEIC 格式的图片
268+
- 需要开启 应用 获取与上传图片或文件资源 权限
269+
- 飞书/Lark App 使用本函数来展示图片
270+
```
271+
{{ $root := . }}
272+
{{ range $i, $v := .Images }}
273+
{{ $transferURL := transferImage $root $v.Src }}
274+
{{ if $transferURL }}![]({{$transferURL}}){{ end }}
275+
{{ end }}
276+
```
277+
278+
12. **如何使用逻辑与、或等条件进行内容显示判断?**
251279

252280
```
253281
# 支持的函数
@@ -280,8 +308,7 @@ CloseTime | int64 | 否 | 关闭时间,EndTime 为告警恢复时间,CloseTi
280308

281309
```
282310

283-
284-
11. **如何查阅更多的函数及其使用示例?**
311+
13. **如何查阅更多的函数及其使用示例?**
285312
- 函数列表:https://github.com/flashcatcloud/sprig/blob/master/functions.go#L97
286313
- 使用示例:查看对应的\_test.go 文件,比如 date 函数测试用例见 https://github.com/flashcatcloud/sprig/blob/master/date_test.go
287314

@@ -432,16 +459,24 @@ CloseTime | int64 | 否 | 关闭时间,EndTime 为告警恢复时间,CloseTi
432459

433460
## Slack 应用
434461
---
462+
435463
您需要预先配置 `集成中心-即时消息- Slack` 集成,才能发送消息卡片。如果不设置自定义内容,将采用系统默认模板,仅渲染常见标签信息:
436464

437465
```go
438-
{{if .Description}}*description* :{{toHtml .Labels.body_text .Description}}{{end}}
439-
{{if .Labels.resource}}*resource* : {{toHtml (joinAlertLabels . "resource" ", ")}}{{end}}
466+
{{if .Labels.body_text}}{{.Labels.body_text}}{{else if .Description}}{{.Description}}{{end}}
467+
{{if .Labels.resource}}*resource* : {{(joinAlertLabels . "resource" ", ")}}{{end}}
440468
{{range $k, $v := .Labels}}
441-
{{if not (in $k "resource" "body_text")}}*{{$k}}* : {{toHtml $v}}{{end}}{{end}}
469+
{{if not (in $k "resource" "body_text" "body_text_with_table")}}*{{$k}}* : {{$v}}{{end}}{{end}}
470+
{{ $root := . }}
471+
{{ range $i, $v := .Images }}
472+
{{ $imageURL := imageSrcToURL $root $v.Src }}
473+
{{ if $imageURL }}
474+
---
475+
![{{$v.Alt}}]({{$imageURL}})
476+
{{ end }}
477+
{{ end }}
442478
```
443479

444-
445480
如下图所示:
446481

447482
<img src="https://download.flashcat.cloud/flashduty/integration/slack/slack_app_message.png" alt="drawing" style="display: block; margin: 0 auto;" width="600"/>
@@ -451,6 +486,7 @@ CloseTime | int64 | 否 | 关闭时间,EndTime 为告警恢复时间,CloseTi
451486
- 我们列出了一些常见标签,您可自行删减;
452487
- 消息可以发送长度为15000左右字符,超出后截断发送;
453488
- 在 Slack 应用中,系统会自动帮您删除(因标签不存在导致的)渲染空行,您可放心配置
489+
- 要展示图片,请用 `---` 把图片和其他内容分割开来, 开头是 `![` 格式, 参考 常见问题 部分
454490

455491
```go
456492
{{if (index .Labels "resource")}}*resource*:{{toHtml (joinAlertLabels . "resource" ", ")}}{{end}}

0 commit comments

Comments
 (0)