Created
June 14, 2016 08:51
-
-
Save y16ra/e22bf71cd05b62d818a7a05ddd68b2ec to your computer and use it in GitHub Desktop.
slack apiで画像ファイルをアップロードする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
botkitで以下の記事を参考にアップロードをしようとしたところテキストファイルじゃないとうまくいかず、画像アップロードできるものを自作した。本当はbotkitのbot.api.files.uploadを使ってできればそれが良かったのだけども。
http://qiita.com/nobukatsu/items/e6ba8d9299816e1a503e