Skip to content

Instantly share code, notes, and snippets.

@pizzacat83
Created December 3, 2018 11:07
Show Gist options
  • Save pizzacat83/2efc20dbb6f2256e5bab04a6a4f74068 to your computer and use it in GitHub Desktop.
Save pizzacat83/2efc20dbb6f2256e5bab04a6a4f74068 to your computer and use it in GitHub Desktop.
if (updateFileMap.length != 0) {
var slackApp = SlackApp.create(slackAccessToken);
if(updateFileMap.length <= 20){
var attachments = [];
for( key in updateFileMap ){
var item = updateFileMap[key];
var title = item.updateType + ":"+item.filename;
var title_url = item.url;
var text = item.lastUpdate?item.updateType+'日時:' + Utilities.formatDate(item.lastUpdate, "JST", "yyyy-MM-dd HH:mm:ss") + '\n':''
var color = item.color;
attachments.push({color:color, title:title, title_link:title_url, text:text});
}
slackApp.postMessage(drivelogId, '', {'icon_url':'https://upload.wikimedia.org/wikipedia/commons/d/da/Google_Drive_logo.png','username':'UpdateNotifier', 'attachments': JSON.stringify(attachments)});
}else{
var l = {};
for( key in updateFileMap ){
var item = updateFileMap[key];
if(item.updateType in l){
l[item.updateType].push(item.filename);
}else{
l[item.updateType] = [item.filename];
}
}
for(key in l){
var text = l[key].join("\n");
var comment = l[key].length+"件のファイルが"+key+"されました。";
console.log(comment, text);
uploadTextFileToSlack(text, comment, drivelogId);
}
}
}
function uploadTextFileToSlack(content, comment, channels){
return UrlFetchApp.fetch("https://slack.com/api/files.upload", {method: "post", payload:{"content":content, initial_comment:comment,channels:channels}, headers:{"Authorization": "Bearer "+properties.getProperty('slackAccessToken2')}});
Logger.log(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment