Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
slack apiで画像ファイルをアップロードする
var request = require('request');
var fs = require('fs');
const SLACK_BOT_TOKEN = 'hogehoge';
const api_url = 'https://slack.com/api/';
var fileName = 'hogefuga.png';
var channel = 'general';
options = {
token: SLACK_BOT_TOKEN,
filename: fileName,
file: fs.createReadStream('./' + fileName),
channels: channel
};
request.post({url:api_url + 'files.upload', formData: options}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('ok');
} else {
console.log('status code: ' + response.statusCode);
}
});
@y16ra

This comment has been minimized.

Copy link
Owner Author

y16ra commented Jun 14, 2016

botkitで以下の記事を参考にアップロードをしようとしたところテキストファイルじゃないとうまくいかず、画像アップロードできるものを自作した。本当はbotkitのbot.api.files.uploadを使ってできればそれが良かったのだけども。
http://qiita.com/nobukatsu/items/e6ba8d9299816e1a503e

@y16ra

This comment has been minimized.

Copy link
Owner Author

y16ra commented Nov 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.