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

【GAS】GoogleアラートをLINEに自動通知して知りたい情報をまとめてた。

Last updated at Posted at 2021-10-29

googleArart.png
Googleアラートをご存知でしょうか?

調べたい検索ワードを登録するとGmailに検索ワードに沿ったニュースが定期的に通知されるサービスです。こちらを使えば自分から検索をする手間が省かれます。

しかし、Gmailを開くのが面倒で、利用をやめた方は多いのではないでしょうか?

より簡単に見られるようにするため、GASを用いてLINEグループにも通知されるようにしてみたので良ければご参考下さい。

使うもの

・Googleアラート
・Gmail
・GoogleAppScript
・LINENotify

完成

Googleアラート:調べたい検索ワードを設定

70E5AB59-CA09-4AAB-9169-35BED1B38B25.jpg

Gmail:検索ワードの関連記事を受信

S__23109902-1536x956.jpg

グループLINEに通知

S__23109899.jpg

コード

function getNews() {

  var thds = GmailApp.search("label:inbox is:unread subject:Google アラート");
  var arr = [];
  for (var n in thds) {
    var thd = thds[n];
    var msgs = thd.getMessages();
    for (m in msgs) {
      var msg = msgs[m];
      var body = msg.getBody();  //メール本文
      var parse = Parser.data(body);
      var name = parse.from('"title": "Google アラート - ').to('",').iterate();
      var links = parse.from('u0026url=').to('\\u0026').iterate();
      alldata = [];
      for (i = 0; i <= links.length; i++) {
        if (links[i] == undefined) {
          continue;
        }
        arr[i] = links[i];
        alldata += "\n" + arr[i];
      }
      sendLineMessage(name[1] + "\n" + alldata);
      thds[n].markRead(); //次回実行の検索に引っかからないようにするため、既読にする
      //console.log(alldata);
    }
  }
}


var LINE_NOTIFY_TOKEN = "LINENotifyトークン";
var LINE_NOTIFY_API = "https://notify-api.line.me/api/notify";

//LINEにメッセージを送る
function sendLineMessage(message) {
  var response = UrlFetchApp.fetch(LINE_NOTIFY_API, {
    "method": "post",
    "headers": {
      "Authorization": "Bearer " + LINE_NOTIFY_TOKEN
    },
    "payload": {
      "message": message
    }
  });
}

詳細な設定方法は下記URLを参照してください。
https://uneincrea.com/?p=389

5
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
5
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?