
このアイテムは廃止予定です
新しいアイテムを使用してください。
(廃止予定) Slack: ファイルアップロード (Bots)
(Deprecated) Slack: Upload File (Bots)
この工程は、Bots 機能を使って Slack にファイルをアップロードします。
Basic Configs
- 工程名
- メモ
Configs for this Auto Step
- conf_OAuth2
- C1: OAuth2 設定 *
- ChannelName
- C2: Slack チャンネル名 *
- File
- C3:アップロードするファイルが保存されているデータ項目 (ファイル) *
Notes
- アップロード先のチャンネルを複数指定する場合、チャンネル名はカンマ区切りで指定します。
Capture

See also
Script (click to open)
- 次のスクリプトが記述されている XML ファイルをダウンロードできます
- slack-file-upload-bots.xml (C) Questetra, Inc. (MIT License)
- Professional のワークフロー基盤では、ファイル内容を改変しオリジナルのアドオン自動工程として活用できます
function main() {
const oauth2 = configs.getObject("conf_OAuth2");
const channel = configs.get("ChannelName");
const filesDef = configs.getObject("File");
//check whether files exist or not
const files = engine.findData( filesDef );
if (files === null){
engine.log ("No File to upload");
return;
}
//check whether number of files is under the limit
const numOfFiles = files.length;
if (numOfFiles > httpClient.getRequestingLimit()){
throw "Number of Files is over the limit.";
}
for (let i = 0; i < numOfFiles; i++){
upload(oauth2,files[i],channel);
}
}
/**
* Upload File
* @param {AuthSettingWrapper} oauth2 OAuth2 認証設定
* @param {String} token
* @param {QfileView} file
* @param {String} channel
*/
function upload (oauth2,file,channel){
const url = 'https://slack.com/api/files.upload';
const response = httpClient.begin()
.authSetting(oauth2)
.multipart('file',file)
.multipart('channels',channel)
.post(url);
const status = response.getStatusCode();
const responseTxt = response.getResponseAsString();
let responseJson;
try {
responseJson = JSON.parse(responseTxt);
} catch(e) {
engine.log("failed to parse as json");
engine.log(`status: ${status}`);
engine.log(responseTxt);
throw `Failed to upload. status: ${status}`;
}
if (responseJson.ok !== true) {
const filename = file.getName();
const error = `Failed to upload\n filename: ${filename} error: ${responseJson.error}`;
engine.log(`status: ${status}`);
engine.log(responseTxt);
throw error;
}
}