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

Allow outgoing webhook to add reaction when sending a response without additional calls to the REST API. #18117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented Apr 12, 2021

Fixes: #12811

Testing plan:
It has been tested both manually and with automated tests.

GIFs or screenshots:
This introduces a new format for response messages for outgoing webhooks:

{
  "reactions": [
    {"emoji_name": "wave"}
  ]
}

It also works with content:

{
  "content": "test",
  "reactions": [
    {"emoji_name": "wave"}
  ]
}

Responding with two emoji reactions along with a message:
image
When the emoji_name field is missing in a specified emoji reaction:
image
Updated documentation for the API:
image
Error messages;
image

@zulipbot
Copy link
Member

Hello @zulip/server-bots members, this pull request was labeled with the "area: bots" label, so you may want to check it out!

@PIG208 PIG208 changed the title Reaction Allow outgoing webhook to add reaction when sending a response without additional calls to the REST API. Apr 12, 2021
@PIG208
Copy link
Member Author

PIG208 commented Apr 13, 2021

While working on the PR, I found that if the response message is not JSON, it will send an error message after the message that triggers it, but it doesn't notify the user. This might be inconsistent with our error handling logic for outgoing webhooks. Prove me wrong if it's intended this way.

The following is the code responsible for this behavior. We might just want to raise a JsonableError here.

try:
    response_json = json.loads(response.text)
except json.JSONDecodeError:
    fail_with_message(event, "Invalid JSON in response")
    return

@timabbott
Copy link
Sponsor Member

Good find; I think we ended up doing just that in b7b1ec0.

@timabbott
Copy link
Sponsor Member

A small comment on commit messages: You should only put Fixes: in one commit. Also, documentation changes generally belong in the commit that changes reality to match that documentation; so we should squash the documentation commit into the previous one.

@PIG208
Copy link
Member Author

PIG208 commented Apr 28, 2021

Thank you for the feedback!

@timabbott
Copy link
Sponsor Member

timabbott commented Apr 28, 2021

I merged the first commit as 9c0ce19, after moving check_add_reaction after do_add_reaction, since generally it's clearer to have functions call functions above them in the file.

I pushed the second commit back here after a few small documentation/comment changes. It looks correct, but I'd like tests that actually verify the full set of parameters passed to check_add_reaction -- one can imagine some future refactoring bug where we mess up the plumbing of parameters, or something, and so it's worth having a test. (Probably in test_outgoing_webhook_system.py?)

@PIG208
Copy link
Member Author

PIG208 commented May 9, 2021

It looks like that I have broken something with the rebase.

@PIG208 PIG208 force-pushed the reaction branch 6 times, most recently from 3b9324f to 703f1ea Compare May 10, 2021 11:52
@PIG208
Copy link
Member Author

PIG208 commented May 10, 2021

Regarding the access_message issue that I mentioned in #17927, I have added a commit here to fix that. The service bots will be able to access private messages that they have sent or received.

@PIG208 PIG208 force-pushed the reaction branch 4 times, most recently from b7bd6a1 to 9e2e5de Compare May 12, 2021 09:54
@PIG208
Copy link
Member Author

PIG208 commented May 12, 2021

I've rebased this due to a recent change. I'm not sure if a service bot is the only case when a user doesn't have a UserMessage row. It is possible that we can remove the check below?

if (
   user_profile.bot_type == UserProfile.EMBEDDED_BOT
   or user_profile.bot_type == UserProfile.OUTGOING_WEBHOOK_BOT
):

Copy link
Member

@eeshangarg eeshangarg left a comment

Choose a reason for hiding this comment

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

Hey @PIG208! This looks great, thanks for working on this! I just left a couple of minor comments.
As always, please feel free to reach out if you have any questions. Thanks! :)

zerver/lib/message.py Outdated Show resolved Hide resolved
zerver/lib/outgoing_webhook.py Outdated Show resolved Hide resolved
@PIG208 PIG208 force-pushed the reaction branch 2 times, most recently from 0b95d3d to 7dd3edc Compare June 12, 2021 10:34
@PIG208 PIG208 force-pushed the reaction branch 2 times, most recently from 0ad210e to 594b862 Compare June 12, 2021 12:21
@eeshangarg
Copy link
Member

@PIG208 I wonder why the build is failing here. Could you please investigate?

@PIG208
Copy link
Member Author

PIG208 commented Jun 14, 2021

@PIG208 I wonder why the build is failing here. Could you please investigate?

I have rerun the tests several times and I think this might be a nondeterministic error? Will rerun it again.

This commit allows service bots including embedded bots and outgoing
webhook bots to access the private messages they sent or received in
a group or a 1-to-1 chat.

Related: zulip#13658
send_response_reaction is created for the sake of this feature, which
is implemented in a way similar to `send_response_message`. Since this
change, the outgoing webhooks will be able to respond to messages only
with reactions, and sending a response message at the same time is
also supported.

Fixes: zulip#12811
@zulipbot
Copy link
Member

Heads up @PIG208, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

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.

Add a field for bots to reacji in response to webhooks
4 participants