`fetchInstallation` never called and bot doesn't react to messages?
See original GitHub issueDescription
I am trying to set up a Slack Bolt app using the OAuth mechanism as described in https://slack.dev/bolt-js/concepts#authenticating-oauth but it seems like the authentication never finishes.
My implementation looks like this
export class SlackService {
slackApp: App;
constructor() {
this.slackApp = new App({
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: process.env.SLACK_STATE_SECRET,
scopes: [
'chat:write',
'channels:read',
'channels:history',
'im:read',
'im:write',
'incoming-webhook',
],
logLevel: LogLevel.DEBUG,
installationStore: {
storeInstallation: async (installation) => {
console.log('store installation');
return await database.set(installation.team.id, installation);
},
fetchInstallation: async (InstallQuery) => {
console.log('fetch Installation');
return await database.get(InstallQuery.teamId);
},
},
});
this.bootstrap();
}
async bootstrap() {
await this.slackApp.start(process.env.SLACK_APP_PORT);
this.slackApp.message(':wave:', async ({ message, say }) => {
console.log('got message');
await say(`Hello, <@${message.user}>`);
});
this.slackApp.client.chat.postMessage({...});
console.log('⚡️ Slack app is running!');
}
}
The part with storing the installation works, so store installation
shows up in the console
once I finish the installation. Also the data that I get in store installation seems valid, I tested
the webhook url and it works fine when I just use it in my HTTP requests.
But what’s weird is that fetchInstallation
never gets called, and my app never reacts to the :wave:
message.
The line this.slackApp.client.chat.postMessage({...});
throws an error:
(node:67243) UnhandledPromiseRejectionWarning: Error: An API error occurred: not_authed
Is there something I forgot to add? Unfortunately I can’t find any more information in the docs.
What type of issue is this? (place an x
in one of the [ ]
)
- bug
- enhancement (feature request)
- question
- documentation related
- example code related
- testing related
- discussion
Requirements (place an x
in each of the [ ]
)
- I’ve read and understood the Contributing guidelines and have done my best effort to follow them.
- I’ve read and agree to the Code of Conduct.
- I’ve searched for any related issues and avoided creating a duplicate issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (4 by maintainers)
@Evilweed This may be a bit confusing but the
slackApp.client
does not hold a token (even when you pass a bot token inApp
constructor). Thus, you need to pass token as an argument in the chat.postMessage method call this way:In the case of @zwenza’s app,
installationStore
does not work outside App’s event listeners. If the app needs to post a message when bootstrapping, picking one bot token up to post the message would be the way to go.I think this comment answered both questions. Let me close this issue now. If you have any further questions, please feel free to write in here or create a new question type issue.
Just because it wasn’t immediatly obvious where fetchInstallation could be called from I wrote an example script that uses
postMessage
andfetchInstallation