slackapi / node-slack-sdk

Slack Developer Kit for Node.js
https://slack.dev/node-slack-sdk
MIT License
3.27k stars 662 forks source link

web-api(fix): share tokens provided as arguments in files upload to upload jobs #1745

Closed zimeg closed 7 months ago

zimeg commented 7 months ago

Summary

This PR passes any token provided to the options of files.uploadV2 with upload jobs for multiple files to prevent an unexpected not_authed error.

This is the error that's thrown when using the example code below! ```sh /Users/me/programming/tools/node-slack-sdk/packages/web-api/dist/errors.js:62 const error = errorWithCode(new Error(`An API error occurred: ${result.error}`), ErrorCode.PlatformError); ^ Error: An API error occurred: not_authed at platformErrorFromResult (/Users/me/programming/tools/node-slack-sdk/packages/web-api/dist/errors.js:62:33) at WebClient. (/Users/me/programming/tools/node-slack-sdk/packages/web-api/dist/WebClient.js:198:60) at Generator.next () at fulfilled (/Users/me/programming/tools/node-slack-sdk/packages/web-api/dist/WebClient.js:28:58) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 'slack_webapi_platform_error', data: { ok: false, error: 'not_authed', response_metadata: { acceptedScopes: [ 'files:write:user' ] } } } ```

Reviewers

Experiment and experience all this has to offer with the following snippet:

(async () => {
    const result = await web.files.uploadV2({
        channel_id: "C0123456789",
        token: "xoxb-0123456789-ABCDEF-GHIJKLMNOP-QRSTUVWXYZ",
        file_uploads: [{
            content: "hello world",
            filename: "GREETINGS.txt",
        }]
    });
    console.log(result);
})();

Requirements

zimeg commented 7 months ago

@seratch thank you for the reviews!