【ソースコード配布用】Googleカレンダーの予定をLINEグループに定時送信する方法【IFTTT・LINE Notify】

const IFTTT_URL = 'https://maker.ifttt.com/trigger/calendar_line/with/key/{your-key}';
const CALENDER_GMAIL = '{GoogleカレンダーのGメールアドレス}@gmail.com';

function handler() {
  var _d = new Date();
  let fromDate = new Date(_d.getFullYear(), _d.getMonth(), _d.getDate(), 0, 0, 0);
  fromDate.setDate(fromDate.getDate() + 1);
  let toDate = new Date(_d.getFullYear(), _d.getMonth(), _d.getDate(), 23, 59, 59);
  toDate.setDate(toDate.getDate() + 1);
  
  const calendar = CalendarApp.getCalendarById(CALENDER_GMAIL);
  const events = calendar.getEvents(fromDate, toDate);
  for(const event of events){
    const options =
    {
      method : 'POST',
      payload : {
        value1: event.getTitle(),
        value2: event.getDescription(),
        value3: Utilities.formatDate(event.getStartTime(), 'JST', 'yyyy-MM-dd HH:mm') +
       ' 〜 ' + Utilities.formatDate(event.getEndTime(), 'JST', 'yyyy-MM-dd HH:mm')
      }
    };
    UrlFetchApp.fetch(IFTTT_URL, options);
  }
}

いただいたサポートは、自己投資と災害復興支援に使わせていただきます。