1
votes

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:

enter image description here

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?

1
Are you wanting this to be triggered when the user opens the chat window with the bot, or receives a DM from the bot? Off the top of my head this might only trigger when the user is opening the DM window after a message has been sent to the user.Charlie Stanard
I want it to be triggered when the user opens the DM of the bot anyway.. (I'll handle the first time flag indicator in my storage at backend)Shlomi

1 Answers

1
votes

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.