logo
2
1
Login

feishu-message

Send messages using Feishu custom bot. For details, refer to Feishu Documentation.

Parameters

  • sign_secret: String, Feishu custom bot signature key. If the bot has not enabled signature, this parameter can be ignored.
  • msg_type: String, message type, available values are text, post, interactive, default is text.
  • content: String | Object, message content. Required when msg_type is text or post. Refer to format description below.
  • card: Object, card message content. Required when msg_type is interactive. Refer to format description below.
  • filepath: String, message content file path. When this value exists, it will read content from the file and override content and card parameters. Refer to format description below.
  • base64_decode_tag: String, Base64 decoding suffix identifier. Default is _cnb_base64_decode. When a JSON field's key ends with this suffix and its value is true, the corresponding original field will undergo Base64 decoding.

Message Content Format Description

content

When msg_type is text, the message content format is:

{ "text": "New Update Notification" }

If parsing fails, the content will be sent as is. It will be automatically assembled into the following format:

{ "text": "$content" }

When msg_type is post, the message content format is:

{ "post": { "zh_cn": { "title": "Project Update Notification", "content": [ [ { "tag": "text", "text": "Project has updates: " }, { "tag": "a", "text": "Check here", "href": "http://www.example.com/" }, { "tag": "at", "user_id": "ou_18eac8********17ad4f02e8bbbb" } ] ] } } }

card

The card message content format is:

{ "elements": [ { "tag": "div", "text": { "content": "**West Lake**, located at No.1 Longjing Road, West Lake District, Hangzhou.", "tag": "lark_md" } }, { "actions": [ { "tag": "button", "text": { "content": "More Scenic Spots Introduction :rose:", "tag": "lark_md" }, "url": "https://www.example.com", "type": "default", "value": {} } ], "tag": "action" } ], "header": { "title": { "content": "Today's Travel Recommendation", "tag": "plain_text" } } }

filepath

The filepath corresponding file content format is:

{ "content": { "post": { "zh_cn": { "title": "Project Update Notification", "content": [ [ { "tag": "text", "text": "Project has no updates: " }, { "tag": "a", "text": "Check here", "href": "http://www.example.com/" } ], [ { "tag": "text", "text": "Project has no updates: " }, { "tag": "a", "text": "Check here", "href": "http://www.example.com/" } ] ] } } }, "card": { "elements": [ { "tag": "div", "text": { "content": "**East Lake**, located at No.1 Longjing Road, West Lake District, Hangzhou.", "tag": "lark_md" } }, { "actions": [ { "tag": "button", "text": { "content": "More Scenic Spots Introduction :rose:", "tag": "lark_md" }, "url": "https://www.example.com", "type": "default", "value": {} } ], "tag": "action" } ], "header": { "title": { "content": "Today's Travel Recommendation", "tag": "plain_text" } } } }

According to msg_type, either content or card content should exist.

Base64 Content Decoding

To resolve formatting errors caused by complex characters (e.g., line breaks, quotes) in JSON/YAML, the plugin supports Base64 decoding of field values. This feature supports recursive processing (including nested objects). This functionality is typically required when environment variables are directly assigned to fields, meaning it cannot be applied when directly manipulating environment variables during the CNB build process.

Usage:

  1. Convert the target field's value into a Base64 string.
  2. Add an auxiliary field at the same level with the key target_field_name + suffix (default suffix: _cnb_base64_decode).
  3. Set the auxiliary field's value to true.
  4. The plugin will automatically decode the target field and remove the auxiliary field.

Example: Assume the content to be sent contains line breaks. The original JSON is as follows:

{ "content": "5Zi/5L2g5aW977yBCui/meaYr+S4gOS4quebuOWvueWkjeadguS4lOWFt+acieaNouihjOespu+8jOWIhumalOespuetieWQhOenjeeJueauiuespuWPt+eahOWGheWuuQpAICYgKiogXHQgXG4=", "content_cnb_base64_decode": true }

The plugin automatically decodes the content and removes the content_cnb_base64_decode field.

Cloud Native Build Examples

The robot address and signature key can be configured in a private repository and imported into environment variables through imports.

# env.yml ROBOT: https://open.feishu.cn/open-apis/bot/v2/hook/xx SIGN_SECRET: xxx

Text Message

main: pull_request: - imports: https://xxx/env.yml stages: - name: send simple message image: tencentcom/feishu-message settings: robot: $ROBOT content: New Update Notification - name: send message image: tencentcom/feishu-message settings: robot: $ROBOT content: | { "text": "New Update Notification" }

Rich Text Message

main: pull_request: - imports: https://xxx/env.yml stages: - name: send message image: tencentcom/feishu-message settings: robot: $ROBOT msg_type: post content: | { "post": { "zh_cn": { "title": "Project Update Notification", "content": [ [{ "tag": "text", "text": "Project has updates: " }, { "tag": "a", "text": "Check here", "href": "http://www.example.com/" }, { "tag": "at", "user_id": "ou_18eac8********17ad4f02e8bbbb" }] ] } } }

Card Message

main: pull_request: - imports: https://xxx/env.yml stages: - name: send message image: tencentcom/feishu-message settings: robot: $ROBOT msg_type: interactive card: | { "elements": [ { "tag": "div", "text": { "content": "**West Lake**, located at No.1 Longjing Road, West Lake District, Hangzhou, Zhejiang Province, western part of Hangzhou city. The scenic area covers 49 square kilometers, with a water catchment area of 21.22 square kilometers and a lake area of 6.38 square kilometers.", "tag": "lark_md" } }, { "actions": [ { "tag": "button", "text": { "content": "More Scenic Spots Introduction :rose:", "tag": "lark_md" }, "url": "https://www.example.com", "type": "default", "value": {} } ], "tag": "action" } ], "header": { "title": { "content": "Today's Travel Recommendation", "tag": "plain_text" } } }

About

利用飞书自定义机器人发送消息

472.00 KiB
2 forks1 stars1 branches1 TagREADMEMIT license
Language
JavaScript73%
Shell24.6%
Dockerfile2.5%