Skip to content

Instantly share code, notes, and snippets.

@Hammond95
Created September 27, 2019 15:58
Show Gist options
  • Save Hammond95/ccee18b8e1f3fa56c6cb4f2a2eff7146 to your computer and use it in GitHub Desktop.
Save Hammond95/ccee18b8e1f3fa56c6cb4f2a2eff7146 to your computer and use it in GitHub Desktop.
Send a message in a slack channel using just curl.
#!/bin/bash
commit_hash=$(git rev-parse HEAD | head -c8)
text="*[DEPLOY] - ($commit_hash) I have made a new deploy for Project! :bomb:*"
token="YOUR_TOKEN"
slackhost="YOUR_SLACK_HOST"
channel="CHANNEL_NAME"
escapedText=$(echo "$text" | sed 's/"/\"/g' | sed "s/'/\'/g" )
json="{\"channel\": \"#$channel\", \"text\": \"$escapedText\",\"icon_emoji\":\":apple:\",\"username\":\"My Bot\"}"
# Example of complex data
#--data
# '{
# "channel": "",
# "text": "",
# "attachments": [{
# "text":"",
# "fallback":"",
# "color":"#3AA3E3",
# "attachment_type":"default",
# "callback_id":"select_simple_1234",
# "actions":[{
# "name":"winners_list",
# "text":"Who should win?",
# "type":"select",
# "data_source":"users"
# }]
# }]
# }'
curl \
-X POST \
-H "Authorization: Bearer $token" \
-H 'Content-type: application/json' \
--data "$json" \
https://slack.com/api/chat.postMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment