1
3

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.

GoogleカレンダーからGASを経由してChatWorkに時間指定で投稿する

Posted at

参考
https://qiita.com/y_minowa/items/39db8ca5bffc9c440caf

--ポイント--
・予定開始時刻になるとChatwaorkに投稿する
・GASスクリプトを一分毎に起動するようにする
・GASにチャットワークのライブラリを読み込む
・投稿内容は本文のみ
・グーグルカレンダーは本人のものを使用する

gaschat.gs
// グーグルカレンダーの題名にこのキーワードがあると投稿する
var GASCHATKEY = 'GASCHAT';
// チャットワークのトークン
var CHATWORK_TOKEN = '';
// チャットワークのルームナンバー
var ROOM_ID = '';

function myFunction() {
  main();
}

function main() {
  var calendars = CalendarApp.getAllCalendars();
  var text = Utilities.formatDate(new Date(), 'JST', 'yyyy/MM/dd') + "\n";

  for(i in calendars) {
    var calendar = calendars[i];
    var events = calendar.getEventsForDay(new Date());
    var date = new Date();
    // 時刻を取得
    var ctime = Utilities.formatDate( date, 'Asia/Tokyo', 'HH:mm');
    for(j in events) {
      var event = events[j];
      var title = event.getTitle();
      var body  = event.getDescription();
      var start = toTime(event.getStartTime());
      var end = toTime(event.getEndTime());
      if (title.indexOf(GASCHATKEY)== -1)
      {
        continue;
      }
      if (start !== ctime)
      {
        continue;
      }
      text = body + '\n';
      SendToChatWork(text);
    }
  }
}

function toTime(str){
  return Utilities.formatDate(str, 'JST', 'HH:mm');
}

function SendToChatWork (mes)
{
    var client = ChatWorkClient.factory({token: CHATWORK_TOKEN});
  client.sendMessage({room_id: ROOM_ID, body: mes});
}
1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?