2
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.

LINE×GAS|決まった曜日・時間にメッセージ通知

Last updated at Posted at 2022-10-01

ゴール

僕は毎週、友達と電話をしています。
でも、その予定を毎週きめるのがめんどくさかったり、忘れたり、なんとなく聞きづらかったりするんですよね。ということで、代わりに聞いてくれるBotを作りました。

完成形

▼LINE
image.png

▼スプレッドシート
image.png

▼コード(GAS)

ask_day_of_week.gs
// ------色々と定義する------
  // スプレッドシートのシート名を取得し、`sheet`に定義
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("set");

  // スプシから取得したLINEトークンを`token`に定義
  let token = sheet.getRange(4,3).getValue();

  // メッセージの形を定義
    function setContentFormat(content) {
    var options = {
      "method": "post",
      "payload" : {"message": content },
      "headers": {"Authorization": "Bearer " + token}    
    };
    UrlFetchApp.fetch("https://notify-api.line.me/api/notify", options);
    }


// ------メッセージを送信する------
  function postContent() {
    let content = sheet.getRange(5,3).getValue();
    setContentFormat(content);
  }

▼トリガー
image.png

使い方

  1. LINE Notifyにてアクセストークンを取得
  2. 取得したアクセストークンをスプレッドシートに貼り付け
  3. 送りたいメッセージを設定
  4. トリガーを設定

ポイント

参考記事では、GAS上で送るメッセージやアクセストークンを定義していましたが、スプレッドシート上で記載できる形に変えました。汎用性やメンテナンス性を高めるためです。

今後の展望

搭載したい機能

  1. 曜日をワンクリックで回答
  2. 回答した曜日の前日にリマインド

参考記事

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