-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add ability to respond to a message reaction being added or remove #520
Conversation
Pull Request Test Coverage Report for Build 11555364501Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution! with a couple of caveats it works as advertised (see comments).
some further tweaks that would be interesting to explore are (and this definitely doesn't have to be in this PR):
- separate the action (added/removed) so you can target either
- check the target thread to see whether we already replied and, at least by default, don't post again
config-example/rules/reaction.yaml
Outdated
@@ -0,0 +1,11 @@ | |||
name: plus-one-reaction | |||
active: true | |||
reaction_match: ":+1:" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this exact rule work for you?
asking because, 1) i can only make it work without the surrounding :
and 2) only if the value doesn't contain +
, like heavy_plus_sign
works without problem.
the issue is that we send the the string to regex in the matcher where +
has special meaning, and the :
s aren't part of the reaction value returned by the Slack API - at least in my test workspace.
if you throw :+1:
as instead of :hello:
in the test you added you will notice that it fails or maybe you saw that too.
reaction_match: ":+1:" | |
reaction_match: "heavy_plus_sign" |
i think to make +1
work we will need to make a few more tweaks and maybe bypass regex to do an exact match. we can do it in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the example and fixed some issue I found. I decided that we need to treat addition and removals of reactions are separate in Rule and Message model so action can be triggered for one or other or both.
Update example Some refactoring in matcher.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works as advertised. thanks for the tweaks. couple of small things and we're good i think.
i noticed you used plural reactions_added
vs reaction_added
. was the thought to be able to support matching multiple reactions in one rule at some point? if so, i think i like that. some workspaces have multiple emojis that are similar, eg. :question:
and :grey_question:
. nothing that has to be fleshed out in this PR though. just curious.
thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
if rule.Hear == "" && rule.ReactionsAdded == "" && rule.ReactionsRemoved == "" {
not be better as
if rule.Respond != "" {
makes a lot of sense, i like it! let's do that. if you don't mind changing the comment above it as well 🥺 thank you! |
@wass3r - I went with plurals as the use case in the other bot library I use, does take multiple emoji triggers. For this framework, the user would need to craft a regexp string to match multiple. For example:
|
PR for docs target/flottbot-docs#60 |
// | ||
//nolint:gocyclo // refactor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this addition is making the build and validate steps fail
for the failing test (https://github.com/target/flottbot/actions/runs/11521113211/job/32081108474?pr=520#step:5:252), it looks like the improvement you made exposed a flaw in a testcase. in this block Lines 647 to 653 in dc4cfeb
testRuleNeedArg.Respond = "foo" (for example)
|
of Hear, Respond, ReactionsAdded, or ReactionsRremoved Update matcher_tests
@wass3r - Yeah those unit tests need an explicit Hear/Respond added. I've clean up the test and added a check to the function that requires one of Hear, Respond, ReactionsAdded, or ReactionsRemoved. to have a value to be valid. |
i think we're one commit away.. linter is (harshly) complaining about this line Line 244 in 63542e7 |
Fixed to keep the linter happy... On the topic of a rule checking if it's replied to the reaction already, the script/code handling the reaction would need to either
|
yup, i was thinking about utilizing https://api.slack.com/methods/conversations.replies . trying to shy away from adding the complexity of state management for users/admins at this time :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
Proposed change
I worked on a slack chat bot that was based on https://github.com/ArcticSnowman/go-slackbot which I added the ability to respond to emojis (reaction).
So this is my first attempt to add reaction support to this bot framework. Hope this helps with #45
Types of changes
What types of changes is this pull request introducing to flottbot? Put an
x
in the boxes that applyChecklist
You can fill this out after creating your PR. Put an
x
in the boxes that apply