Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using bolt-js without passing bot_id #874

Closed
seratch opened this issue Apr 9, 2021 · 2 comments · Fixed by #1087
Closed

Enable using bolt-js without passing bot_id #874

seratch opened this issue Apr 9, 2021 · 2 comments · Fixed by #1087
Assignees
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor
Milestone

Comments

@seratch
Copy link
Member

seratch commented Apr 9, 2021

As of v3.3, developers cannot use bolt-js only with a user token for the following reason. We can revisit ignore self middleware and update the middleware not to rely on given bot_id.


Hey @~Levelleor! Thanks so much for raising this issue. 🙂

After a little digging, it turns out this is in fact a bug. We've made note of it and will hopefully get a fix out shortly.

In the meantime, to workaround this issue, you can introduce a temporary authorize function that returns both the botId and the userToken, as seen in the example below:

// cached auth.test response
let botAuthTestResult = undefined;

const authorize = async () => {
  if (botAuthTestResult === undefined) {
    // if the cached result does not exist yet
    botAuthTestResult = await app.client.auth.test({token: process.env.SLACK_BOT_TOKEN});
  }
  return {
    // for ignoreSelf middleware compatibility as of bolt-js v3.3
    botId: botAuthTestResult.bot_id,
    // for ignoreSelf middleware compatibility as of bolt-js v3.3
    botUserId: botAuthTestResult.user_id,
    // if the token is a user token, you can use userToken for the key in context
    userToken: process.env.SLACK_USER_TOKEN,
  };
}

const app = new App({
  logLevel: 'debug',
  appToken: process.env.SLACK_APP_TOKEN,
  socketMode: true,
  authorize,
});

Thanks again for bringing this to our attention. Do let us know if the above resolves the problem for the time being!

Originally posted by @misscoded in #869 (comment)

@gitwave gitwave bot added the untriaged label Apr 9, 2021
@seratch seratch added bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor and removed untriaged labels Apr 9, 2021
@seratch seratch modified the milestones: 3.4.0, 3.5.0 Apr 9, 2021
@misscoded misscoded self-assigned this Jun 21, 2021
@seratch seratch modified the milestones: 3.5.0, 3.6.0 Jul 14, 2021
@srajiang srajiang modified the milestones: 3.6.0, 3.7.0 Aug 19, 2021
@seratch
Copy link
Member Author

seratch commented Aug 25, 2021

👋 @misscoded I just found that, for v3.7 release https://github.com/slackapi/bolt-js/milestone/11 , you are assigned to #866 and this one. If you want to focus on #866, I think that you can ask other maintainers to work on this task!

@misscoded
Copy link
Contributor

@seratch I actually got around to fixing this one earlier today and have the code sitting locally! I'll open a PR for it tomorrow morning 🙂

seratch pushed a commit that referenced this issue Aug 28, 2021
* Remove thrown exception if botId isn't present
* fix linting errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants