Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

member_joined_channel event not firing for own bot #225

Closed
4 of 9 tasks
YanivSilberman opened this issue Jul 24, 2019 · 5 comments
Closed
4 of 9 tasks

member_joined_channel event not firing for own bot #225

YanivSilberman opened this issue Jul 24, 2019 · 5 comments
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented

Comments

@YanivSilberman
Copy link

Description

My bot is subscribed to the member_joined_channel event, which fires successfully for all group invite events except for my own bot. It works for inviting other users and other bots. I tried it with the @slack/events-api and it worked for my bot, I'm not sure why it doesn't with Bolt. Authorize runs successfully during this event.

Cheers

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation 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.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: 1.2

node version: 10.16.0

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

@TK95
Copy link
Contributor

TK95 commented Jul 29, 2019

I'm seeing the same issue. Also, I noticed in NgRok admin panel that requests are making into /slack/events endpoint (response statuses are marked as 200).

And one more thing, when member_left_channel is fired there is one additional request POST /bot/slack/event which always return 400.

@TK95
Copy link
Contributor

TK95 commented Aug 7, 2019

Alright, since no one doesn't want to look at this question I figured out it by myself.

Here is the line which is causing the issue.

Fix 1 (Long and hard)
Modify source code.

Fix 2 (No one knows what can happen)
Create your app in that way:

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  ignoreSelf: false,
});

Fix 2 works perfectly for me, but it's unclear why do we need that if (in bolt/src/middleware/builtin.ts:L228). It looks like there is an easy and fast way to break Bolt.

@YanivSilberman, ^^

@aoberoi
Copy link
Contributor

aoberoi commented Aug 7, 2019

@TK95 I'm sorry that we hadn't responded to this issue sooner, that's our bad.

I can add some useful context. By default, Bolt apps ignore events that come from itself. This is really useful in situations when your app sends a message and you don't expect your own message listeners to be triggered (what most people would expect). It's not what you want for most other kinds of events.

The ignoreSelf() middleware (which contains the line you linked to above) is the mechanism Bolt apps use to decide whether a specific event should or should not be ignored for the reason that it came from your own app. The ignoreSelf option can be set to false to opt out this behavior (in the case your app expects its own messages to trigger its listeners).


Okay, done with context. What do I think about this issue?

When a member_joined_channel event arrives, it shouldn't be ignored by the ignoreSelf() middleware. If we see that it's being ignored, then that's a bug in that middleware and we need to fix it.

I'd be surprised if it was the line you pointed to (L228) that caused this issue. In fact, that code is contained in a condition that says if (args.message !== undefined) {, which means that line shouldn't be reached (the event is not of message type). Have you modified L228 and observed it working as expected?

Instead, I think the culprit might be the following lines: https://github.com/slackapi/bolt/blob/522e70b381cf3d18a88b7ca271dcfb4f0ce1be9b/src/middleware/builtin.ts#L233-L236

That code will make ignoreSelf() ignore any event whose user property is set to the bot user ID, which it seems does happen with member_joined_channel. In order to fix this, I think we need to audit all the Events API events to see which ones we actually want to ignore, or perhaps instead which ones we are sure we shouldn't ignore (like member_joined_channel) and modify that condition.

@aoberoi aoberoi added the bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented label Aug 7, 2019
@TK95
Copy link
Contributor

TK95 commented Aug 8, 2019

Hi @aoberoi

Thank you for your answer! It's really helpful.

And regarding the code, you're right. These lines are causing the issue:

https://github.com/slackapi/bolt/blob/522e70b381cf3d18a88b7ca271dcfb4f0ce1be9b/src/middleware/builtin.ts#L233-L235

Sorry, I provided the wrong line in my previous message :(

My fix was:

 // Its an Events API event that isn't of type message, but the user ID might match our own app. Filter these out. 
 const isMemberLeftOrJoined = ["member_joined_channel", "member_left_channel"].includes(args.event.type);

 if (botUserId !== undefined && args.event.user === botUserId && !isMemberLeftOrJoined) { 
   return; 
}

Which is exactly what you suggested:

I think we need to audit all the Events API events to see which ones we actually want to ignore, or perhaps instead which ones we are sure we shouldn't ignore (like member_joined_channel) and modify that condition.

I think the best available solution, is setting ignoreSelf flag to false, copying modified ignoreSelfMiddleware to the project and using it.

@ankitshubham97
Copy link

Just writing in case it helps anyone else:
If you try to add a person in a channel where the bot is not already added, the event won't be fired. It started firing when I added the bot to the same channel where the person was later added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented
Projects
None yet
Development

No branches or pull requests

5 participants