1
1

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 5 years have passed since last update.

GASでGoogleカレンダーのリマインドをラインに送る

Last updated at Posted at 2020-01-19

はじめに

Google App Scriptを使って、Googleカレンダーに登録してある、予定のリマインドをラインに送信する方法です。

システム構成図

b.png

コード

var token = "<token>";
var google_calendar_id = '<calendar_id>';

function notify() {
  var calendar = CalendarApp.getCalendarById(google_calendar_id);
  var today = new Date();
  var tomorrow = new Date(today);
  tomorrow.setDate(tomorrow.getDate() + 1);
  var events = calendar.getEventsForDay(tomorrow);
  if( events.length >= 1 ) {
    var title = events[0].getTitle();
    var message = title;
    sendToLine(message);
  }

}

function sendToLine(message){
  var options =
   {
     "method"  : "post",
     "headers" : {"Authorization" : "Bearer "+ token},
     "payload" : "message=" + message
   };

   UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
}

ポイント

  • 特定のカレンダーの明日の予定をチェックして、あればラインにメッセージを送信する

トリガーの設定

スクリーンショット 2020-01-19 22.15.10.png

こんな感じで毎日決まって時間に実行するようにしています。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?