mirrorGit/feishu_notify.sh
songtianlun cce33ee405 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.
2025-01-04 18:57:33 +08:00

41 lines
883 B
Bash

#!/bin/bash
# 参数获取
WEBHOOK_URL="$1"
TITLE="$2"
CONTENT="$3"
# 飞书通知
send_feishu_notification() {
local message=$(jq -n \
--arg title "$TITLE" \
--arg text "$CONTENT" \
'{
msg_type: "post",
content: {
post: {
zh_cn: {
title: $title,
content: [[{
tag: "text",
text: $text
}]]
}
}
}
}'
)
curl -s -X POST "$WEBHOOK_URL" -H "Content-Type: application/json" -d "$message"
}
# 主函数
main() {
if [ -z "$WEBHOOK_URL" ] || [ -z "$TITLE" ] || [ -z "$CONTENT" ]; then
echo "错误: 缺少必要的飞书通知参数"
exit 1
fi
send_feishu_notification
}
main "$@"