ð©âð»ãã³ãšã³ãžãã¢ãchatGPTã掻çšããŠäŒæ©çµäºæå»ãªãã€ã³ããŒãäœã£ãŠã¿ãïŒâšå®éã®å¶äœå·¥çšãã¹ããããã€ã¹ãããã§è§£èª¬ããð
ã¯ããã«
ããã«ã¡ã¯
ãšãã¯ã¹ãã€ã³ãã¯ã³ã®CSOïŒchief spreadsheet officerïŒã®å£å ã§ãã
ä»åã¯ããã³ãšã³ãžãã¢ãªããchatGPTãé§äœ¿ããŠäŒæ©çµäºæå»ãªãã€ã³ããŒãå¶äœããçµç·¯ããå®éã®å·¥çšãã¹ããããã€ã¹ãããã§è©³çŽ°ã«è§£èª¬ããŠãããŸãã
ããŠãæ¬é¡ã«ç§»ãåã«ããã®ãããžã§ã¯ãã®èæ¯ãšç®çãã玹ä»ããããŸãã
èæ¯
- åœç€Ÿã§ã¯ãäŒæ©ã®éå§ãšçµäºãSlackã§æå»ããŠããŸãããäŒæ©çµäºã®æå»ãå¿ããããšããã°ãã°ãããŸããã
- ãŸããã¡ã³ããŒã«ããäŒæ©éå§ã®æå»ãç°ãªãããšããããŸãã
ç®ç
- ããããã®ã¡ã³ããŒãäŒæ©ãéå§ããŠããäžå®æéåŸããã®ã¡ã³ããŒã«å¯ŸããŠSlackã§ãªãã€ã³ããéä¿¡ããæ©èœãå®è£ ããã
ãããããå®éã«chatGPTãšã®ããåããéããŠãäžèšã®ç®çéæã«åããåãçµã¿ãæç³»åã«æ²¿ã£ãŠçŽ¹ä»ããŠãŸãããŸããç§ã®çºèšïŒããã³ããïŒãchatGPTã®è¿çãšãã«å¿ èŠãªéšåã®ã¿ãæç²ããŠæ²èŒãã圢ãåããŸãããã®ç¹ããç解ããã ããŸããšå¹žãã§ãã
ããããªïœãšæã£ãç¹ïŒäºåç·šïŒ
æ¬ç·šãããªãé·ããªã£ãŠããŸã£ããããä»åã®åãçµã¿ã§åããªãšæã£ãç¹ã«ã€ããŠããã€ãäŸç€ºããããŸãã
ãšã©ãŒã¡ãã»ãŒãžãæž¡ãããã»ã»ã»
ãšã©ãŒã«ã€ããŠæããŠãããã®ããªãšæããŸããããæ®éããã ãšæããŸãã
ä»åããšã©ãŒã¡ãã»ãŒãžãéã«æž¡ããŠããããªã«ïŒãã¿ãããªçµãã£ãŠãèãæ¹ãããã·ãŒã³ããã£ãã®ã§ããããã®æã«ãããã¯ãããããšã©ãŒã§ãããããããããèæ¯ã«ãã£ãŠèµ·ãã£ãŠããã®ã§ã以äžã®ãããªä¿®æ£ã§çŽããšæããŸãããšãããšãããŸã§ãã³ã¹ãããã§é§ãæããŠãããŸãããã»ããšã«ãæ°ãå©ããšã³ãžãã¢ãšåã£ãŠãïŒã£ãŠããäœéšã§ããã
botã®èšå®ããŠãªãã®ã«
incoming webhookãã€ãã£ãŠslackã«ã¡ãã»ãŒãžãéã£ãŠããã®ã§ããããã®botã®è¡šç€ºããŸã 觊ã£ãŠããªãã«ãé¢ãããé©åãªbotåã»ã¢ã€ã³ã³ïŒã¢ã€ã³ã³ãŸã§ïŒïŒã«ãªã£ãŠããŠãã¡ããã¡ãé©ããã®ã§ãããã¡ãã»ãŒãžãéãã¡ãœããã®äžã§payloadã§é©åã«èšå®ããŠãããŠããããã§ãããããã¯ã»ããšã«æåäœãèµ·ãã£ãã®ãããããªãã£ãã§ãã
æ¬ç·š
chatGPTãšã®å¯Ÿè©±ã¯åŒçšåœ¢åŒã§ç€ºãããŸãã
ç§ïŒslackäžã§ã®äŒæ©æå»ãoutgoing webhookã§GASã«é£ã°ããŠãxååŸã«äŒæ©çµäºã®ãªãã€ã³ããslackäžã§åœäººã«ã¡ã³ã·ã§ã³ããåäœã®GASäžã§åäœãããµã³ãã«ããã°ã©ã ãåºåããŠãã ãã
chatGPT
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.text;
if(text === 'äŒæ©éå§') {
var userName = data.user_name;
Utilities.sleep(1000 * 60 * X); // X is the time in minutes. Replace X with the time you want to wait before sending the reminder.
postMessage(userName);
}
return ContentService.createTextOutput();
}
function postMessage(userName) {
var url = 'https://slack.com/api/chat.postMessage';
var payload = {
'channel' : '@' + userName,
'text' : '<@' + userName + '> äŒæ©æéãçµäºããŸãããäœæ¥ãåéããŠãã ããã',
'as_user' : false,
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'headers': {
'Authorization': 'Bearer SLACK_API_TOKEN'
},
'payload' : JSON.stringify(payload)
};
UrlFetchApp.fetch(url, options);
}
ããèŠããšãããã®ã§ãããsleepã§å®è£
ããŠãã®ãç¬ããŸãã
äžæŠçœ®ããšããŠïŒãã®æç¹ã§ã¯æ°ã¥ããŠããªãã£ãïŒæ¬¡
ç§ïŒã¹ãã¬ããã·ãŒããç䌌çãªDBãšããŠæ±ãããªãã€ã³ãã®æå»ããåã«äŒæ©çµäºæå»ããã£ãå Žåã«ãªãã€ã³ãã解é€ãããµã³ãã«ããã°ã©ã ã瀺ããŠãã ãã
chatGPTïŒ
var SPREADSHEET_ID = "Your_Spreadsheet_ID";
var SHEET_NAME = "Your_Sheet_Name";
var SLACK_API_TOKEN = "Your_Slack_API_Token";
var REMINDER_TIME = 10; // 10 minutes for example
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.text;
var userName = data.user_name;
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
if(text === 'äŒæ©éå§') {
var date = new Date();
var startTime = date.getTime();
sheet.appendRow([userName, date, startTime, '']);
Utilities.sleep(REMINDER_TIME * 60 * 1000); // Reminder Time in ms
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
if(breakData[0] == userName && breakData[3] == '') {
postMessage(userName);
}
}
if(text === 'äŒæ©çµäº') {
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
if(breakData[0] == userName && breakData[3] == '') {
var date = new Date();
sheet.getRange(lastRow, 4).setValue(date);
}
}
return ContentService.createTextOutput();
}
function postMessage(userName) {
var url = 'https://slack.com/api/chat.postMessage';
var payload = {
'channel' : '@' + userName,
'text' : '<@' + userName + '> äŒæ©æéãçµäºããŸãããäœæ¥ãåéããŠãã ããã',
'as_user' : false,
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'headers': {
'Authorization': 'Bearer ' + SLACK_API_TOKEN
},
'payload' : JSON.stringify(payload)
};
UrlFetchApp.fetch(url, options);
}
ããªãããã³ãã©ããæºèŒãªæãã§ã¯ããããŸãããç¶ããŠãŸãããŸã
ç§ïŒäŒæ©éå§ããã³å®äºã¯å¥ã®ãµãŒãã¹ã«çŽã¥ããbotã«ã¡ã³ã·ã§ã³ãã"bi"ã宣èšãéå§ãã"bo"ã宣èšããŠå®äºããŸããã€ãŸããbiãŸãã¯boãæäžã«å«ãŸããŠãããã§åŠçãåå²ãããå¿ èŠããããŸãã
ãã®ç¹ã«ã€ããŠä¿®æ£ããé¡ãããããŸã
chatGPTïŒæå®ããããŒã¯ãŒããå«ãŸãããã©ããã§åŠçãåå²ãããããã«ãindexOfé¢æ°ã䜿çšããŠã¡ãã»ãŒãžããã¹ãã確èªããããšãã§ããŸãã
ïŒæç²ïŒ
if(text.indexOf('bi') !== -1) {
var date = new Date();
var startTime = date.getTime();
sheet.appendRow([userName, date, startTime, '']);
Utilities.sleep(REMINDER_TIME * 60 * 1000); // Reminder Time in ms
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
if(breakData[0] == userName && breakData[3] == '') {
postMessage(userName);
}
}
if(text.indexOf('bo') !== -1) {
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
if(breakData[0] == userName && breakData[3] == '') {
var date = new Date();
sheet.getRange(lastRow, 4).setValue(date);
}
}
return ContentService.createTextOutput();
}
å®ã¯ãã®æç¹ã§ãGASãå®è¡ããŠã倱æããŠããŸããã®ã§ãåå ãæ¢ãããã«
ç§ïŒèŠæèŠæã«console.log()ã§é©åãªå€ãã³ã³ãœãŒã«ã«åºåããããã«å€æŽããŠãã ãã
ããããéãªæ瀺ãã§ããã®ãããã§ãããchatGPTãæ¬åœã«ããããããšæãã®ã¯ããããç¬éã§ãã
chatGPTïŒGoogle Apps Scriptã§ã¯console.log()ã®ä»£ããã«Logger.log()ãå©çšå¯èœã§ãã
ïŒæç²ïŒ
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.text;
var userName = data.user_name;
Logger.log('Received text: ' + text + ', from user: ' + userName);
å¥ã«console.log()ã䜿ãããã§ãããããchatGPT倧å
çããã£ã¡ãæ¡çšãããªãåŸããŸãããã
ããããããã§ã¯ãšã©ãŒã®èª¿æ»ãã§ããŸããã§ããã
調ã¹ãŸããããå€éšããdoPost()ãåŒã³åºãããšãã¯ãã°åºåãããªããšã®ããšããã
å€éšããã®HTTPãªã¯ãšã¹ãã§åŒã³åºãããdoPosté¢æ°ã¯ããããã®ãã°åºåã¡ãœããã䜿ã£ãŠããã°ãåºåãããŸããã
ããã§ããããããšããããšã§ãåäœéããªãã®ã§ãããããªãã§ãããéœåºŠã¹ãã¬ããã·ãŒãã«ãã°ãæžãåºãããã«
ç§ïŒLoggerã®ãããã«ãDEBUGãšããååã®ã·ãŒãã«éœåºŠãã°ãæžãåºãããã«å€æŽãé¡ãããŸã
chatGPTïŒ
ïŒæç²ïŒ
var SPREADSHEET_ID = "Your_Spreadsheet_ID";
var SHEET_NAME = "Your_Sheet_Name";
var DEBUG_SHEET_NAME = "DEBUG";
var SLACK_API_TOKEN = "Your_Slack_API_Token";
var REMINDER_TIME = 10; // 10 minutes for example
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var text = data.text;
var userName = data.user_name;
writeLog('Received text: ' + text + ', from user: ' + userName);
ïŒäžç¥ïŒ
function writeLog(message) {
var date = new Date();
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(DEBUG_SHEET_NAME);
sheet.appendRow([date, message]);
}
Logger.log()ãwriteLog()ã«é©åã«çœ®ãæããããŸãããæé«ïŒ
ããããŸããŠãæå
ã§ã¡ãã£ãšè©ŠããŠããŸãããããããæåã®
var data = JSON.parse(e.postData.contents);
var text = data.text;
var userName = data.user_name;
ãã®æç¹ã§äœããã®ãšã©ãŒãèµ·ããŠããŠåŠçãäžæããŠããããšãããããŸããã®ã§ã
ç§ïŒä»¥äžã®éšåã§äœããã®ãšã©ãŒãèµ·ããŠãããããªã®ã§tryã§å²ã£ãŠãcatchãããšã©ãŒãåæ§ã«DEBUGã·ãŒãã«wrhteLogããããã«ããŠãã ãã
ãŒ
var data = JSON.parse(e.postData.contents);
var text = data.text;
var userName = data.user_name;
chatGPTïŒ
ïŒæç²ïŒ
try {
data = JSON.parse(e.postData.contents);
text = data.text;
userName = data.user_name;
} catch (error) {
writeLog('Error occurred: ' + error.message);
return ContentService.createTextOutput();
}
ãããã£ããã¿ã€ãããŠããŸãã DEBUGã·ãŒãã«wrhteLogããããã«
chatGPTããã¯åœããåã®ããã«ãã¯ãã¯ãwriteLog()ããã°ããã®ãããšç¢ºèªãããã«ãã£ãŠãããŠãŸãã
ãããš
Error occurred: Unexpected token 'o', "token=Y6pvP"... is not valid JSON
ãšãããšã©ãŒã衚瀺ãããŸããã®ã§ãéã«ãããŸãã
ãããä»åéçºããŠããŠchatGPTããïœïœïœãšãªã£ãç®æã§ãã
ç§ïŒã©ãæå³ïŒ
Error occurred: Unexpected token 'o', "token=Y6pvP"... is not valid JSON
chatGPTïŒãã®ãšã©ãŒã¡ãã»ãŒãžã¯ãJSONã®è§£æã«å€±æããããšã瀺ããŠããŸããå ·äœçã«ã¯ãJSON.parse()ã¡ãœãããåŒã³åºãããéã«ãç¡å¹ãªJSONããŒã¿ãæž¡ãããããŒã¹åŠçäžã«äºæããªãããŒã¯ã³ 'o' ãæ€åºããããšããå 容ã§ãã
"token=Y6pvP"... is not valid JSON ãšããéšåãç¹ã«éèŠã§ãããã¯æž¡ãããããŒã¿ãJSON圢åŒã§ã¯ãªããããããã¯ãšãªãã©ã¡ãŒã¿åœ¢åŒïŒkey=valueïŒã§ããããšã瀺ããŠããŸãã
Google Apps Scriptã§Slackã®Outgoing Webhooksã䜿çšããŠããå Žåãéä¿¡ãããããŒã¿ã¯ã¯ãšãªãã©ã¡ãŒã¿åœ¢åŒã§ããããšãäžè¬çã§ããã§ãã®ã§ãJSON.parse()ã䜿çšãã代ããã«ãããŒã¿ãé©åã«åŠçããå¿ èŠããããŸãã
以äžã¯ãä¿®æ£ãããµã³ãã«ã³ãŒãã®äžéšã§ããe.parameter ã䜿çšããŠã¯ãšãªãã©ã¡ãŒã¿ãåãåããŸãã
ãšããšã©ãŒã¡ãã»ãŒãžãæž¡ããšããšã©ãŒã®æå³ã ãã§ãªãããã®ãšã©ãŒãèµ·ãã£ãèæ¯ãé¡æšããããã«å¯Ÿããä¿®æ£ã³ãŒãæ¡ãæ瀺ããŠãããŸããã
ãã®äžè¡éããŸãããïŒæåããŸãã
"token=Y6pvP"... is not valid JSON ãšããéšåãç¹ã«éèŠã§ãããã¯æž¡ãããããŒã¿ãJSON圢åŒã§ã¯ãªããããããã¯ãšãªãã©ã¡ãŒã¿åœ¢åŒïŒkey=valueïŒã§ããããšã瀺ããŠããŸãã
function doPost(e) {
var text = e.parameter.text;
var userName = e.parameter.user_name;
try {
writeLog('Received text: ' + text + ', from user: ' + userName);
} catch (error) {
writeLog('Error occurred: ' + error.message);
return ContentService.createTextOutput();
}
// ... 以äžã¯ä»¥åãšåæ§
}
ãã®ä¿®æ£ã§ãã£ãããšã©ãŒã§åŠçã倱æããããšã¯ãªããªã£ãã®ã§ãå®éã®ããžãã¯ã®å®è£ ã«ãã€ã£ãŠãŸãããŸãã
ç§ïŒãªãã€ã³ããŒãŸã§ã®æéãsleepã§å®è£ ããã®ã¯gasã®å®è¡æéã®å¶éãšããåé¡ãšãå®è¡äžã«äŒæ©çµäºæå»ããã£ããšãã«ãã®æ å ±ãåãåããªããšããåé¡ãããã®ã§ãscriptAppãªããžã§ã¯ãã®triggerã¯ã©ã¹ãçšããŠå®è£ ã§ããŸããïŒ
chatGPTïŒã¯ããããã¯å¯èœã§ãããã ããäžã€ã®ã¹ã¯ãªããã§å€ãã®ããªã¬ãŒãäœæããå ŽåãGoogle Apps Scriptã®ããªã¬ãŒã«ã¯äžå®ã®å¶éããããŸãã®ã§æ³šæãå¿ èŠã§ãã
以äžã«ãäŒæ©éå§æã«ãªãã€ã³ããŒããªã¬ãŒãäœæããäŒæ©çµäºæã«ãã®ããªã¬ãŒãåé€ãããµã³ãã«ã³ãŒãã瀺ããŸãããã®ã³ãŒãã§ã¯ãcreateReminderTriggeré¢æ°ãšdeleteReminderTriggeré¢æ°ãæ°ããå®çŸ©ããŠããŸãã
ïŒæç²ïŒ
if(text.indexOf('bi') !== -1) {
var date = new Date();
var startTime = date.getTime();
sheet.appendRow([userName, date, startTime, '']);
writeLog('Break start logged for user: ' + userName);
// Create a reminder trigger
createReminderTrigger(userName);
}
if(text.indexOf('bo') !== -1) {
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
if(breakData[0] == userName && breakData[3] == '') {
var date = new Date();
sheet.getRange(lastRow, 4).setValue(date);
writeLog('Break end logged for user: ' + userName);
// Delete the reminder trigger
deleteReminderTrigger(userName);
}
}
ïŒäžç¥ïŒ
function createReminderTrigger(userName) {
ScriptApp.newTrigger('postReminder')
.timeBased()
.after(10 * 60 * 1000) // 10 minutes
.create();
writeLog('Reminder trigger created for user: ' + userName);
}
function deleteReminderTrigger(userName) {
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
if (triggers[i].getHandlerFunction() === 'postReminder') {
ScriptApp.deleteTrigger(triggers[i]);
}
}
writeLog('Reminder trigger deleted for user: ' + userName);
}
function postReminder() {
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
var lastRow = sheet.getLastRow();
var breakData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
var userName = breakData[0];
if(breakData[3] == '') {
postMessage(userName);
}
}
åãåã£ãtextã«biïŒäŒæ©éå§ã®å®£èšïŒãå«ãŸããŠãããcreateReminderTrigger()
ããboïŒäŒæ©å®äºã®å®£èšïŒãå«ãŸããŠãããdeleteReminderTrigger()
ãåŒã°ããããã«ä¿®æ£ãããå°äžã€ããããã®é¢æ°ãé©åã«å®çŸ©ãããŠããããšãããããŸãããã®ä¿®æ£ã§triggerãçºç«ãããšãã«åŒã°ããpostReminder()
ãå¿
èŠã«ãªã£ãŠããã®ã§å®çŸ©ãããŠããŸãã
ããããããããããè¿·èµ°ããŸããå ·äœçã«ã¯ãããã®ä¿®æ£æ¡ã³ãŒããè¿ä¿¡ãããŠããæäžã«é·æã§ãããããã«chatGPTã®çºèšãéåããã®ã§ããã€ãã®ããã«ãã€ã¥ããããªã¯ãšã¹ããããšããã
chatGPTïŒãããã¿ãŸããããããããã®ããªã¬ãŒããŠãŒã¶ãŒåã«çŽã¥ããæ¹æ³ãèããŠããªãã£ãããã§ãã
ãšèšããå床修æ£æ¡ã®ã³ãŒããéã£ãŠããŸããã
çµè«ããèšããšãããè€æ°ãŠãŒã¶ãŒãžã®å¯Ÿå¿ãäžå®å
šã ã£ãããããã®ããš
ç§ïŒãªãã€ã³ããŒã®åã¯åœåã®ããªãã®ææ¡éã
REMINDER_TIME
ãšããå®æ°ã§å®çŸ©ããŠããã®ã§ããã®ããã«çŽåã®ã³ãŒãã®ä¿®æ£ããé¡ãããããŸã
ãšããå°å€æŽãæã¿ã€ã€
ç§ïŒä»è©Šéšãããã®ã§ãã2åã®ãŠãŒã¶ãŒãé çªã«äŒæ©éå§ïŒbiïŒãããšãããããã®ãªãã€ã³ããŒã®ã¡ã³ã·ã§ã³ãããããåŸããç»é²ããæ¹ã«å¯ŸããŠãªãããŸãã
ç§ïŒAãããBããã®é åºã§biããã«ãé¢ãããããªãã€ã³ããŒãBãããAããã®é ã«ã¡ã³ã·ã§ã³ãããŸãã
ãšè€æ°åchatGPTãšããåãããŸããããchatGPTã®ã³ãŒããã©ãã©ãããããããªããªã£ãŠãããæ£çŽããã§ã¯äžåºŠè€æ°äººã®triggerãé©åã«ç®¡çããããšã¯é£ãããã ãšæããå¿ãæããããŠããŸããã
ããã§ãã¹ãã¬ããã·ãŒããç䌌çãªDBãšããŠäŒæ©äžã®æ¹ãšãã®äŒæ©éå§æå»ã管çããtriggerããããã³ã«äŒæ©éå§æå»ãèµ°æ»ããŠå¿
èŠãªè¡ã«ã¯ãªãã€ã³ããŒãéããšããã¢ã€ãã£ã¢ãæµ®ããã ã®ã§ã
ç§ïŒããªã¬ãŒãçºç«ããããšãã®åäœããDBå šäœã確èªããäœææ¥æããREMINDER_TIMEãçµéãããã®ãã¹ãŠã«é©åãªçžæã«postMessageããpostMessageãããªãã€ã³ããŒã«ã¯DBäžã§ãããå®äºããããšãããããããªåãèšããããã§ç®¡çããïŒãããã¯åœè©²è¡ã¯åé€ããïŒãšããåäœã®ã¢ã€ãã£ã¢ã«ã€ããŠã¯ãããã§ããããïŒã³ãŒãã£ã³ã°ããåã«ãã®ã¢ã€ãã£ã¢ã®é·æãšçæãæ瀺ããŠãã ãã
ãšãchatGPTã«æèŠãæ±ããŸããã
å³åº§ã«ã³ãŒãã£ã³ã°ããããšãããæªããããããªãããããã®ããã«äžåºŠchatGPTãšè°è«ããããšã¯çµæçã«ã¯ããã¢ãããŒãã ã£ããšæããŸãã
chatGPTïŒããªãã®ææ¡ã¯ããªã¬ãŒãçºç«ãããæã«ãGoogle ã¹ãã¬ããã·ãŒãïŒDBïŒãã¹ãã£ã³ããäŒæ©éå§ãã REMINDER_TIME ãçµéãããŠãŒã¶ãŒãã¹ãŠã«å¯Ÿã㊠postMessage ãè¡ããšãããã®ã§ãããããŠããªãã€ã³ããŒãéä¿¡ãããåŸããã®æ å ±ãèšé²ãŸãã¯è¡ãåé€ããããšã§ç®¡çããŸãã
ãã®ã¢ãããŒãã®é·æãšçæã¯ä»¥äžã®éãã§ãã
é·æ:
- åçŽã: ç¹å®ã®ãŠãŒã¶ãŒãç¹å®ã®ããªã¬ãŒã«é¢é£ä»ããå¿ èŠããªããã³ãŒããåçŽã«ãªããŸãã
- é åºã®æ£ç¢ºã: ãã¹ãŠã®ãªãã€ã³ããŒã¯ããŠãŒã¶ãŒãäŒæ©ãéå§ããé ã«æ£ç¢ºã«éä¿¡ãããŸãã
- è€æ°ã®ãªãã€ã³ããŒã®åæ管ç: ãã®ã¢ãããŒãã§ã¯ããªãã€ã³ããŒãçµéããå šãŠã®ãŠãŒã¶ãŒã«å¯ŸããŠäžåºŠã«ãªãã€ã³ããŒãéä¿¡ããŸããããã«ãããè€æ°ã®ãŠãŒã¶ãŒãã»ãŒåæã«äŒæ©ãéå§ããå Žåã§ããæ£ç¢ºã«ãªãã€ã³ããŒãéä¿¡ããããšãå¯èœã§ãã
çæ:
- å¹ç: ããªã¬ãŒãçºç«ãããã³ã«ãDBå šäœãã¹ãã£ã³ããå¿ èŠããããŸããããã«ãããDBã®ãµã€ãºã倧ãããªããšããã©ãŒãã³ã¹ãäœäžããå¯èœæ§ããããŸãã
- ãªãã€ã³ããŒã®ã¿ã€ãã³ã°ã®ç²ŸåºŠ: ããªã¬ãŒãå®æçã«çºç«ããèšå®ïŒäŸãã°æ¯åïŒã«äŸåããããããªãã€ã³ããŒã®ã¿ã€ãã³ã°ã¯å®å šã«æ£ç¢ºã§ã¯ãªãå¯èœæ§ããããŸããäŸãã°ãREMINDER_TIMEã10åã§ãã£ãŠããããªã¬ãŒã9å59ç§ãŸãã¯10å1ç§ã§çºç«ããå¯èœæ§ããããŸãã
- ããªã¬ãŒã®å¶é: Google Apps Scriptã«ã¯ããªã¬ãŒã®äœæãšåé€ã®åæ°ã«å¶éããããŸããããªã¬ãŒãé »ç¹ã«äœæã»åé€ãããšããããã®å¶éã«éããå¯èœæ§ããããŸãã
é·æã¯ããŠãããçæã«ã€ããŠã¯çå£ã«æ€èšããå¿
èŠããããšæããŸããã
ãã®äžã§1ã«ã€ããŠã¯éœåºŠçšæžã¿ã®è¡ãåé€ããããšã§ã«ããŒã§ãããšæããŸããã2ã«ã€ããŠã¯ç€Ÿå
ããŒã«ãªã®ã§1åçšåºŠã®èª€å·®ã¯èš±å®¹ããããšã«ããŸããã
ããããåé¡ã¯3ã§ãããã¯çéã§ããªãåé¡ã ã£ãããããŸã以äžã®ããã«ããŠæžå¿µç¹ã«ã€ããŠç¢ºèªããŸããã
ç§ïŒçæã®1ã«ã€ããŠã¯ããªãã€ã³ãæžã®è¡ãéœåºŠåé€ããããšã§ã«ããŒã§ãããšæããŸãã
çæã®3ã«ã€ããŠã以äžã®ãããªè³æããããŸãã
-
ããªã¬ãŒå¶é
åŠçã®èªååã®ããã«æéçã§ããªã¬ãŒãèšå®ããããšãå€ãããšæããŸããããã®ããªã¬ãŒã«ãå¶éããããŸãã察象 ç¡æã¢ã«ãŠã³ã Google Workspace
ããªã¬ãŒã®ç·å®è¡æé 90 å / æ¥ 6 æé / æ¥
ããªã¬ãŒæ° 20 / ãŠãŒã¶ãŒ / ã¹ã¯ãªãã 20 / ãŠãŒã¶ãŒ / ã¹ã¯ãªãã
-
ãã®ããªã¬ãŒæ°å¶éïŒ20/ãŠãŒã¶ãŒ/ã¹ã¯ãªããïŒã«ã¯çºç«æžã§ç¡å¹ã«ãªã£ãããªã¬ãŒã¯å«ãŸãªãã®ã§ãããïŒ
chatGPTïŒã¯ãããã®éãã§ããGoogle Apps Scriptã®ããªã¬ãŒæ°å¶éã¯ã¢ã¯ãã£ããªïŒæå¹ãªïŒããªã¬ãŒã«å¯ŸããŠã®ã¿é©çšãããŸãããã§ã«çºç«æžã¿ã§ç¡å¹åãããããªã¬ãŒããæåãŸãã¯ã¹ã¯ãªããã«ããåé€ãããããªã¬ãŒã¯å¶éæ°ã«ã¯å«ãŸããŸããã
ãããã£ãŠãåãŠãŒã¶ãŒã®äŒæ©éå§æã«ããªã¬ãŒãäœæãããªãã€ã³ããŒéä¿¡åŸã«ãã®ããªã¬ãŒãåé€ãããšããã¢ãããŒããåãå Žåã§ãã1ã€ã®ã¹ã¯ãªããå ã§åæã«ã¢ã¯ãã£ããªããªã¬ãŒã20åãè¶ ããªãéããããªã¬ãŒæ°å¶éã«ã¯éããªããšããããšã«ãªããŸãã
ãã ããããªã¬ãŒã®äœæãšåé€ãé »ç¹ã«è¡ããšããã®æäœèªäœããšã©ãŒãåŒãèµ·ããå¯èœæ§ããããŸãããã®ãããå¯èœãªéãããªã¬ãŒã®äœæãšåé€ã®åæ°ãæå°éã«æããããšãæãŸãããšèšããŸãã
ä»ãã®ç¬éã®ç€Ÿå ã§ã¯ãããªã¬ãŒãåæã«20åãŸã§äœ¿ããã®ã§ããã°æããåé¡ãªã皌åããã®ã§ãããå°æ¥æããã«éçã«äžè¶³ããããã«ãªãéžæã¯æããã«ã¢ã³ããã¿ãŒã³ã§ãã®ã§ã以äžã®ãããªã¢ã€ãã£ã¢ãèããŸããã
ç§ïŒè¥å¹²ããžãã¯ãè€éã«ãªããŸãããã¢ã¯ãã£ããªããªã¬ãŒã¯åžžã«1ã€ãšããå®è£ ã®ã¢ã€ãã£ã¢ãæµ®ãã³ãŸããã以äžã§ãããèšè¿°ããã®ã§ãè©äŸ¡ããé¡ãããŸãã
- bi宣èšããããšããdoPostãå®è¡ããã
- DBãã¹ãã£ã³ãã
- a. DBäžã®ããŒã¿ããçŸåšã¢ã¯ãã£ããªããªã¬ãŒããªããšå€æãããå ŽåïŒéœåºŠåé€æ¹åŒã§ããã°1è¡ãæå¹ãªããŒã¿ããªãå Žåããã©ã°åŒåé€ã§ããã°æå¹ãªè¡ããªãå ŽåïŒïŒREMINDER_TIME åŸã®ããªã¬ãŒãèšå®ããã
b. ã¢ã¯ãã£ããªããªã¬ãŒããããšå€æãããå ŽåïŒããªã¬ãŒã¯èšå®ããªããããŸã§ã®åäœã«ãã£ãŠå°ãªããšã1ã€ãæããæ倧ã§ã1ã€ã®æå¹ãªããªã¬ãŒãèšå®ãããŠããŸããããã¯æ倧ã§REMINDER_TIME åŸã§ããã3bã®å Žåã¯ãããããçãæéåŸã®ããªã¬ãŒã§ããå¯èœæ§ããããŸãã
- ããªã¬ãŒã«ãã£ãŠãªãã€ã³ããŒãå®è¡ããã
- äžã®ã¢ã€ãã£ã¢ã«ããDBãã¹ãã£ã³ããŠæå¹ãªãªãã€ã³ããŒãå šãŠå®è¡ãããè«ç/ç©ççã«DBã®è¡ãåé€ããã
- a. DBã¹ãã£ã³æã«ãä»åãªãã€ã³ããŒãéãå¿ èŠã¯ãªãããæªæ¥ã«ãªãã€ã³ããŒãéãå¿ èŠããããè¡ããã£ãå Žåã«ã¯ãã®ãªãã€ã³ããŒãŸã§ã®æéïŒã€ãŸãèšå®æå»ïŒREMINDER_TIME ããšãçŸåšæå»ãšã®å·®ïŒãDBã®åè¡ã«ã€ããŠä¿æããæãçŽè¿ã®ãªãã€ã³ããŒãŸã§ã®ããªã¬ãŒãå床èšå®ãã
b. DBã¹ãã£ã³æã«ä»åãªãã€ã³ããŒãéããã®ä»¥å€ã«æå¹ãªããŒã¿ïŒæªæ¥ã«ãªãã€ã³ããŒãéãã¹ãããŒã¿ïŒããªãå Žåãããªã¬ãŒãèšå®ããªãã
ãããåããŠchatGPT
chatGPTïŒããªããææ¡ããŠããããžãã¯ã¯ãå¿ èŠãªãšãã«ã®ã¿ããªã¬ãŒãåçã«äœæããã¢ã¯ãã£ããªããªã¬ãŒã¯åžžã«1ã€ã ãã«å¶éãããšãããã®ã§ããããã«ã¯ä»¥äžã®ãããªé·æãšçæããããŸãã
é·æ:
å¹ç: åæã«ã¢ã¯ãã£ããªããªã¬ãŒã1ã€ã ãã§ãããããGoogle Apps Scriptã®ããªã¬ãŒå¶éãæ°ã«ããå¿ èŠããªããªããŸãã
ãªãœãŒã¹ã®æå°å: äŒæ©ã®ãªãã€ã³ããŒãå¿ èŠãªãšãã ãããªã¬ãŒãäœæããããããäžå¿ èŠãªããªã¬ãŒãäœæã»åé€ããæéããªããªããŸãã
çæ:
ã³ãŒãã®è€éæ§: ãã®ã¢ãããŒãã§ã¯ãäŒæ©éå§æãšãªãã€ã³ããŒéä¿¡æã®2ã€ã®ç°ãªãã¿ã€ãã³ã°ã§ããªã¬ãŒã管çããå¿ èŠããããŸãããŸããã©ã®ããªã¬ãŒã次ã«å¿ èŠãã決å®ããããã«ãå šãŠã®è¡ãã¹ãã£ã³ããŠæãæ©ããªãã€ã³ããŒãèŠã€ããããžãã¯ãå¿ èŠã«ãªããŸãã
ã¹ãã£ã³ã®é »åºŠ: ãŠãŒã¶ãŒãäŒæ©ãéå§ãããçµäºããããããã³ããããŠãªãã€ã³ããŒãéä¿¡ããããã³ã«å šãŠã®è¡ãã¹ãã£ã³ããå¿ èŠããããŸããããã¯å€§ããªããŒã¿ããŒã¹ã®å Žåãããã©ãŒãã³ã¹ã«åœ±é¿ãäžããå¯èœæ§ããããŸãã
å šäœãšããŠãææ¡ãããã¢ãããŒãã¯å¹æçã§ãããããªãã®å¿ èŠæ§ã«ããåã£ãŠãããšæãããŸãããã ããäžèšã®ãããªçæã«ã€ããŠã¯æ³šæããŠèšèšãšå®è£ ãé²ããŠãã ããã
ãšãæªããªããããªã®ã§ãã®æ¹éã§è¡ãããšã«ããŸããã
ãããããã®åŸã®é²ãæ¹ã«ã€ããŠããã課é¡ããããŸããã
ç§ïŒåäœå¯èœãªããžãã¯ãèšèšããŠãã ãããéãå€ããªããšæãããã®ã§ãå ãã¯å®æ°ã®å®£èšéšåã®ã³ãŒãã®ã¿ãšãå¿ èŠãªé¢æ°ã®ãªã¹ããæ瀺ããŠãã ãã
å®éã«ã¯å
ã»ã©ã®èªåã®çºèšãå床æ²èŒããïœãããåäœå¯èœãªïœããšç¶ããŠäžã®çºèšã«ãªã£ãŠããŸãã
ãããåããchatGPTã¯ä»¥äžã®ããã«è¿äºãããŠããŸãã
chatGPTïŒ
// Slackã«ã¡ãã»ãŒãžãæçš¿ããããã®URL
var SLACK_WEBHOOK_URL = 'YOUR_SLACK_WEBHOOK_URL';
// ãªãã€ã³ããŒãŸã§ã®æéïŒåäœ: ããªç§ïŒ
var REMINDER_TIME = 15 * 60 * 1000;
// ã¹ãã¬ããã·ãŒãã®ID
var SPREADSHEET_ID = 'YOUR_SPREADSHEET_ID';
// ã¹ãã¬ããã·ãŒãã®ã·ãŒãå
var SHEET_NAME = 'Break';
// ãã°ãåºåããã·ãŒãå
var LOG_SHEET_NAME = 'DEBUG';
// ã¹ãã¬ããã·ãŒãã®ã¢ã¯ã»ã¹
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(SHEET_NAME);
// ãã°åºåçšã·ãŒãã®ã¢ã¯ã»ã¹
var logSheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(LOG_SHEET_NAME);
// äŒæ©éå§ã®ããŒã¯ãŒã
var BREAK_START_KEYWORD = 'bi';
// äŒæ©çµäºã®ããŒã¯ãŒã
var BREAK_END_KEYWORD = 'bo';
ããã«ç¶ãã以äžã®é¢æ°ãå®è£ ããŸãïŒ
doPost(e) - Slackããã®ãªã¯ãšã¹ããåãåããããã«å¯Ÿå¿ããã¢ã¯ã·ã§ã³ãè¡ããŸãã
setReminderTrigger(userName, timeToTrigger) - æå®ãããæéåŸã«ãªãã€ã³ããŒã®ããªã¬ãŒãèšå®ããŸãã
deleteTriggers() - ãã¹ãŠã®ãªãã€ã³ããŒããªã¬ãŒãåé€ããŸãã
scanDatabase() - ããŒã¿ããŒã¹ãã¹ãã£ã³ããŠãæªæ¥ã®ãªãã€ã³ããŒãå¿ èŠãªè¡ãããããã§ãã¯ãããã®æ å ±ãè¿ããŸãã
sendReminder() - ããªã¬ãŒã®çºç«ã«ããå®è¡ããããªãã€ã³ããŒãéããããŒã¿ããŒã¹ãæŽæ°ããŸãã
writeLog(message) - DEBUGã·ãŒãã«ãã°ãæžã蟌ã¿ãŸãã
åé¢æ°ã®è©³çŽ°ãªå®è£ ã¯å ·äœçãªèŠä»¶ãšããžãã¯ã«ãããŸãããäžèšã®éªšåãããšã«åé¢æ°ã詳现ã«èšèšãããããçµã¿åãããŠå šäœã®ã·ã¹ãã ãäœãäžããããšãã§ããŸãã
ãªãã»ã©ãããŸããªããæªããªãæ°ãããŸããšã
REMINDER_TIME
ã®èšå®ããããã¥ããã£ãã®ã§ããããŸã§èšå®ã¯åã§ãããªç§ãžã®å€æã¯æ©æ¢°çã«ãã£ãŠãããããã«ããŸããã
ç§ïŒãŸãå®æ°éšã«ã€ããŠãREMINDER_TIMEã¯åã§å ¥åã§ããããã«ããã·ã¹ãã çã«ããªç§ã®å®æ°ãä»ã«æºåããããã¯èšç®ã«ãã£ãŠæ±ããããã«ããŸããã
chatGPTïŒ
ïŒæç²ïŒ
// ãªãã€ã³ããŒãŸã§ã®æéïŒåäœ: åïŒ
var REMINDER_TIME_MINUTES = 15;
// ãªãã€ã³ããŒãŸã§ã®æéãããªç§åäœã§èšç®ïŒ1å = 60,000ããªç§ïŒ
var REMINDER_TIME = REMINDER_TIME_MINUTES * 60 * 1000;
ç¶ããŠã·ãŒãåãªã©ã®ç®¡çã®ããã«
ç§ïŒDBã®ã·ãŒãã«é¢ããå€æ°åã¯DBã·ãŒãã«é¢ãããã®ã ãšå€æ°åããç解ã§ããããã«DB_ãdbãå€æ°åã®ã«ãŒã«ã«åãåççã«ä»èšããŠãã ããããŸãå®éã®ã·ãŒãåã¯DBã§ãã®ã§ãããå€æŽé¡ããŸã
chatGPTïŒ
ïŒæç²ïŒ
// ã¹ãã¬ããã·ãŒãã®DBã·ãŒãå
var DB_SHEET_NAME = 'DB';
// ãã°ãåºåããã·ãŒãå
var LOG_SHEET_NAME = 'DEBUG';
// ã¹ãã¬ããã·ãŒãã®DBã·ãŒãã®ã¢ã¯ã»ã¹
var dbSheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(DB_SHEET_NAME);
// ãã°åºåçšã·ãŒãã®ã¢ã¯ã»ã¹
var logSheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName(LOG_SHEET_NAME);
ããŠãããããå®éã«å¿ èŠãªé¢æ°ãå®è£ ããŠããããšèããŠããŸãããå ·äœçã«ã¯ãå ã»ã©chatGPTããªã¹ãåããŠããã以äžã®é¢æ°
ããã«ç¶ãã以äžã®é¢æ°ãå®è£ ããŸãïŒ
doPost(e) - Slackããã®ãªã¯ãšã¹ããåãåããããã«å¯Ÿå¿ããã¢ã¯ã·ã§ã³ãè¡ããŸãã
setReminderTrigger(userName, timeToTrigger) - æå®ãããæéåŸã«ãªãã€ã³ããŒã®ããªã¬ãŒãèšå®ããŸãã
deleteTriggers() - ãã¹ãŠã®ãªãã€ã³ããŒããªã¬ãŒãåé€ããŸãã
scanDatabase() - ããŒã¿ããŒã¹ãã¹ãã£ã³ããŠãæªæ¥ã®ãªãã€ã³ããŒãå¿ èŠãªè¡ãããããã§ãã¯ãããã®æ å ±ãè¿ããŸãã
sendReminder() - ããªã¬ãŒã®çºç«ã«ããå®è¡ããããªãã€ã³ããŒãéããããŒã¿ããŒã¹ãæŽæ°ããŸãã
writeLog(message) - DEBUGã·ãŒãã«ãã°ãæžã蟌ã¿ãŸãã
åé¢æ°ã®è©³çŽ°ãªå®è£ ã¯å ·äœçãªèŠä»¶ãšããžãã¯ã«ãããŸãããäžèšã®éªšåãããšã«åé¢æ°ã詳现ã«èšèšãããããçµã¿åãããŠå šäœã®ã·ã¹ãã ãäœãäžããããšãã§ããŸãã
ããããé ã«èšè¿°ããŠããããšæã£ãã®ã§ããããç¶ããæžããŠãã ããããšç¶ããŠãããšããã®ææ瀺ããé¢æ°ãšã¯éãé¢æ°ã§å®è£ ãå§ããã®ã§ãããããžãããä»çŸåšã®ã³ãŒããèŠããŠã"ãããããããŠã»ãã"ãšãããµãã«ãªã¯ãšã¹ããã圢ã®ããã³ããã®æãæ¹ã«å€æŽããŸãããããã¯ããªãæå¹ã ã£ããšæããŸãã
ç§ïŒä»¥äžã®ãããªåäœãéæãããã³ãŒãã®èšè¿°ããé¡ãããããŸãã
- bi宣èšããããšããdoPostãå®è¡ããã
- DBãã¹ãã£ã³ãã
3a. DBäžã®ããŒã¿ããçŸåšã¢ã¯ãã£ããªããªã¬ãŒããªããšå€æãããå ŽåïŒéœåºŠåé€æ¹åŒã§ããã°1è¡ãæå¹ãªããŒã¿ããªãå Žåããã©ã°åŒåé€ã§ããã°æå¹ãªè¡ããªãå ŽåïŒïŒREMINDER_TIME åŸã®ããªã¬ãŒãèšå®ããã
3b. ã¢ã¯ãã£ããªããªã¬ãŒããããšå€æãããå ŽåïŒããªã¬ãŒã¯èšå®ããªã
ãŒãããŸã§ã®åäœã«ãã£ãŠå°ãªããšã1ã€ãæããæ倧ã§ã1ã€ã®æå¹ãªããªã¬ãŒãèšå®ãããŠããŸããããã¯æ倧ã§REMINDER_TIME åŸã§ããã3bã®å Žåã¯ãããããçãæéåŸã®ããªã¬ãŒã§ããå¯èœæ§ããããŸãã- ããªã¬ãŒã«ãã£ãŠãªãã€ã³ããŒãå®è¡ããã
- äžã®ã¢ã€ãã£ã¢ã«ããDBãã¹ãã£ã³ããŠæå¹ãªãªãã€ã³ããŒãå šãŠå®è¡ãããè«ç/ç©ççã«DBã®è¡ãåé€ããã
6a. DBã¹ãã£ã³æã«ãä»åãªãã€ã³ããŒãéãå¿ èŠã¯ãªãããæªæ¥ã«ãªãã€ã³ããŒãéãå¿ èŠããããè¡ããã£ãå Žåã«ã¯ãã®ãªãã€ã³ããŒãŸã§ã®æéïŒã€ãŸãèšå®æå»ïŒREMINDER_TIME ããšãçŸåšæå»ãšã®å·®ïŒãDBã®åè¡ã«ã€ããŠä¿æããæãçŽè¿ã®ãªãã€ã³ããŒãŸã§ã®ããªã¬ãŒãå床èšå®ãã
6b. DBã¹ãã£ã³æã«ä»åãªãã€ã³ããŒãéããã®ä»¥å€ã«æå¹ãªããŒã¿ïŒæªæ¥ã«ãªãã€ã³ããŒãéãã¹ãããŒã¿ïŒããªãå Žåãããªã¬ãŒãèšå®ããªãã次ã®ãå®æ°å®£èšãšdoPostã«ç¶ããŠèšè¿°ããŠãã ãã
// Slackã«ã¡ãã»ãŒãžãæçš¿ããããã®URL var SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/xxx'; // ãªãã€ã³ããŒãŸã§ã®æéïŒåäœ: åïŒ var REMINDER_TIME_MINUTES = 1; // ãªãã€ã³ããŒãŸã§ã®æéãããªç§åäœã§èšç®ïŒ1å
ïŒç¥ïŒ
chatGPTïŒ
ïŒæç²ïŒ
if (now - startTime >= REMINDER_TIME) {
// ãªãã€ã³ããŒãéä¿¡ããåŠçãããã«æžã
dbSheet.deleteRow(i + 1);
} else {
var timeLeft = startTime + REMINDER_TIME - now;
if (nextReminderTime === null || timeLeft < nextReminderTime) {
nextReminderTime = timeLeft;
}
}
ãããæžãã®ãããªããªãã ã
ç§ïŒãªãã€ã³ããéä¿¡ããåŠçã¯postMessageã§å€ã ãããŠãã ãã
chatGPTïŒ
// Slackã«ã¡ãã»ãŒãžãæçš¿ãã
function postMessage(userName) {
writeLog("postMessage started");
try {
var payload = {
"text": "ãªãã€ã³ããŒïŒ " + userName + "ãããäŒæ©çµäºã®æéã§ãã",
"username": "reminder-bot",
"icon_emoji": ":alarm_clock:"
};
var options = {
"method" : "post",
"payload" : JSON.stringify(payload)
};
UrlFetchApp.fetch(SLACK_WEBHOOK_URL, options);
} catch (error) {
writeLog(`Error occurred in postMessage: ${error}`);
}
}
ããã®
ç§ïŒå ã»ã©ã®ã//ãªãã€ã³ããŒãéä¿¡ããåŠçãããã«æžããã®éšåãpostmessageé¢æ°ãçšããŠé©åãªåœ¢ã«ãªã©ã€ãããŠãã ãããååŸ3è¡ã»ã©ã®è¡šç€ºã§çµæ§ã§ã
ããã®è¿äºããŸãã¡ãã£ãšããããã£ãïŒæ¢åã®ã³ãŒããšéœéœ¬ã£ãŠãïŒã®ã§æ¹ããŠ
ç§ïŒã¡ãã£ãšèšè¿°ãããã»ã©ãšéãã®ã§ç¢ºèªã§ããããã»ã©ããªããææ¡ããŠãã ãã£ã以äžã®sendReminderãããšã«postmessageãçšããèšè¿°ã«ä¿®æ£ããŠãã ãã
ãŒ
// ãªãã€ã³ããŒãéä¿¡ãã次ã®ãªãã€ã³ããŒã®ããªã¬ãŒãèšå®ãã
function sendReminder() {
writeLog("sendReminder started");
try {
var now = new Date().getTime();
var data = dbSheet.getDataRange().getValues();
var nextReminderTime = null;
for (var i = 0; i < data.length; i++) {
var userName = data[i][0];
var startTime = new Date(data[i][1]).getTime();
if (now - startTime >= REMINDER_TIME) {
// ãªãã€ã³ããŒãéä¿¡ããåŠçãããã«æžã
dbSheet.deleteRow(i + 1);
} else {
var timeLeft = startTime + REMINDER_TIME - now;
if (nextReminderTime === null || timeLeft < nextReminderTime) {
nextReminderTime = timeLeft;
}
}
}
if (nextReminderTime !== null) {
ScriptApp.newTrigger("sendReminder")
.timeBased()
.after(nextReminderTime)
.create();
}
} catch (error) {
writeLog(`Error occurred in sendReminder: ${error}`);
}
}
ãšããã¯ãå®éã®ã³ãŒããæ瀺ããŠãããä¿®æ£ããŠãããããã«ããŸããã
ãŸãããã§ã以äžã®ç®æã§ãforã®äžã§åè¡æ¯ã«è¡ãåé€ããŠããã®ã§
ç§ïŒåè¡ãforã§ã¹ãã£ã³ããŠããæäžã«çŽæ¥è¡ãåé€ãããšforã®ã¹ãã£ã³ãç Žç¶»ããŸãããïŒ
chatGPTïŒãã®éãã§ãåè¡ãã¹ãã£ã³ããŠããéäžã§è¡ãåé€ãããšãåé€åŸã®è¡ã®ã€ã³ããã¯ã¹ãå€ãããããã次ã®ã«ãŒãåŠçã«åœ±é¿ãäžããŸãããããã£ãŠãéåžžã¯è¡ãåé€ãããšãã¯ãæåŸã®è¡ããéé ã«åé€ãããããŸãã¯åé€ããè¡ãå¥ã®é åã«æ ŒçŽããŠããã«ãŒãçµäºåŸã«åé€ããã®ãäžè¬çã§ãã
以äžã®ããã«ä¿®æ£ããŸãã
// ãªãã€ã³ããŒãéä¿¡ãã次ã®ãªãã€ã³ããŒã®ããªã¬ãŒãèšå®ãã
function sendReminder() {
writeLog("sendReminder started");
try {
var now = new Date().getTime();
var data = dbSheet.getDataRange().getValues();
var nextReminderTime = null;
var rowsToDelete = [];
for (var i = 0; i < data.length; i++) {
var userName = data[i][0];
var startTime = new Date(data[i][1]).getTime();
if (now - startTime >= REMINDER_TIME) {
// ãªãã€ã³ããŒãéä¿¡
postMessage(userName);
// åé€ããè¡çªå·ãèšé²
rowsToDelete.push(i + 1);
} else {
var timeLeft = startTime + REMINDER_TIME - now;
if (nextReminderTime === null || timeLeft < nextReminderTime) {
nextReminderTime = timeLeft;
}
}
}
// èšé²ããè¡ãåé€
for (var i = rowsToDelete.length - 1; i >= 0; i--) {
dbSheet.deleteRow(rowsToDelete[i]);
}
if (nextReminderTime !== null) {
ScriptApp.newTrigger("sendReminder")
.timeBased()
.after(nextReminderTime)
.create();
}
} catch (error) {
writeLog(`Error occurred in sendReminder: ${error}`);
}
}
ããã§ãforã«ãŒããç Žç¶»ããããšãªããæ£ç¢ºã«è¡ãåé€ããããšãã§ããŸãã
ããããšãããããŸãã
ãšããããã§ç¶ããŠ
ç§ïŒããããšãããããŸããããã§ã¯writeLogé¢æ°ãèšè¿°ããŠãã ãã
chatGPTïŒ
// ãã°ãåºåããé¢æ°
function writeLog(logText) {
try {
var currentTime = new Date();
var logOutput = currentTime + ': ' + logText;
// ã¹ãã¬ããã·ãŒãã®æå®ãããã·ãŒãã«ãã°ãè¿œå
logSheet.appendRow([logOutput]);
} catch (error) {
// äœããã®çç±ã§ãã°ã®æžã蟌ã¿ã«å€±æããå Žå
Logger.log('Failed to write log: ' + error);
}
}
ãšããŠãåœåã®ããã«ã¹ãã¬ããã·ãŒãã«ãã°ãåºåããããã«ããŸããã
ãããŸã§ã§ãšããããåŠçã¯äžéãèšè¿°ã§ããã®ã§
ç§ïŒçŸåšä»¥äžã®ããã«ãªã£ãŠããŸããããã§ãåžæããåäœãéæãããããªãã¡ã¯ã¿ãªã³ã°ããé¡ãããŸã
ïŒçŸç¶ã®ã³ãŒããchatGPTã«æž¡ãïŒ
chatGPTïŒãã®ã³ãŒãã¯éåžžã«è¯ãã§ããŠãããåºæ¬çãªæ©èœã¯æ£åžžã«åäœãããšæããŸãããã ãã以äžã®ç¹ãå°ãæ¹è¯ããããšã§ããããã¹ããªã³ãŒãã«ã§ããŸãïŒ
- postMessageé¢æ°ã§æçš¿ã®æåã»å€±æããã°åºåããããã«ããã
- isActiveTriggerExistsé¢æ°ã§ããããžã§ã¯ãã«ããå šãŠã®ããªã¬ãŒãã¹ãã£ã³ããŠããŸãããgetProjectTriggersã¯äžå®éã®åŠçæéãæ¶è²»ããŸããããªã¬ãŒã®ååšããã§ãã¯ããã®ã¯ãæ°ãã«ããªã¬ãŒãèšå®ããéã ãã§è¯ãã®ã§ãstartBreaké¢æ°ã§ã®ã¿å®è¡ããããã«ããã
- çŸåšãdoPostå ã§äŸå€ãçºçãããšãããããã°ã«èšé²ãããã ãã§ãSlackãžã®å¿çã¯è¡ãããŸããããã®ãŸãŸã§ã¯ããšã©ãŒãçºçããå Žåã«ãŠãŒã¶ãŒã¯åå¿ãèŠãããšãã§ããŸããããããã£ãŠããšã©ãŒãçºçããå Žåã«ãäœããã®å¿çãè¿ãããã«doPostãä¿®æ£ãããšè¯ãã§ãããã
以äžã«æ¹è¯çã®ã³ãŒãã瀺ããŸãïŒ
// ...
function doPost(e) {
writeLog("doPost started");
try {
// ...
} catch (error) {
writeLog(`Error occurred in doPost: ${error}`);
return ContentService.createTextOutput(JSON.stringify({ 'text': 'ãšã©ãŒãçºçããŸãã: ' + error }));
}
}
// ...
function sendReminder() {
writeLog("sendReminder started");
try {
// ...
// èšé²ããè¡ãåé€
for (var i = rowsToDelete.length - 1; i >= 0; i--) {
dbSheet.deleteRow(rowsToDelete[i]);
writeLog(`Deleted row ${rowsToDelete[i]} in sendReminder`);
}
// ...
} catch (error) {
writeLog(`Error occurred in sendReminder: ${error}`);
}
}
// ...
// Slackã«ã¡ãã»ãŒãžãæçš¿ãã
function postMessage(userName) {
writeLog("postMessage started");
try {
// ...
var response = UrlFetchApp.fetch(SLACK_WEBHOOK_URL, options);
if (response.getResponseCode() === 200) {
writeLog(`Successfully sent message to ${userName}`);
} else {
writeLog(`Failed to send message to ${userName}. Response code: ${response.getResponseCode()}`);
}
} catch (error) {
writeLog(`Error occurred in postMessage: ${error}`);
}
}
chatGPTå çããã®ç±ãèªç»èªè³ãåãã€ã€ããã¡ãã®ã³ãŒãã¯ãdoPost(e)ã®åŒæ°'e'ãJSON圢åŒãšã¿ãªããŠããŒã¹ããããšããŠããŸãããããããã§ã«ãã®'e'ãJSON圢åŒã§ã¯ãªããšããããšã¯çµè«ã¥ããããŠããŸãããã®ç¹ãææããã®ã§ãããchatGPTã¯æãããã«ã³ãŒããä¿®æ£ããŠãããŸããã§ãããçµæçã«ããã®éšåã¯æäœæ¥ã§ä¿®æ£ããããšã«ããŸããã
ãŸããçŸåšã®ã³ãŒãã§ã¯ãç¹å®ã®æèšãå¿ èŠãªç®æããšã«çŽæ¥èšè¿°ãããŠãããããã§ã¯ä¿å®æ§ãæãªãããŸããããã§ããããã®æèšãå®æ°åããããšãèããŸãããããããäžæŠãã®æ¹åã§æèãé²ãããšãããããããã¹ãã¬ããã·ãŒãã§çŽæ¥èšå®ã§ããæ¹ã䟿å©ãããããªããšèããããã«ãªããŸããã
ç§ïŒãããã®ã¹ã¯ãªããã®äžã«ã¯slackã§è¿åŽããæååãªã©ããã¿ã§èšè¿°ãããŠããç®æãå€ããããŸãã
æçµçã«ãããã®å®çŸ©ã¯ã¹ãã¬ããã·ãŒãäžã§ã§ããããã«ãããã§ãã
ãã®ããã«ä»¥äžã®é ã§åŠçãããã¯ã¹ãã¬ããã·ãŒãäžã§ã®äœæ¥ãå®çŸ©ããŠãã ãã
- æèšå®çŸ©ããã·ãŒãåãèããŠãã ãã ç§ã¯ãããæ¡çšããŸã
- Aåã«æèšã®èŠåºãïŒäººéãèŠãŠã©ããªæèšãèããã°ããã®ããããããã«ïŒãèããBåã«çŸç¶ã®æèšãããŒãã«åœ¢åŒã§ç€ºããŠãã ãã
- ãããã®æèšïŒ2ã§ç€ºãçŸç¶ã®æèšïŒã¯åçã«å®çŸ©ãããç®æãå€ãããã®ã§ããããã£ãç®æã¯å€æ°åããããã§ã¹ã¯ãªããã®äžã§é©åã«çœ®æãããããªåŠçãæ¿å ¥ããŠãã ãããã©ãã®åŠçãã©ã®ããã«å€æŽããã瀺ããŠãã ããã
chat GPTïŒ
ãã®ã·ããªãªã§ã¯ãã¹ãã¬ããã·ãŒããçšããŠå€éšããSlackã«éä¿¡ããã¡ãã»ãŒãžã®æèšã管çããŸãã以äžã«èŠä»¶ã«åºã¥ããŠã¹ããããå®çŸ©ããŸããæèšãå®çŸ©ããã·ãŒãåã"MESSAGE_DEFINITIONS"ãšããŸãã
"MESSAGE_DEFINITIONS"ã·ãŒãã®Aåã«ã¯æèšã®èŠåºãããBåã«ã¯çŸç¶ã®æèšãèšå®ããŸããå ·äœçãªããŒãã«ã¯ä»¥äžã®ããã«ãªããŸãïŒ
A (èŠåºã) | B (çŸç¶ã®æèš) |
---|---|
Reminder Message | <@{username}> äŒæ©çµäºã®æéã§ãã |
Error Message | ãšã©ãŒãçºçããŸãã: {error} |
Bot Username | reminder-bot |
Bot Icon | :alarm_clock: |
äžèšã®æèšãã¹ã¯ãªããå ã§åçã«èªã¿èŸŒãã§äœ¿çšããããã«ããŸããããã«ã¯ã以äžã®ãããªæé ãå¿ èŠã§ãïŒ
ã¹ãã¬ããã·ãŒãããã®æèšã®èªã¿èŸŒã¿ã«å¯Ÿå¿ããæ°ããªé¢æ°ãäœæããŸããäŸãã°ãgetDefinedMessage(key)ãšããé¢æ°ãäœããŸãããã®é¢æ°ã¯ãåŒæ°ãšããŠèŠåºãïŒäžèšã®ããŒãã«ã®AåïŒãåãã察å¿ããæèšïŒäžèšã®ããŒãã«ã®BåïŒãè¿ããŸãã
postMessageé¢æ°å ã§Slackã«éä¿¡ããã¡ãã»ãŒãžã®æèšãgetDefinedMessageé¢æ°ãçšããŠèªã¿èŸŒãããã«å€æŽããŸãããŸãããŠãŒã¶ãŒåãšãšã©ãŒã¡ãã»ãŒãžã®éšåã¯getDefinedMessageé¢æ°ããååŸããæèšã«å¯ŸããŠæåå眮æãè¡ãããšã§åã蟌ã¿ãŸãã
以äžã«ã¯ããããã®æé ãåæ ããgetDefinedMessageé¢æ°ãšä¿®æ£åŸã®postMessageé¢æ°ã®äŸã瀺ããŸãïŒ
ïŒæç²ïŒ
// æèšå®çŸ©ã·ãŒãã®ã¢ã¯ã»ã¹
var messageSheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName("MESSAGE_DEFINITIONS");
// æèšå®çŸ©ã·ãŒãããæèšãååŸããé¢æ°
function getDefinedMessage(key) {
var data = messageSheet.getDataRange().getValues();
for (var i = 0; i < data.length; i++) {
if (data[i][0] === key) {
return data[i][1];
}
}
return null; // èŠåºãã«å¯Ÿå¿ããæèšãèŠã€ãããªãå Žåã¯nullãè¿ã
}
// Slackã«ã¡ãã»ãŒãžãæçš¿ãã
function postMessage(userName) {
writeLog("postMessage started");
try {
var messageTemplate = getDefinedMessage("Reminder Message");
var messageText = messageTemplate.replace("{username}", userName);
ãã®åŸã现ã ãšå€æŽãå ããŸããããããªã现ããç¹ã§ãã®ã§å²æããããŸãã
åŠã³
ããªãåé·ãªããã°ãšã³ããªã«ãªã£ãŠããŠæçž®ã§ãã
å
šäœãéããŠè²ã
ãšåŠã³ããããŸããã
åºæ¬çãªç¥èãå¿ èŠãªå Žé¢ãå€ã
ä»åã®ãããžã§ã¯ãã§ã¯ãªãã€ã³ããŒæ©èœã®å®è£ ã«éãsleep()ã®äœ¿çšãè©Šã¿ãããããŒã¿åœ¢åŒãJSONã§ãªããšäžåºŠèªå·±è§£æ±ºãããã®ã®ããã®ç¥èããªããå¿ããäºåºŠç®ã«åé¡ãåºãéã«ã¯ä¿®æ£ãªã¯ãšã¹ããJSONãããŒã¹ããããšãããã®ã§ããããŸããåè¡ãäžããforã«ãŒãã§åããªããçŽæ¥è¡ãåé€ãããããªã±ãŒã¹ããããŸããã
ãããã®åé¡ã¯ãåé¡ãçºçããéããšã©ãŒãçºçããéã«é©åãªä¿®æ£ãäŸé Œããã°ãåŸã ã«è§£æ±ºããŠããããšãå¯èœã§ãããããããããã®åé¡ã解決ããããã®åºæ¬çãªããã°ã©ãã³ã°ã®ç¥èãããããšã¯ãéçºã®å¹çæ§ãé«ããäžã§åŒ·ãæŠåšã«ãªããšæããŸããã
éã«é©ãã»ã©ã¹ããŒãã«åçã»ä¿®æ£ã»èšè¿°ããŠããããã±ãŒã¹ããã
ããã¯äœåºŠã§ãããããã®ã§ããã以äžã®ã³ãã¥ãã±ãŒã·ã§ã³ã¯æ¬åœã«ãŸãã§åªãã人éã®ãšã³ãžãã¢ãšäŒè©±ããŠãããã®ããã«ãæ±²ã¿åããã»ã·ãŒã ã¬ã¹ã«è§£æ±ºãŸã§å°ããŠãããããæèŠãåŸãããŸããã
ç§ïŒã©ãæå³ïŒ
Error occurred: Unexpected token 'o', "token=Y6pvP"... is not valid JSON
chatGPTïŒãã®ãšã©ãŒã¡ãã»ãŒãžã¯ãJSONã®è§£æã«å€±æããããšã瀺ããŠããŸããå ·äœçã«ã¯ãJSON.parse()ã¡ãœãããåŒã³åºãããéã«ãç¡å¹ãªJSONããŒã¿ãæž¡ãããããŒã¹åŠçäžã«äºæããªãããŒã¯ã³ 'o' ãæ€åºããããšããå 容ã§ãã
"token=Y6pvP"... is not valid JSON ãšããéšåãç¹ã«éèŠã§ãããã¯æž¡ãããããŒã¿ãJSON圢åŒã§ã¯ãªããããããã¯ãšãªãã©ã¡ãŒã¿åœ¢åŒïŒkey=valueïŒã§ããããšã瀺ããŠããŸãã
Google Apps Scriptã§Slackã®Outgoing Webhooksã䜿çšããŠããå Žåãéä¿¡ãããããŒã¿ã¯ã¯ãšãªãã©ã¡ãŒã¿åœ¢åŒã§ããããšãäžè¬çã§ããã§ãã®ã§ãJSON.parse()ã䜿çšãã代ããã«ãããŒã¿ãé©åã«åŠçããå¿ èŠããããŸãã
以äžã¯ãä¿®æ£ãããµã³ãã«ã³ãŒãã®äžéšã§ããe.parameter ã䜿çšããŠã¯ãšãªãã©ã¡ãŒã¿ãåãåããŸãã
ãŸããincoming webhookã®èšå®ã§ãã£ã³ãã«å ã«è¡šç€ºãããbotã®è¡šç€ºåãã¢ã€ã³ã³ãèšå®ã§ããã®ã§ãããä»åç¹ã«ãããããŠããªãã«ãé¢ãããé©åãªè¡šç€ºåãšã¢ã€ã³ã³ã«ãªã£ãŠããŠéåžžã«é©ããŸãããããããchatGPTãslackãžã®ã¡ãã»ãŒãžéä¿¡ã®ãšããã§
"username": "reminder-bot",
"icon_emoji": ":alarm_clock:"
ãšããã£ãšèšå®ããŠãããŠããŸãããããã
ãéå»ã®ãããšããããšã«æŽåæ§ããã£ãŠåçããŠããããããšãæåŸ ããªã
é·ãã¹ã¯ãªãããæžãéã«ã¯ã现ããé¢æ°ã«åå²ããŠäœæããããšãå¿ èŠãšãªããŸãããããããã®éã«ã¯ããã€ãã®èª²é¡ãæµ®äžããŸããäŸãã°ãäžåºŠå¿ èŠãªé¢æ°ããªã¹ãã¢ããããŠããããããã®é¢æ°ãèšè¿°ããéçšã§ãå ã ãªã¹ãã«ã¯å«ãŸããŠããªãã£ãé¢æ°ãæ°ãã«çŸããããšããããŸããããã«ãäžåºŠå®çŸ©ããé¢æ°ããŸãã§æªå®çŸ©ã§ãããã®ããã«åå®çŸ©ãããããããã®å®è£ å 容ãåã®ãã®ãšç°ãªãããšããäºæ ãçºçããŸãããããã¯æ³šææ·±ã察åŠãè¡ãå¿ èŠãããåé¡ç¹ã§ãã
ãã¡ãããæž¡ããã³ãŒãã®ãªãã¡ã¯ã¿ãªã³ã°ãä¿®æ£ã¯åŒ·å
ã§ãã
åºæ¬çã«ã¯éœåºŠãã¡ãããã³ãŒããæž¡ããŠãæž¡ããã³ãŒãã«ã€ããŠã©ãä¿®æ£ããŠã»ããããæ瀺ããŠããããæ¹ããã£ãšãå¹çããããšæããŸããã
ãŸãšã
è²ã ãšçªã£èŸŒã¿ã©ããã¯ãã£ããã®ã®ãæçµçã«ã¯chatGPTã®åãåããŠãããã€ããããŒã«ãçŸåšãåé¡ãªã皌åããŠããŸãããã®ããšãããããŒã«ã®æ§ç¯ãåççã«è¡ãããã°ãäºæãã¬ãã°ã®çºçãå°ãªããªãã®ã§ã¯ãªãããšæããŠããŸãã
ããã1æ¥åŒ±ã§å®æãããããšãã§ããããšã¯ãåçŽã«é©ãã¹ãããšã§ããã確ãã«ãåªç§ãªãšã³ãžãã¢ãªãåãæéã§å®æãããããšã¯å¯èœã ãšæããŸããããããäºæããªãåäœã®ä¿®æ£ãå¿ èŠã«ãªã£ãããåççã§ãªãæ§é ãæ®ã£ãŠããŸã£ããããããšã¯ãçŸå®ã®éçºã§ã¯ããããããšã§ãããããã£ãç¹ã§ãchatGPTã®å¯èœæ§ãæããŸããã
ãã®ãšã³ããªã誰ãã®ããŒã«äœæã«äžåœ¹è²·ããã°ã倧å€å¬ããã§ãã
Discussion