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 + WebhookでMeetの録画ファイルの移動 & Slackへ通知の自動化

Last updated at Posted at 2021-11-19

##前書き
会社のデイリーミーティングにGoogle Meetを使っているのだが、困ったことに録画したファイルの保存先を別のフォルダに設定することは現状できないらしい。他の人に共有する際に別の録画も見られてしまうのは嫌だったので何とかならないかなと思いGoogle Apps Script(GAS)で自動的にファイル名変更 & フォルダ移動 & Slackへの通知ができたので共有。

##ファイルが移動完了した旨の通知が来るようにSlackにアプリを追加

  1. https://my.slack.com/services/new/incoming-webhook/ へアクセス
  2. 投稿チャンネルは適当に選択(GASで指定すればどのチャンネルでも通知出来る)
  3. 「IncomingWebhook Integrationの追加」クリック
  4. Webhook URLをコピーして控えておく

##録画ファイルを現在のフォルダから別フォルダへ移動するコード(GAS)

function move() {
  var mydrive = ""; //移動元フォルダURL
  var destination = ""; //移動先フォルダURL
  var tittle = ""; //会議名
  var slackch = ""; //slackのチャンネル名
  var webhookUrl = ""; //控えたWebhookURL
  var notificationFlag = true; //slackに通知したくなければここをfalseにする

  //移動元フォルダ情報と移動先フォルダ情報を取得
  var sliceText = "folders/";
  var positionToStartSlice = mydrive.search(sliceText) + sliceText.length;
  var origin_folderId = mydrive.slice(positionToStartSlice);
  var destination_folderId = destination.slice(positionToStartSlice);

  //ファイル一覧取得
  var origin_folder = DriveApp.getFolderById(origin_folderId);
  var LIST = origin_folder.getFiles();

  //ファイル名を比較して対象の場合はファイル名をJSTに直した上で移動させる
  while (LIST.hasNext()) {
    var file = LIST.next();
    if (file.getName().indexOf(tittle) === 0) {  //前方一致した場合
      //ファイル名を分割
      var splitText = (String(file)).split('(');

      //作成日を抽出
      var lastUpdated = file.getLastUpdated();
      var Dateformat = Utilities.formatDate(lastUpdated, '"GMT+9"', 'yyyy-MM-dd'); //日付フォーマット変更

      //ファイル名変更
      var fileid = file.getId()
      var getFileid = DriveApp.getFileById(fileid);
      getFileid.setName(splitText[0] + "(" + Dateformat + ")");

      //ファイルを移動
      var destination_folder = DriveApp.getFolderById(destination_folderId);
      getFileid.moveTo(destination_folder);
      Logger.log('ファイル名「' + splitText[0] + "(" + Dateformat + ")" + '」を移動しました');

      //Slack通知
      if (notificationFlag == true) {
        var options =
        {
          "method": "post",
          "contentType": "application/json",
          "payload": JSON.stringify
            (
              {
                "username": "録画データ通知BOT",
                "channel": slackch,
                "text": '録画ファイル「' + splitText[0] + "(" + Dateformat + ")" + '」を保存しました' + destination,
                "link_names": 1
              }
            )
        };
        //Slack投稿
        UrlFetchApp.fetch(webhookUrl, options);
      }
    }
  }
}

##実行する時間の設定
GASにはトリガーという機能があり、設定すると指定した時刻で上記の関数を実行してくれる。
左の一覧から「トリガー」を選択し右下の「トリガーを追加」ボタン押下
スクリーンショット 2021-11-19 14.37.16.png

以下のようなメニューが表示されるので、例えば毎日午後3時~4時に実行したい場合は以下のようにする。

  1. 「実行する関数」 → 今回書いた関数名
  2. 「イベントソースを選択」 → 「時間主導型」
  3. 「時間ベースのトリガーのタイプを選択」 → 「日付ベースのタイマー」
  4. 「時刻を選択」 → 「午後3時~4時」
    スクリーンショット 2021-11-19 14.36.54.png

##参考
[GoogleMeetの録画ファイルをマイドライブ以外に保管させる(+おまけ)][link-1]
[link-1]:https://note.com/yasuym1/n/n9d4e2e0402a1
[Google Apps Script で毎日決まった時刻にスクリプトを実行するトリガー設定][link-2]
[link-2]:https://tonari-it.com/gas-trigger-set/

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?