Skip to content

Commit 9a61fa5

Browse files
committed
use bot token to get or list files
in v2, user tokens will not have the `files:read` scope
1 parent 7dc8ef0 commit 9a61fa5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

components/slack_v2_test/slack_v2_test.app.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export default {
483483
return this.$auth.oauth_uid;
484484
},
485485
getToken(opts = {}) {
486-
return opts.as_user === false
486+
return (opts.as_bot && this.$auth.bot_token)
487487
? this.$auth.bot_token
488488
: this.$auth.oauth_access_token;
489489
},
@@ -497,19 +497,21 @@ export default {
497497
});
498498
},
499499
async makeRequest({
500-
method = "", throwRateLimitError = false, as_user, ...args
500+
method = "", throwRateLimitError = false, as_bot, ...args
501501
} = {}) {
502+
as_bot = args.as_user === false || as_bot;
503+
502504
const props = method.split(".");
503505
const sdk = props.reduce((reduction, prop) =>
504506
reduction[prop], this.sdk({
505-
as_user,
507+
as_bot,
506508
}));
507509

508510
let response;
509511
try {
510512
response = await this._withRetries(() => sdk(args), throwRateLimitError);
511513
} catch (error) {
512-
if (error?.data?.error === "channel_not_found" && as_user === false) {
514+
if (error?.data?.error === "channel_not_found" && as_bot) {
513515
throw new ConfigurationError(`${error}
514516
Ensure the bot is a member of the channel, or set the **As User** option to true to act on behalf of the authenticated user.
515517
`);
@@ -859,6 +861,7 @@ export default {
859861
args.count ||= constants.LIMIT;
860862
return this.makeRequest({
861863
method: "files.list",
864+
as_bot: true,
862865
...args,
863866
});
864867
},
@@ -872,6 +875,7 @@ export default {
872875
getFileInfo(args = {}) {
873876
return this.makeRequest({
874877
method: "files.info",
878+
as_bot: true,
875879
...args,
876880
});
877881
},

0 commit comments

Comments
 (0)