feat: improve feishu notification formatting

- Refactor the message construction in `send_feishu_notification` to use `jq` for better readability and maintainability.
- Update the email and feishu notification content preparation in `main.sh` to use consistent variable names for subject and content.

These changes enhance the clarity of the notification messages and ensure that the code is easier to modify in the future. The use of `jq` also reduces the risk of syntax errors in JSON formatting.
This commit is contained in:
songtianlun
2025-01-04 18:57:33 +08:00
parent 3f4185589d
commit cce33ee405
2 changed files with 23 additions and 31 deletions

View File

@@ -7,27 +7,24 @@ CONTENT="$3"
# 飞书通知
send_feishu_notification() {
local message=$(cat <<EOF
{
"msg_type": "post",
"content": {
"post": {
"zh_cn": {
"title": "$TITLE",
"content": [
[
{
"tag": "text",
"text": "$CONTENT"
}
]
]
local message=$(jq -n \
--arg title "$TITLE" \
--arg text "$CONTENT" \
'{
msg_type: "post",
content: {
post: {
zh_cn: {
title: $title,
content: [[{
tag: "text",
text: $text
}]]
}
}
}
}
}
}
EOF
)
}'
)
curl -s -X POST "$WEBHOOK_URL" -H "Content-Type: application/json" -d "$message"
}