@@ -490,9 +490,14 @@ export default {
490490 } ,
491491 getToken ( opts = { } ) {
492492 // Use bot token if asBot is true and available, otherwise use user token.
493- return ( opts . asBot && this . $auth . bot_token )
494- ? this . $auth . bot_token
495- : this . $auth . oauth_access_token ;
493+ const botToken = this . getBotToken ( ) ;
494+ const userToken = this . $auth . oauth_access_token ;
495+ return ( opts . asBot && botToken )
496+ ? botToken
497+ : userToken ;
498+ } ,
499+ getBotToken ( ) {
500+ return this . $auth . bot_token ;
496501 } ,
497502 async getChannelDisplayName ( channel ) {
498503 if ( channel . user ) {
@@ -533,12 +538,11 @@ export default {
533538 async makeRequest ( {
534539 method = "" , throwRateLimitError = false , asBot, as_user, ...args
535540 } = { } ) {
536- const botTokenAvailable = Boolean ( this . $auth . bot_token ) ;
537541 // Passing as_user as false with a v2 user token lacking the deprecated
538542 // `chat:write:bot` scope results in an error. If as_user is false and a
539543 // bot token is available, use the bot token and omit as_user. Otherwise,
540544 // pass as_user through.
541- if ( as_user === false && botTokenAvailable ) {
545+ if ( as_user === false && Boolean ( this . getBotToken ( ) ) ) {
542546 asBot = true ;
543547 } else {
544548 args . as_user = as_user ;
@@ -673,15 +677,18 @@ export default {
673677 return realNames ;
674678 } ,
675679 async maybeAddAppToChannels ( channelIds = [ ] ) {
676- if ( ! this . $auth . bot_token ) return ;
680+ if ( ! this . getBotToken ( ) ) {
681+ console . log ( "Skipping adding app to channels: bot unavailable." ) ;
682+ return ;
683+ }
677684 try {
678685 const {
679686 bot_id, user_id,
680687 } = await this . authTest ( {
681688 asBot : true ,
682689 } ) ;
683690 if ( ! bot_id ) {
684- console . log ( "Skipping adding Slack app to channels: bot ID unavailable ." ) ;
691+ console . log ( "Skipping adding app to channels: bot not found ." ) ;
685692 return ;
686693 }
687694 for ( const channel of channelIds ) {
@@ -693,11 +700,11 @@ export default {
693700 users : user_id ,
694701 } ) ;
695702 } catch ( error ) {
696- console . log ( `Unable to add Slack app to channel ${ channel } : ${ error } ` ) ;
703+ console . log ( `Unable to add app to channel ${ channel } : ${ error } ` ) ;
697704 }
698705 }
699706 } catch ( error ) {
700- console . log ( `Unable to add Slack app to channels: ${ error } ` ) ;
707+ console . log ( `Unable to add app to channels: ${ error } ` ) ;
701708 }
702709 } ,
703710 /**
0 commit comments