Skip to content

Instantly share code, notes, and snippets.

@kob-to-wni
Created January 12, 2017 10:33
Show Gist options
  • Save kob-to-wni/7b18fe4fa485db04fc76ffb46e3a2586 to your computer and use it in GitHub Desktop.
Save kob-to-wni/7b18fe4fa485db04fc76ffb46e3a2586 to your computer and use it in GitHub Desktop.
Google App ScriptからSlackに投稿するサンプル
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