Post Message through LINE Notify

Message Posting with LINE Notify

Post message through LINE Notify

Posts a message to a LINE group through LINE Notify. Please obtain a personal access token in advance. The recipient of the message will be selected at the time of acquiring the token, either the user acquiring the token themself or a group in which that person participates.

Auto Step icon
Configs for this Auto Step
conf_OAuth2
C1: OAuth2 Setting *
conf_Message
C2. Text Message(Within 1000 characters) *#{EL}
conf_log
X: Access Log (update)
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

warning This is freely-modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installation of add-on automated processes is only available in Professional edition)

Notes

Capture

See Also

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading