0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【GAS】会議の時間が近づいてきたら教えてほしい

Last updated at Posted at 2022-11-21

会議をすっぽかすことが多いので、GASで通知させることにした。

目次

1. 概要
2. スクリプト

1. 概要

サンプルコードはコンソールログ表示させるようにしていますが、
chatbotにpostするようにすれば、怒涛の通知を受け取れます。

2. スクリプト

noticeYourSchedule.js
// ━━━━━━━━━━━━━━━
// 共通
// ━━━━━━━━━━━━━━━
var user = Session.getActiveUser().getUserLoginId()
var cal = CalendarApp.getCalendarById(user);

function getSchedule() {
  var currenttime = new Date();
  Utilities.formatDate(currenttime, "Asia/Tokyo", "yyyy/MM/dd HH:mm:ss");

  var endtime = new Date();
  endtime.setHours(23, 59, 59);
  Utilities.formatDate(endtime, "Asia/Tokyo", "yyyy/MM/dd HH:mm:ss");

  var events = cal.getEvents(currenttime, endtime);
  var eventsarr = [];

  for (var i of events) {
    var title = i.getTitle();
    var starttime = i.getStartTime();
    Utilities.formatDate(starttime, "Asia/Tokyo", "yyyy/MM/dd HH:mm:ss");

    var eventarr = [];    
    eventarr.push(starttime);
    eventarr.push(title);
    eventsarr.push(eventarr);
  }
  return eventsarr;
}

// ━━━━━━━━━━━━━━━
// 今日の残スケジュール
// ━━━━━━━━━━━━━━━
function noticeTodaysLeftSchedule() {
  var schedule = getSchedule();

  var currenttime = new Date();

  var schedule = schedule.filter(data => data[0] > currenttime);

  var messagearr = [];
  for (var i = 0; i < schedule.length; i++) {
    var starttime = schedule[i][0];
    var starttime = Utilities.formatDate(starttime, "Asia/Tokyo", "HH:mm");
    var title = schedule[i][1];
    messagearr.push(starttime + ' ' + title);
  }
  messagearr.join('\n');
  var message = '▼本日の残スケジュール\n━━━━━━━━━━━━━━━\n' + messagearr + '\n━━━━━━━━━━━━━━━'
  Logger.log(message);
}

// ━━━━━━━━━━━━━━━
// まもなく始まるスケジュール
// ━━━━━━━━━━━━━━━
function noticeScheduleStartingSoon() {
  var schedule = getSchedule();

  var currenttime = new Date();
  var after10min = new Date();
  after10min.setMinutes(after10min.getMinutes(after10min) + 10);

  var schedule = schedule.filter(data => data[0] > currenttime);
  var schedule = schedule.filter(data => data[0] < after10min);

  var messagearr = [];
  for (var i = 0; i < schedule.length; i++) {
    var starttime = schedule[i][0];
    var starttime = Utilities.formatDate(starttime, "Asia/Tokyo", "HH:mm");
    var title = schedule[i][1];
    messagearr.push(starttime + ' ' + title);
  }
  messagearr.join('\n');
  var message = '▼まもなく始まるスケジュール\n━━━━━━━━━━━━━━━\n' + messagearr + '\n━━━━━━━━━━━━━━━'
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log('');
  Logger.log(message);
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?