botkitでのファイルのアップロードには
bot.api.files.upload を用いる。
fs.readFile('hoge.png', function(err,data){
if(err) throw err;
bot.api.files.upload({
content: data,
filename: 'hoge.png',
channels: message.channel
},function(err,res) {
if (err) console.log(err)
})
});
ただし上記の方法で画像ファイルをアップロードしても
plain text としてアップロードされてしまう。
画像ファイルでは以下のように content ではなく file にstream を
渡してあげる必要がある。
bot.api.files.upload({
file: fs.createReadStream('hoge.png'),
filename: 'hoge.png',
channels: message.channel
},function(err,res) {
if (err) console.log(err)
})
下記コミットにて修正された模様。
https://github.com/howdyai/botkit/commit/2bde51ff5326ccc44b8764ecc3110dac6696ef6c
contentにデータを設定すると通常のformとしてapiを叩くが、
fileにデータを設定するとMultipart form としてapiを叩くようにしているよう。