ChatWork: Add Message
Add a message to the specified chat room of ChatWork.
2020-01-10 (C) Questetra, Inc. (MIT License)
Configs
  • A: API Token *
  • B: Select TEXT DATA for Room Id *
  • C: Select TEXT DATA for Message *
  • X: Select TEXT DATA for Log
Script
//// == Config Retrieving ==
var apiToken = configs.get("conf_ApiToken") + "";


//// == Data Retrieving ==
var roomId = engine.findDataByNumber( configs.get("conf_RoomId") ) + "";
var message = engine.findDataByNumber( configs.get("conf_Message") ) + "";


//// == Calculating ==
var uri = "https://api.chatwork.com/v2/rooms/" + roomId + "/messages";

var response = httpClient.begin()
  .header( "X-ChatWorkToken", apiToken )
  .formParam( "body", message )
  .post( uri );


//// == Data Updating ==
//If log data is specified
var dataNum_Log = configs.get("conf_Log") + "";
if (dataNum_Log !== "") {
  var log = "";
  log += "---PUT request--- " + response.getStatusCode() + "\n";
  log += response.getResponseAsString() + "\n";
  engine.setDataByNumber( dataNum_Log, log );
}

Download

Capture

See also

%d bloggers like this: