Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GasでSlackbot、データを2つとって結合して出力
function doPost(y) {
var token = PropertiesService.getScriptProperties().getProperty("xoxp-123");
var name = "name";
var token = PropertiesService.getScriptProperties().getProperty('SLACK_ACCESS_TOKEN');
var app = SlackApp.create(token);
var spreadsheet = SpreadsheetApp.openById('sheetID');
var sheet = spreadsheet.getSheetByName('シート1');
var range = sheet.getRange("シート1!C1").setFormula('=INDIRECT("シート1!A:A" & INT(RAND()*n+1))');
//A列内からランダムでC列1番セルに出力
var range2 = sheet.getRange("シート1!D1").setFormula('=INDIRECT("シート1!B:B" & INT(RAND()*n+1))');
//B列内からランダムでD列1番セルに出力
var message =sheet.getRange("シート1!C1").getValue()+sheet.getRange("シート1!D1").getValue();
//C1セルとD1セルの内容をつなげてbotの投稿として出力
return app.postMessage("#general", message, {
username: name,
icon_emoji: ':emojiname:'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.