Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slack Notification by Shell
#!/usr/bin/env bash
# ユーザーIDを調べる場合のURL
# https://api.slack.com/methods/users.list/test
# ユーザーグループを調べる場合のURL
# https://api.slack.com/methods/usergroups.list/test
# ユーザーのメンション記法
# <@USER_ID>
# ユーザーグループのメンション記法
# <!subteam^GROUP_ID|group-name>
SLACK_WEBHOOK_URL='https://hooks.slack.com/services/xxxxxxxxx/yyyyyyyyy/xxxxxxxxxxxxxxxxxxxxxxxx'
USER_NAME="Script"
CHANNEL="#channel_name"
MESSAGE="$(cat << EOS | sed -e "s/[\"]/\\\&/g" | sed -e "s/$/\\\\\\\\n/g"
Description1
Description2
Description3
EOS
)"
PAYLOAD="$(cat << EOS | sed -e "s/[\"]/\\\&/g" | xargs
{
"channel": "${CHANNEL}",
"text": "${MESSAGE}",
"username": "${USER_NAME}",
"icon_emoji": ":blush:",
"link_names": 1
}
EOS
)"
echo curl -X POST --data-urlencode "payload=${PAYLOAD}" "${SLACK_WEBHOOK_URL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.