Typetalk: Post Message
Post a message to Typetalk with a specified text.
2018 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set topic id to post (e.g. 12345) *
  • B: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • C: Select TEXT DATA for Post Message *
  • X: Select TEXT DATA for Log
Script
//// == Note ==
// Authorization Code Request URL: https://typetalk.in/oauth2/authorize
// Access Token Request URL: https://typetalk.in/oauth2/access_token
// Scope: chat:topic.post
// Client ID: ( from https://typetalk.com/my/develop/applications )
// Consumer Secret: ( from https://typetalk.com/my/develop/applications )

//// == Config Retrieving ==
var topicId = configs.get("conf_TopicId") + "";
var myOAuthConfig = configs.get("conf_OAuth2") + "";

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

//// == Calculating ==
var token = httpClient.getOAuth2Token( myOAuthConfig );
var response = httpClient.begin()
  .bearer( token )
  .formParam( "message", textForPost )
  .post( "https://typetalk.com/api/v1/topics/" + topicId );

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

Download

Capture

See also

%d bloggers like this: