Slack: Chat Post Ephemeral

Slack: Chat Post Ephemeral
Sends an ephemeral message, which is visible only to the assigned user in a specific public channel, private channel, or private conversation. The user should be in the channel specified. SLACK USER is ID of the user who will receive the message.
https://support.questetra.com/addons/slack-chat-post-ephemeral/
2018-12-06 (C) Questetra, Inc. (MIT License)
Configs
  • A: Set SLACK CHANNEL to Post (e.g. “#general”) * #{EL}
  • a: Set SLACK USER to Receive (e.g. “U0BPQUNTA”) * #{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.postEphemeral


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const channel = configs.get( "conf_Channel" ) + "";
const slackUser = configs.get( "conf_SlackUser" ) + "";
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( "user", slackUser );
apiRequest     = apiRequest.formParam( "text", myText );

// access API (with post(), get(), put(), etc.)
const response = apiRequest.post( "https://slack.com/api/chat.postEphemeral" );
// - 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-Ephemeral.xml

Capture

See also

1 thought on “Slack: Chat Post Ephemeral”

  1. Pingback: Slack: Chat Post Ephemeral

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