Skip to content

Instantly share code, notes, and snippets.

@y16ra
Created June 14, 2016 08:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save y16ra/e22bf71cd05b62d818a7a05ddd68b2ec to your computer and use it in GitHub Desktop.
Save y16ra/e22bf71cd05b62d818a7a05ddd68b2ec to your computer and use it in GitHub Desktop.
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
Copy link
Author

y16ra commented Jun 14, 2016

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

@y16ra
Copy link
Author

y16ra commented Nov 29, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment