
Slack: Files Upload
Uploads files. If you want to share files, specify a comma separated list of channel names or IDs in SLACK CHANNELs.
https://support.questetra.com/addons/slack-files-upload/
2018-12-01 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/slack-files-upload/
2018-12-01 (C) Questetra, Inc. (MIT License)
Configs
- A: Select FILES DATA for Upload *
- B: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
- C: Set SLACK CHANNELs to Share (e.g. “#general,#random”) #{EL}
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: "files:write:user" (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/files.upload
//////// START "main()" ////////
main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + "";
const oauth2 = configs.get( "conf_OAuth2" ) + "";
const channels = configs.get( "conf_Channels" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'
//// == Data Retrieving / ワークフローデータの参照 ==
const myFiles = engine.findDataByNumber( dataIdA );
// java.util.ArrayList
if (myFiles == null) {
throw new Error( '\n Files not Attached \n' );
}
const numFiles = myFiles.size() - 0; // javascript 'number'
// myFiles[i]: com.questetra.bpms.core.event.scripttask.QfileView
//// == Calculating / 演算 ==
/// obtain OAuth2 Access Token
const token = httpClient.getOAuth2Token( oauth2 );
for(let i = 0; i < numFiles; i++){
/// prepare API Request
let apiRequest = httpClient.begin(); // HttpRequestWrapper
// - com.questetra.bpms.core.event.scripttask.HttpClientWrapper
apiRequest = apiRequest.multipart( "token", token );
// not "apiRequest.bearer( token )"
if(channels !== ""){
apiRequest = apiRequest.multipart( "channels", channels );
}
apiRequest = apiRequest.multipart( "file", myFiles[i] );
/// access API (with post(), get(), put(), etc.)
const response = apiRequest.post( "https://slack.com/api/files.upload" );
// - HttpResponseWrapper
const httpStatus = response.getStatusCode() + "";
engine.log( "STATUS: " + httpStatus );
const responseStr = response.getResponseAsString() + "";
engine.log( "RESPONSE: \n" + responseStr );
}
//// == Data Updating / ワークフローデータへの代入 ==
// (nothing)
} //////// END "main()" ////////
Download
Capture
See also
Slack: Chat Post