Gmailに来たZoomの招待リンクをGoogle Calendarに登録
概要
目的
Zoomミーティングに参加するときにわざわざGmailを開いてリンクをクリックするのが面倒なので、 Zoomのアプリを開いて、ミーティングタブに表示されるミーティング予定の「参加」ボタンクリック一発で参加したい。
必要な準備
ZoomとGoogleカレンダーの連携
- zoom.usにログインして、プロフィールの編集から「カレンダーと連絡先の統合」でGoogleカレンダーと連携しておく
- 招待メールを受け取ったら、招待メールの中に記されているZoomリンクを場所欄にコピペした予定をカレンダーに登録
- これでZoomアプリのミーティングタブに、Googleカレンダーに登録されている予定が表示され「参加」ボタンからワンクリックでZoomに参加できるようになる。
- 「場所」欄にZoomの招待リンクを入れて予定を登録するのがポイント。
スクリプト
さらにものぐさな私は、招待メールが来たら、リンクを自動ででGoogleカレンダーに登録できないか考えた。
それでGoogle Apps Scriptを使い、Gmailを定期的にチェックし、Zoomリンクが含まれたメールが来ていたらその件名と日付、URLで予定作成しGoogleカレンダーに登録するスクリプトを作成した。
1//新着メールチェック
2function mailCheck(){
3 const SEARCH_TERM = 'is:unread zoom.us/j/';
4 const threads = GmailApp.search(SEARCH_TERM, 0, 30);
5 const messages = GmailApp.getMessagesForThreads(threads);
6 const regexpUrl = RegExp('https:\/\/[^.]+\.zoom\.us\/j\/.*', 'gi');
7 const label = GmailApp.getUserLabelByName("Zoom");
8
9 for(var i=0; i < messages.length;i++){
10 thread = messages[i];
11 for(var j=0; j < thread.length; j++){
12 message = thread[j];
13 if(message.isUnread() && !message.isStarred()){
14 const plainBody = message.getPlainBody();
15 let title = message.getSubject();
16 const resultTitle = plainBody.match(/トピック:\s(.*)/i);
17 if (resultTitle != null) {
18 title = resultTitle[1];
19 }
20 title = title.replace(/[0-9]{1,2}\/[0-9]{1,2}\(.\)[0-9]{1,2}:[0-9]{1,2}~/,"");
21 console.log(title);
22
23 const resultUrl = plainBody.match(regexpUrl);
24 if (resultUrl == null) {
25 continue;
26 }
27 const zoomUrl = resultUrl[0];
28 console.log("URL:"+ zoomUrl);
29
30 const resultTime = plainBody.match(/([0-9]{4})年([0-9]{1,2})月([0-9]{1,2})日\s([0-9]{1,2}):([0-9]{1,2})\s*(PM|AM)?/i);
31 if (resultTime == null) {
32 continue;
33 }else{
34 const year = parseInt(resultTime[1]);
35 const month = parseInt(resultTime[2]);
36 const dayOfMonth = parseInt(resultTime[3]);
37 const startTimeHour = resultTime[6] == "PM" ? parseInt(resultTime[4]) + 12 : parseInt(resultTime[4]);
38 const startTimeMin = parseInt(resultTime[5]);
39 const startTime = new Date(year, month - 1, dayOfMonth, startTimeHour, startTimeMin, 0);
40 const endTime = new Date(year, month - 1, dayOfMonth, startTimeHour + 1, startTimeMin, 0);
41 createEvent(title, zoomUrl, startTime, endTime);
42 message.star();
43 message.getThread().addLabel(label);
44 console.log("start: "+startTime.toString());
45 }
46 }
47 }
48
49 }
50}
51
52function createEvent(title, location, startTime, endTime) {
53 const calendar = CalendarApp.getDefaultCalendar();
54 const option = {
55 location: location,
56 }
57 calendar.createEvent(title, startTime, endTime, option);
58}
使用方法
- Googleドライブで新しいGoogle Apps Scriptを作成し、上のコードをコピペ
- プロジェクトに名前を付けて保存
- スクリプトのタイムゾーンを変更
- 「プロジェクトの設定」で「「appsscript.json」マニフェスト ファイルをエディタで表示する」にチェックを入れる
- エディタで「appsscript.json」を開き「timeZone」の"America/New_York"を"Asia/Tokyo"に変更
- 実行する。承認が必要というダイアログが出るので権限を確認→詳細→○○に移動→許可
- もう一度実行
- トリガーを追加して定期的に実行するように設定する
- GmailでZoomという名前のラベルを作成しておく(処理済みはこのラベルが付く)
感想
Gmailを開いてリンクをクリックするのも、参加ボタンをクリックするのも同じのような気もするけど、こんな利点があると思った。
- 埋もれた招待メールを探さなくてもいい
- Zoomミーティングに参加する前にカメラや音声チェックをする習慣があるので、かならずZoomアプリは先に開いているのでスムーズに入室できる。
それではよいZoomライフを。