bolt-js: An unhandled error occurred while Bolt processed an event
We are facing the following issue with the Slack app when we are trying to add the app to another workspace (different from the one where it was created). Once the authorization is given, we are able to read all the credentials including team id, access token, etc. However, when we try to use the same credentials to access the workspace for any activity,
we are getting the following error:
2023-03-20T18:07:34: [ERROR] An unhandled error occurred while Bolt processed an event
2023-03-20T18:07:34: [DEBUG] Error details: TypeError: Cannot read property 'teamId' of undefined, storedResponse: undefined
I think getting this response from Slack bolt,
In the first line, I’m printing the teamId and same also passing it to the bolt lib(authorizer),
0|slack-app | 2023-03-20T18:10:58: TQXMVxxxx
0|slack-app | 2023-03-20T18:10:58: [ERROR] An unhandled error occurred while Bolt processed an event
0|slack-app | 2023-03-20T18:10:58: [DEBUG] Error details: TypeError: Cannot read property 'teamId' of undefined, storedResponse: undefined
Code:
const authorizeFn = async ({ teamId, enterpriseId }) => {
console.log(teamId);
// Fetch team info from database
db.mongoose
.connect(process.env.DB_CONNECTION_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log("Connected to the database!");
})
.catch(err => {
console.log("Cannot connect to the database!", err);
process.exit();
});
Slackbot.find({ "access_details.team.id": teamId })
.then(data => {
if (!data)
console.log("Not found slack user with team " + teamId);
else {
console.log(data[0].access_details);
return {
// You could also set userToken instead
botToken: data[0].access_details.access_token,
botId: data[0].access_details.app_id,
botUserId: data[0].access_details.bot_user_id
};
}
})
.catch(err => {
console.log("Error retrieving slack with team=" + teamId);
});
}
// Initializes your app with your bot token and app token
const app = new App({
appToken: process.env.SLACK_APP_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
logLevel: LogLevel.DEBUG,
customRoutes: customRoutes.customRoutes,
processBeforeResponse: true,
stateSecret: 'my-state-secret',
scopes: [process.env.SLACK_SCOPES],
authorize: authorizeFn
});
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (7 by maintainers)
Added the socket mode also, @filmaj