Created
January 12, 2017 10:33
-
-
Save kob-to-wni/7b18fe4fa485db04fc76ffb46e3a2586 to your computer and use it in GitHub Desktop.
Google App ScriptからSlackに投稿するサンプル
This file contains 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
function postSlack(botname, boticon, channel, message) { | |
var u = PropertiesService.getScriptProperties().getProperty('SLACK_WEBHOOK_URL'); | |
var p = { 'text': message }; | |
if (botname) { | |
p.username = botname; | |
} | |
if (/^:[^:]+:$/.test(boticon)) { | |
p.icon_emoji = boticon; | |
} else if (/^https?:\/\//.test(boticon)) { | |
p.icon_url = boticon; | |
} | |
if (channel) { | |
p.channel = '#' + channel; | |
} | |
var o = { | |
'method': 'POST', | |
'contentType': 'text/json', | |
'payload': JSON.stringify(p) | |
}; | |
UrlFetchApp.fetch(u, o); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment