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

Fixed the issue with member joined\left channel event not firing for own bot #236

Merged
merged 8 commits into from
Oct 4, 2019
Merged

Fixed the issue with member joined\left channel event not firing for own bot #236

merged 8 commits into from
Oct 4, 2019

Conversation

TK95
Copy link
Contributor

@TK95 TK95 commented Aug 12, 2019

Summary

This PR fixes issue #225 related to member_joined_channel(and also member_left_channel) events which are not fired for own bot.

Plus, I covered with unit tests ignoreSelf() middleware from https://github.com/slackapi/bolt/blob/522e70b381cf3d18a88b7ca271dcfb4f0ce1be9b/src/middleware/builtin.ts#L205

Requirements (place an x in each [ ])

…own bot. Added tests for ignoreSelf middleware
subtype: 'bot_message',
bot_id: fakeBotUserId,
},
} as any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I wasn't able to provide the correct type here :(
If someone could help, it would be great!

@TK95 TK95 marked this pull request as ready for review August 12, 2019 10:47
@codecov
Copy link

codecov bot commented Aug 12, 2019

Codecov Report

Merging #236 into master will increase coverage by 1.98%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
+ Coverage   59.95%   61.94%   +1.98%     
==========================================
  Files           7        7              
  Lines         492      494       +2     
  Branches      136      136              
==========================================
+ Hits          295      306      +11     
+ Misses        169      163       -6     
+ Partials       28       25       -3
Impacted Files Coverage Δ
src/middleware/builtin.ts 44.27% <100%> (+7.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a56f795...faa8426. Read the comment docs.

@@ -231,7 +231,11 @@ export function ignoreSelf(): Middleware<AnyMiddlewareArgs> {
}

// Its an Events API event that isn't of type message, but the user ID might match our own app. Filter these out.
if (botUserId !== undefined && args.event.user === botUserId) {
// However, some events still must be fired, because they can make sense.
const eventsWhichShouldNotBeFilteredOut = ['member_joined_channel', 'member_left_channel'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const eventsWhichShouldNotBeFilteredOut = ['member_joined_channel', 'member_left_channel'];
const eventsWhichShouldBeKept = [
'member_joined_channel',
'member_left_channel',
];

if (botUserId !== undefined && args.event.user === botUserId) {
// However, some events still must be fired, because they can make sense.
const eventsWhichShouldNotBeFilteredOut = ['member_joined_channel', 'member_left_channel'];
const isEventShouldBeSkipped = !eventsWhichShouldNotBeFilteredOut.includes(args.event.type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isEventShouldBeSkipped = !eventsWhichShouldNotBeFilteredOut.includes(args.event.type);
const isEventShouldBeSkipped = !eventsWhichShouldBeKept.includes(args.event.type);

I didn't like the double negative 🤔 this might be more readable...

@shaydewael shaydewael merged commit b030f27 into slackapi:master Oct 4, 2019
assert(fakeNext.notCalled);
});

it('should filter an event out, because it matches our own app and shouldn\'t be retained', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same test as above?

@aoberoi
Copy link
Contributor

aoberoi commented Oct 4, 2019

i just want to say this PR is super awesome!

@TK95 TK95 mentioned this pull request Dec 8, 2019
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants