Sasikanth
Sasikanth

Reputation: 3043

Slack Events API not working for normal users

I'm using slack api to send reply whenever there is any direct message to authenticated user. So I created app, enabled events api and verified webhook url and subscribed to messages.im event

enter image description here

I use regular oauth flow with scope(chat:write:user,users:read) to get the access token.

First I tried with the admin of the workspace and everything worked fine. Whenever there is a direct message between admin user and any other user, i'm receiving events to my callback.

NOW

when I tried same with normal user(user2) i'm not receiving any events back when there is direct message between user2 and some other user. I followed the same steps above.

User2 went through same oauth flow with same scopes and got the access token of his own. As I subscribed to events api, I should be able to received event callbacks to the url I mentioned.

Is there any issue here? Is this not how things work?

Upvotes: 4

Views: 3261

Answers (2)

Sasikanth
Sasikanth

Reputation: 3043

Turns out it is an issue with scopes, following is the message I received from slack support team, they are awesome.

Hi Sasikanth,

Thanks for getting back to me. I took a look and it seems that there was some change with the scopes requested when user2 installed the "My App Name" app.

Here are the scopes that each of these users received upon installing the "My App Name":

user1: im:history,users:read,chat:write:user

user2: users:read,chat:write:user

You'll notice that user 1 above has the im:history scope, whereas user 2 above does not. It's mentioned on the doc for the message.im event type (https://api.slack.com/events/message.im) that the im:history scope is needed.

That's the reason why you're not receiving the message.im event type for DMs sent to user 2.

I hope that helps to explain the issue. What you'll need to do is remove the authorization for user2 from: (my dev app url) and have that user reinstall the app with the appropriate scopes.

Upvotes: 1

Erik Kalkoken
Erik Kalkoken

Reputation: 32854

This is not supposed to work.

Your Slack app will only receive message events from channels / conversations, which the installing user is a member of (e.g. the admin is member of the direct messaging conversation between him and others). But it's not possible to get direct messages between other users.

This is how Slack's security architecture is designed. In general it is not possible for any Slack app to monitor all private and direct messaging channel, even if the installing use is an admin / owner.

A common workaround for private channels is to retrieve messages for a bot user and make sure that bot user is a member of all private channels you need to monitor. However, this workaround is not very practical for direct message conversations.

Upvotes: 2

Related Questions