LoginSignup
4
9

More than 3 years have passed since last update.

【GAS】LINE botでメッセージを(定期)配信

Last updated at Posted at 2020-03-26
code.js
// LINE Message API アクセストークン
var ACCESS_TOKEN = "自分のアクセストークンをコピペ";

function broadcast() {
  UrlFetchApp.fetch('https://api.line.me/v2/bot/message/broadcast', {
    method: 'post',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + ACCESS_TOKEN,
    },
    payload: JSON.stringify({
      messages: [
        {
            type: 'text',
            text: 'メッセージ1。'
        },
      ]
    }),
  });
}

※linebotの設定の仕方はここでは省略します。

このプログラムで実行ボタン押すと、友達登録している人全員に”メッセージ1”が送信されます。
(broadcastという機能を使ってます。)

コードを更新したとき

以下のように”ウェブアプリケーションを公開”からNEWを選択してURLを発行します。

image.png

image.png

このURLはLINE developerのURLとは連携されているのでLINE developerへのログインは不要です。

メッセージを定期配信する方法

スクリプトエディタのトリガーを利用。
image.png

”現在使われているトリガー”から、新規登録でbroadcastを選び、設定。
これで分単位、時間単位、週単位など設定できます。

image.png

簡単便利!

4
9
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
4
9