// (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()" ////////
Pingback: Slack: Chat Post Ephemeral