Я использую Slack Bot, который генерирует изображения и отправляет их на канал, node-slack-sdk
s files.upload
возвращает ошибку. Где мне нужно исправить?
Я попытался MyImage
класс, который имеет член буфера изображения и метод для его генерации. Сначала контроллер генерирует изображение, а затем отправляет его в Slack API. В Slack Web Client есть метод files.upload
, и он принимает аргумент file
как Buffer
, отправляет в API в формате multipart/form-data
.
Контроллер находится здесь:
export const receiveCommand = async (
req: Request,
res: Response
): Promise<Response> => {
const myImage = new MyImage(req);
// ...
try {
await myImage.generateImage();
await client.files.upload(myImage.fileUploadOption); // <- (*)
return res.status(200).send("");
} catch (e) {
console.log(e);
return res.status(200).send("");
}
};
inMyImage
class, генерирует изображение с кукловодом
public async generateImage(): Promise<void> {
const html = ` ... `;
const browser = await Puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html);
// get image as Buffer
this._image = await page.screenshot({ encoding: "binary" });
}
и fileUploadOption
getter возвращает Slack API's FilesUploadArguments
.
public get fileUploadOption(): FilesUploadArguments {
return {
channel: this._channelId,
text: this._message,
as_user: true,
file: this._image,
filename: "card.png",
};
}
Когда вызывается client.files.upload
(строка, отмеченная как*
), эта ошибка возникает.
[WARN] WebClient:0 http request failed The first argument must be one of type string or Buffer. Received type boolean
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type boolean
at write_ (_http_outgoing.js:595:11)
at ClientRequest.write (_http_outgoing.js:567:10)
at FormData.ondata (internal/streams/legacy.js:15:31)
at FormData.emit (events.js:198:13)
at FormData.EventEmitter.emit (domain.js:448:20)
at FormData.CombinedStream.write (/path/to/my_project/node_modules/combined-stream/lib/combined_stream.js:138:8)
at FormData.CombinedStream._pipeNext (/path/to/my_project/node_modules/combined-stream/lib/combined_stream.js:126:8)
at FormData.CombinedStream._realGetNext (/path/to/my_project/node_modules/combined-stream/lib/combined_stream.js:99:10)
at FormData.CombinedStream._getNext (/path/to/my_project/node_modules/combined-stream/lib/combined_stream.js:82:12)
at FormData.CombinedStream.resume (/path/to/my_project/node_modules/combined-stream/lib/combined_stream.js:154:10)
Я изменил Buffer
на ReadStream
, но это не изменилось. Мне действительно интересно, что происходит ...