如何解决无法构建自定义 Slack 通知
经过大量研究,我发现了这个 .sh 脚本,它允许我向 Slack 频道发送非常简单的个性化通知(我未能将其发送给特定成员)。 我面临的问题是格式化通知消息的问题。 Slack 站点上提供的用于格式化通知的标签无法正常工作(我不知道如何使用它们!)。 必须在 Rundeck 作业每次执行结束时“从头开始”构建通知。 Rundeck 的“失败”和“成功”通知不适合用户。
这是 sh 脚本:
#!/bin/bash
#Usage: slackpost <channel> <message>
slackhost="https://hooks.slack.com/services"
token="XXXXXXXXXX/XXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXX"
slack_username="Someone-who-loves-you"
slack_icon="smile"
channel=$1
if [[ $channel == "" ]]
then
echo "No channel specified"
exit 1
fi
text="$2"
if [[ $text == "" ]]
then
echo "No text specified"
exit 1
fi
escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" )
json="{\"channel\": \"#$channel\",\"username\":\"${slack_username}\",\"icon_emoji\":\":${slack_icon}:\",\"text\": \"$escapedText\"}"
curl -s -d "payload=$json" "$slackhost/$token"
变量 $text 填充了 .txt 文件 (myFileText) 的内容:
myFileText 内容如下:
text="",{
blocks=[
{
"type": "section","text": {
"type": "mrkdwn","text": "Hello World! <@UNVD64N02> :tada: \n\n - a \n-b"
}
}
]
}
{
"blocks": [
{
"type": "section","text": "Hello,Assistant to the Regional Manager John Doe! *Martin Scott* wants to kNow where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
}
}
]
}
.sh 脚本运行如下:
sh slack_post.sh "channel-receiving-the-notification" "$(< myFileText)"
结果我有:
invalid_payload
任何想法都会有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。