-
-
Save Gaurav2728/b9654df90b1c78ffd3bd654a12aaddaa to your computer and use it in GitHub Desktop.
Post incoming webhook to Slack using Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Assumes: | |
| # - curl is installed | |
| # - you have a slack channel with an incoming webhook configured | |
| require 'json' | |
| def notify_slack(webhook_url, channel, username, text, image) | |
| payload = { | |
| :channel => channel, | |
| :username => username, | |
| :text => text, | |
| :icon_url => image | |
| }.to_json | |
| cmd = "curl -X POST --data-urlencode 'payload=#{payload}' #{webhook_url}" | |
| system(cmd) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment