Create a gist now

Instantly share code, notes, and snippets.

var TRIGGER_WORD = "skin:"
function doPost(e){
if (VERIFY_TOKEN != e.parameter.token) {
throw new Error("invalid token.");
}
var inputText = e.parameter.text.replace(TRIGGER_WORD,"");
var data = inputText.split(",");
recordSkinData(data);
var slackApp = SlackApp.create(Slack_Token);
slackApp.chatPostMessage(ChannelID,"スプレッドシートに記入しました!",{
username:"skinBot"
});
}
function getSheetName(){
var date = new Date();
var sheetName = date.getYear()+"/"+(date.getMonth()+1);
return sheetName;
}
function getNewSheet(spreadsheet){
var sheet = spreadsheet.insertSheet(""+getSheetName(),0);
sheet.getRange('A1').setValue("日付");
sheet.getRange('B1').setValue("水分量");
sheet.getRange('C1').setValue("水分");
sheet.getRange('D1').setValue("オイル");
sheet.getRange('E1').setValue("柔らかさ");
return sheet;
}
function debug(){
var data = [41,3,5,3];
recordSkinData(data);
}
function recordSkinData(data){
var id = SpreadSheetID;
var spreadsheet = SpreadsheetApp.openById(id);
var sheet = spreadsheet.getSheetByName(getSheetName());
if(sheet==null){
sheet = getNewSheet(spreadsheet);
}
var date = new Date();
var i = sheet.getLastRow()+1;
sheet.getRange('A'+i).setValue(date.getYear()+"/"+(date.getMonth()+1)+"/"+date.getDate());
sheet.getRange('B'+i).setValue(data[0]);
sheet.getRange('C'+i).setValue(data[1]);
sheet.getRange('D'+i).setValue(data[2]);
sheet.getRange('E'+i).setValue(data[3]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment