Slack: Chat Post

Slack: Chat Post
Sends a message to a channel. SLACK CHANNEL can be an encoded ID, or a name for channel, private group, or IM channel to send message to.
https://support.questetra.com/addons/slack-chat-post/
2018-12-02 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set SLACK CHANNEL to Post (e.g. “#general”) * #{EL}
  • B: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • C: Select TEXT DATA for Post Message *
Script
// (c) 2018, Questetra, Inc. (the MIT License)

//// == OAuth2 Setting example ==
// Authorization Endpoint URL: "https://slack.com/oauth/authorize"
// Token Endpoint URL: "https://slack.com/api/oauth.access"
// Scope: "chat:write:bot" (or "bot" etc)
// Client ID: ( from https://api.slack.com/apps )
// Consumer Secret: ( from https://api.slack.com/apps )
// -more- https://api.slack.com/methods/chat.postMessage


//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const channel = configs.get( "conf_Channel" ) + "";
const oauth2  = configs.get( "conf_OAuth2" ) + "";
const dataIdC = configs.get( "conf_DataIdC" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'
if( channel === "" ){
  throw new Error( " SLACK CHANNEL not specified" );
}

//// == Data Retrieving / ワークフローデータの参照 ==
const myText  = engine.findDataByNumber( dataIdC ) + "";


//// == Calculating / 演算 ==
// obtain OAuth2 Access Token
const token   = httpClient.getOAuth2Token( oauth2 );

// prepare API Request
let apiRequest = httpClient.begin(); // HttpRequestWrapper
// - com.questetra.bpms.core.event.scripttask.HttpClientWrapper
apiRequest     = apiRequest.formParam( "token", token );
// not "apiRequest.bearer( token )"
apiRequest     = apiRequest.formParam( "channel", channel );
apiRequest     = apiRequest.formParam( "text", myText );

// access API (with post(), get(), put(), etc.)
const response = apiRequest.post( "https://slack.com/api/chat.postMessage" );
// - HttpResponseWrapper
const httpStatus  = response.getStatusCode() + "";
engine.log( "STATUS: " + httpStatus );
const responseStr = response.getResponseAsString() + "";
engine.log( "RESPONSE: \n" + responseStr );


//// == Data Updating / ワークフローデータへの代入 ==
// (nothing)

} //////// END "main()" ////////

Download

Slack-Chat-Post.xml

Capture

See also

Episode 499: Why am I Unsure about General Situation of Submitted Quotations?

5 thoughts on “Slack: Chat Post”

  1. Pingback: Slack Post (Fixed phrase) – Questetra Support

  2. Pingback: Slack Post (String type Data Item) – Questetra Support

  3. Pingback: Slack: Files Upload – Questetra Support

  4. Pingback: Slack: Chat Post Ephemeral – Questetra Support

  5. Pingback: Open Chat, Post – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top

Discover more from Questetra Support

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

Continue reading