Last active
September 17, 2020 01:29
-
-
Save stewsters/093b03091dd3c485b80f to your computer and use it in GitHub Desktop.
This sends messages as slackbot to slack
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
/** | |
* This sends messages as slackbot to slack using groovy | |
*/ | |
String.metaClass.encodeURL = { | |
java.net.URLEncoder.encode(delegate, "UTF-8") | |
} | |
def address = "https://slack.com/api/" | |
def method = "chat.postMessage" | |
def token = "Your API Token goes here" | |
def username = "slackbot" | |
def channel = "#general" //"@specific.teammember" | |
def text = "I am sentient slackbot." | |
def url = address + method + | |
'?' + 'token=' + token + | |
'&' + 'text=' + text.encodeURL() + | |
'&' + 'channel=' + channel.encodeURL() + | |
'&' + 'username=' + username.encodeURL() | |
println new URL(url).text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment