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

🐛 Ignore Old AppMentions Events #18

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

toddtee
Copy link
Contributor

@toddtee toddtee commented Sep 22, 2023

This commit adds a check to the AppMention event handler, to check how recent the message was created. If the message is greater than 2 seconds old, it will be ignored. This will prevent the bot responding to edited, older messages.

Previously, the bot would respond to any incoming AppMention event, regardless of how old the message was.

Fixes #16.

This commit adds a check to the AppMention event handler, to check how
recent the message was created. If the message is greater than 2 seconds
old, it will be ignored. This will prevent the bot responding to edited,
older messages.

Previously, the bot would respond to any incoming AppMention event,
regardless of how old the message was.

Fixes #16.
@toddtee
Copy link
Contributor Author

toddtee commented Sep 22, 2023

Yeah this sucks, but welcome to the Slack API! 🎉

I tried checking something along the lines of a IsEdited parameter for the event, however this did not appear possible as we trigger this on an AppMention event, so this is not a parameter they attach to this type of event (they do for generic MessageEvents).

So dirty time hacks it is!

Copy link
Collaborator

@Eunoseer Eunoseer left a comment

Choose a reason for hiding this comment

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

It's a shame that the slackEvents go package doesn't seem to support the concept of "message_changed". It looks like the "AppMentionEvent" struct holds the "message" data from the event. There appears to be an open issue against the slack-go library which if resolved could give us the data we need?

Note the "edited" data in the example payload.
Slack-Go issue #961

Slack Event API - message_changed

Slack Go - inner_events.go AppMentionEvent

Copy link
Collaborator

@dHeinemann dHeinemann left a comment

Choose a reason for hiding this comment

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

I haven't tested, but the code looks good to me. Thanks for the PR!

Copy link
Collaborator

@rickwillcox rickwillcox left a comment

Choose a reason for hiding this comment

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

🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀

@toddtee toddtee merged commit 441975b into main Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sugarcity-bot asks "where...", whenever a post is edited.
7 participants