所以我写了一个代码来从一个松弛的机器人下载一个文件
代码是
var https = require('https');
var fs = require('fs');
var pDownload= function (url, dest){
var slug = url.split('.com').pop();
console.log(slug);
var options = {
"method": "GET",
"hostname": "files.slack.com",
"path": slug,
"rejectUnauthorized": "false",
"headers": {
"Authorization": "Bearer MYTOKEN"
}
}
var file = fs.createWriteStream(dest);
return new Promise((resolve, reject) => {
var responseSent = false; // flag to make sure that response is sent only once.
https.get(options, response => {
response.pipe(file);
file.on('finish', () =>{
file.close(() => {
if(responseSent) return;
responseSent = true;
resolve();
});
});
}).on('error', err => {
if(responseSent) return;
responseSent = true;
reject(err);
});
});
}
module.exports.pDownload=pDownload;
example
pDownload('https://files.slack.com/files-pri/T7JRF8TCN-F7WDP24LV/analysis.r', './test/res.new')
.then( ()=> console.log('downloaded file no issues...'))
.catch( e => console.error('error while downloading', e));
但是,如果用户通过直接消息与机器人交谈,则下载的文件仅包含'https://files-origin.slack.com/files-pri/T7JRF8TCN-F7WDP24LV/analysis.r found'
而不包含内容
但是,如果我们在频道上与机器人交谈并上传文件,它会正确下载文件并将所有内容存储到文件中。
为什么会出现这个问题?当我将范围设置为files:read
和时,为什么它会重定向到 files-origin.slack.comfiles:write:user
发送私信时,机器人可以下载文件吗?