Reputation: 3792
I have a Slack app that has a Bot user, and I want to get notified via the Slack Events API (using @slack/events-api
official NPM package) when a user opens the app's Direct Message window of the Bot User (UC: to send him a welcome message).
Looks like the im_open
event is what i need but somehow it's not triggered.
I configured it in my app's settings:
And then defined the following code:
const { createEventAdapter } = require('@slack/events-api');
const slackEvents = createEventAdapter('some-secret);
slackEvents.on('im_open', async (event) => {
console.log(`Received a im_open event`);
});
const port = 5000;
slackEvents.start(port).then(() => {
console.log(`server listening on port ${port}`);
});
But it's never triggered.
I have listeners for app_mention
and message
events that works fine but this one somehow doesn't.
Any idea why?
Upvotes: 1
Views: 318
Reputation: 32852
I think you misunderstand what triggers the im.open
event.
It fires when a new direct message channel is established for the first time, not when someone clicks on an existing channel to see its messages. The app channel is created by default during installation of the app. You probably don't see it fired, because it is created before the event handler of your app can be active.
So this will not work and to my knowledge there also is no alternative solution to your problem. Slack events just are not designed to work on the UI level.
Upvotes: 1