LINE Notifyでメッセージ投稿
Post message through LINE Notify
LINE Notifyを通してLINEグループにメッセージを投稿します。送信先はトークンを取得するユーザー本人、またはその人の参加しているグループの中からトークン取得時に選択します。
Configs for this Auto Step
- conf_OAuth2
- C1: OAuth2 設定 *
- conf_Message
- C2. テキスト(1000文字まで) *#{EL}
- conf_log
- X: 通信ログを保存するデータ項目 (更新)
Script (click to open)
// Post message to LINE via LINE Notify (ver. 202304)
// OAuth2 config sample at [OAuth 2.0 Setting]
// - Authorization Endpoint URL: https://notify-bot.line.me/oauth/authorize
// - Token Endpoint URL: https://notify-bot.line.me/oauth/token
// - Scope: notify
// - Consumer Key: (Get by LINE Notify)
// - Consumer Secret: (Get by LINE Notify)
main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const oauth2 = configs.get( "conf_OAuth2" ) + "";
const message = configs.get( "conf_Message" ) + "";
const dataId_log = configs.get( "conf_log" );
//// == 演算 / Calculating ==
let accessLog = "";
//check length of message
messageCheck(message);
//send message to LINE Notify API
let response = httpClient.begin()
.authSetting( oauth2 )
.multipart("message", message)
.post('https://notify-api.line.me/api/notify');
accessLog += "---POST request--- " + response.getStatusCode() + "\n";
accessLog += response.getResponseAsString() + "\n";
engine.log("res:" + response.getResponseAsString());
const status = response.getStatusCode();
if( status >= 300 ){
engine.log(accessLog);
throw `Failed in POST request. status: ${status}`;
}
//// == ワークフローデータへの代入 / Data Updating ==
if ( dataId_log !== "" ) {
engine.setDataByNumber( dataId_log, accessLog );
}
}
function messageCheck(message) {
if (message == null) {
throw "Message is empty."
} else if (message.length > 1000) {
throw("Message Length over 1000");
}
}
Download
- Line-pushNotify-202304.xml
- 2023-04-05 (C) Questetra, Inc. (MIT License)
(アドオン自動工程のインストールは Professional editionでのみ可能です)
Notes
- LINE 側のアプリケーション登録の方法
- LINE のアカウントで LINE Notify (https://notify-bot.line.me/ja/) にログイン
- 「登録サービス管理」を開く
- 「サービスを登録する」から「サービス名」等を入力
※「CallbackURL」以外は任意の内容でよい
※「CallbackURL」:https://s.questetra.net/oauth2callback を指定
- Questetra 側の HTTP 認証設定の方法
※参考ページ:HTTP 認証設定について理解する(https://support.questetra.com/ja/developer-blog/http-auth-setting/)- 「OAuth2」を選択
- 「名前」:LINE Notify(ワークフローアプリ側のアドオンXMLの「OAuth2設定」と一致していれば任意の名称でよい)
- 「認可エンドポイントURL」:https://notify-bot.line.me/oauth/authorize
- 「トークンエンドポイントURL」:https://notify-bot.line.me/oauth/token
- 「スコープ」:notify
- 「クライアントID」:(LINE側の設定により取得したものを指定)
- 「クライアントシークレット」:(LINE側の設定により取得したものを指定)
Capture
