Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks: Add support to event filtering system for webhooks.
PIG2085359d20a13b3
diff --git a/zerver/webhooks/basecamp/view.py b/zerver/webhooks/basecamp/view.pyindex 3c6bcfb631c..f8d78906fc8 100644--- a/zerver/webhooks/basecamp/view.py+++ b/zerver/webhooks/basecamp/view.py@@ -26,8 +26,18 @@ MESSAGE_TEMPLATE = "{user_name} {verb} the message [{title}]({url})"TODO_LIST_TEMPLATE = "{user_name} {verb} the todo list [{title}]({url})"TODO_TEMPLATE = "{user_name} {verb} the todo task [{title}]({url})"--@webhook_view("Basecamp")+ALL_EVENT_TYPES = [+ "document",+ "question_answer",+ "question",+ "message",+ "todolist",+ "todo",+ "comment",+]+++@webhook_view("Basecamp", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_basecamp_webhook(request: HttpRequest,@@ -42,22 +52,29 @@ def api_basecamp_webhook(subject = get_project_name(payload)if event.startswith("document_"):body = get_document_body(event, payload)+ event = "document"elif event.startswith("question_answer_"):body = get_questions_answer_body(event, payload)+ event = "question_answer"elif event.startswith("question_"):body = get_questions_body(event, payload)+ event = "question"elif event.startswith("message_"):body = get_message_body(event, payload)+ event = "message"elif event.startswith("todolist_"):body = get_todo_list_body(event, payload)+ event = "todolist"elif event.startswith("todo_"):body = get_todo_body(event, payload)+ event = "todo"elif event.startswith("comment_"):body = get_comment_body(event, payload)+ event = "comment"else:raise UnsupportedWebhookEventType(event)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, event)return json_success()diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.pyindex eca1d12f653..249fa68a2ba 100644--- a/zerver/webhooks/bitbucket2/view.py+++ b/zerver/webhooks/bitbucket2/view.py@@ -53,8 +53,28 @@ PULL_REQUEST_SUPPORTED_ACTIONS = ["comment_deleted",]+ALL_EVENT_TYPES = [+ "change_commit_status",+ "pull_request_comment_created",+ "pull_request_updated",+ "pull_request_unapproved",+ "push",+ "pull_request_approved",+ "pull_request_fulfilled",+ "issue_created",+ "issue_commented",+ "fork",+ "pull_request_comment_updated",+ "pull_request_created",+ "pull_request_rejected",+ "repo:updated",+ "issue_updated",+ "commit_comment",+ "pull_request_comment_deleted",+]+-@webhook_view("Bitbucket2")+@webhook_view("Bitbucket2", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_bitbucket2_webhook(request: HttpRequest,@@ -85,11 +105,13 @@ def api_bitbucket2_webhook(if type != "push":check_send_webhook_message(- request, user_profile, subject, body, unquote_url_parameters=True+ request, user_profile, subject, body, type, unquote_url_parameters=True)else:for b, s in zip(body, subject):- check_send_webhook_message(request, user_profile, s, b, unquote_url_parameters=True)+ check_send_webhook_message(+ request, user_profile, s, b, type, unquote_url_parameters=True+ )return json_success()diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.pyindex 7e0c5b8ce13..f5e5063de53 100644--- a/zerver/webhooks/bitbucket3/view.py+++ b/zerver/webhooks/bitbucket3/view.py@@ -380,8 +380,10 @@ EVENT_HANDLER_MAP: Dict[str, Optional[Callable[..., List[Dict[str, str]]]]] = {"pr:reviewer:unapproved": partial(pr_handler, action="unapproved"),}+ALL_EVENT_TYPES = list(EVENT_HANDLER_MAP.keys())-@webhook_view("Bitbucket3")++@webhook_view("Bitbucket3", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_bitbucket3_webhook(request: HttpRequest,@@ -406,7 +408,12 @@ def api_bitbucket3_webhook(data = handler(payload)for element in data:check_send_webhook_message(- request, user_profile, element["subject"], element["body"], unquote_url_parameters=True+ request,+ user_profile,+ element["subject"],+ element["body"],+ eventkey,+ unquote_url_parameters=True,)return json_success()diff --git a/zerver/webhooks/buildbot/view.py b/zerver/webhooks/buildbot/view.pyindex cdda546bf02..a0ff5d9bf3d 100644--- a/zerver/webhooks/buildbot/view.py+++ b/zerver/webhooks/buildbot/view.py@@ -8,8 +8,10 @@ from zerver.lib.response import json_successfrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile+ALL_EVENT_TYPES = ["new", "finished"]-@webhook_view("Buildbot")++@webhook_view("Buildbot", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_buildbot_webhook(request: HttpRequest,@@ -20,7 +22,7 @@ def api_buildbot_webhook(if not topic:topic = "general"body = get_message(payload)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, payload["event"])return json_success()diff --git a/zerver/webhooks/circleci/view.py b/zerver/webhooks/circleci/view.pyindex 6824c086464..96de45911bf 100644--- a/zerver/webhooks/circleci/view.py+++ b/zerver/webhooks/circleci/view.py@@ -14,8 +14,10 @@ outcome_to_formatted_status_map = {"canceled": "was canceled",}+ALL_EVENT_TYPES = list(outcome_to_formatted_status_map.keys())-@webhook_view("CircleCI")++@webhook_view("CircleCI", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_circleci_webhook(request: HttpRequest,@@ -26,7 +28,13 @@ def api_circleci_webhook(subject = get_subject(payload)body = get_body(payload)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(+ request,+ user_profile,+ subject,+ body,+ payload.get("status") if not payload.get("build_num") else payload.get("outcome"),+ )return json_success()diff --git a/zerver/webhooks/clubhouse/tests.py b/zerver/webhooks/clubhouse/tests.pyindex 755bbb061f9..c735069db79 100644--- a/zerver/webhooks/clubhouse/tests.py+++ b/zerver/webhooks/clubhouse/tests.py@@ -232,6 +232,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="Story1", url="https://app.clubhouse.io/pig208/story/17"),+ "pull-request_create",),call(request,@@ -240,6 +241,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="Story2", url="https://app.clubhouse.io/pig208/story/18"),+ "pull-request_create",),]self.assertEqual(check_send_webhook_message_mock.call_args_list, expected_list)@@ -271,6 +273,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="new1", url="https://app.clubhouse.io/pig208/story/26"),+ "pull-request_comment",),call(request,@@ -279,6 +282,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="new2", url="https://app.clubhouse.io/pig208/story/27"),+ "pull-request_comment",),]self.assertEqual(check_send_webhook_message_mock.call_args_list, expected_list)@@ -306,6 +310,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="asd4", url="https://app.clubhouse.io/pig208/story/17"),+ "story_update_batch",),call(request,@@ -314,6 +319,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="new1", url="https://app.clubhouse.io/pig208/story/26"),+ "story_update_batch",),call(request,@@ -322,6 +328,7 @@ class ClubhouseWebhookTest(WebhookTestCase):expected_message.format(name="new2", url="https://app.clubhouse.io/pig208/story/27"),+ "story_update_batch",),]self.assertEqual(check_send_webhook_message_mock.call_args_list, expected_list)@@ -364,6 +371,7 @@ class ClubhouseWebhookTest(WebhookTestCase):user_profile,expected_message[0],expected_message[1],+ "story_update_batch",)for expected_message in expected_messages]diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.pyindex bd7929fec21..77d499a67c6 100644--- a/zerver/webhooks/clubhouse/view.py+++ b/zerver/webhooks/clubhouse/view.py@@ -640,7 +640,7 @@ def send_stream_messages_for_actions(body = body_func(payload, action)if topic and body:- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)EVENT_BODY_FUNCTION_MAPPER: Dict[str, Callable[[Dict[str, Any], Dict[str, Any]], Optional[str]]] = {@@ -676,6 +676,8 @@ EVENT_BODY_FUNCTION_MAPPER: Dict[str, Callable[[Dict[str, Any], Dict[str, Any]],"story_update_batch": get_story_update_batch_body,}+ALL_EVENT_TYPES = list(EVENT_BODY_FUNCTION_MAPPER.keys())+EVENT_TOPIC_FUNCTION_MAPPER = {"story": partial(get_entity_name, entity="story"),"pull-request": partial(get_entity_name, entity="story"),@@ -705,7 +707,7 @@ EVENTS_SECONDARY_ACTIONS_FUNCTION_MAPPER: Dict[}-@webhook_view("ClubHouse")+@webhook_view("ClubHouse", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_clubhouse_webhook(request: HttpRequest,diff --git a/zerver/webhooks/freshping/view.py b/zerver/webhooks/freshping/view.pyindex 5705a0355b4..acb30c5e3f9 100644--- a/zerver/webhooks/freshping/view.py+++ b/zerver/webhooks/freshping/view.py@@ -16,9 +16,10 @@ FRESHPING_MESSAGE_TEMPLATE_UNREACHABLE = """Error code: {http_status_code}.""".strip()FRESHPING_MESSAGE_TEMPLATE_UP = "{request_url} is back up and no longer unreachable."+ALL_EVENT_TYPES = ["Reporting Error", "Available"]-@webhook_view("Freshping")+@webhook_view("Freshping", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_freshping_webhook(request: HttpRequest,@@ -29,7 +30,9 @@ def api_freshping_webhook(body = get_body_for_http_request(payload)subject = get_subject_for_http_request(payload)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(+ request, user_profile, subject, body, payload["webhook_event_data"]["check_state_name"]+ )return json_success()diff --git a/zerver/webhooks/freshstatus/view.py b/zerver/webhooks/freshstatus/view.pyindex 9ed262a9206..d6f0ad04574 100644--- a/zerver/webhooks/freshstatus/view.py+++ b/zerver/webhooks/freshstatus/view.py@@ -67,8 +67,16 @@ FRESHSTATUS_SERVICES_ROW_TEMPLATE = "* {service_name}\n"FRESHSTATUS_SERVICES_OTHERS_ROW_TEMPLATE = "[and {services_number} more service(s)]"FRESHSTATUS_SERVICES_LIMIT = 5+ALL_EVENT_TYPES = [+ "MAINTENANCE_NOTE_CREATE",+ "INCIDENT_NOTE_CREATE",+ "INCIDENT_OPEN",+ "MAINTENANCE_PLANNED",+ "INCIDENT_REOPEN",+]-@webhook_view("Freshstatus")++@webhook_view("Freshstatus", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_freshstatus_webhook(request: HttpRequest,@@ -88,7 +96,9 @@ def api_freshstatus_webhook(raise JsonableError(_("Invalid payload"))- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(+ request, user_profile, subject, body, payload["event_data"]["event_type"]+ )return json_success()diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.pyindex 2a97fa1fa1d..8e2a02d05e4 100644--- a/zerver/webhooks/front/view.py+++ b/zerver/webhooks/front/view.py@@ -129,12 +129,14 @@ EVENT_FUNCTION_MAPPER = {"untag": get_conversation_untagged_body,}+ALL_EVENT_TYPES = list(EVENT_FUNCTION_MAPPER.keys())+def get_body_based_on_event(event: str) -> Any:return EVENT_FUNCTION_MAPPER[event]-@webhook_view("Front")+@webhook_view("Front", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_front_webhook(request: HttpRequest,@@ -148,6 +150,6 @@ def api_front_webhook(topic = payload["conversation"]["id"]body = get_body_based_on_event(event)(payload)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()diff --git a/zerver/webhooks/gci/view.py b/zerver/webhooks/gci/view.pyindex d6a5583faf6..cdf07fafa1c 100644--- a/zerver/webhooks/gci/view.py+++ b/zerver/webhooks/gci/view.py@@ -113,7 +113,23 @@ def get_outoftime_event_body(payload: Dict[str, Any]) -> str:)-@webhook_view("GoogleCodeIn")+EVENTS_FUNCTION_MAPPER = {+ "abandon": get_abandon_event_body,+ "approve": get_approve_event_body,+ "approve-pending-pc": get_approve_pending_pc_event_body,+ "claim": get_claim_event_body,+ "comment": get_comment_event_body,+ "extend": get_extend_event_body,+ "needswork": get_needswork_event_body,+ "outoftime": get_outoftime_event_body,+ "submit": get_submit_event_body,+ "unassign": get_unassign_event_body,+}++ALL_EVENT_TYPES = list(EVENTS_FUNCTION_MAPPER.keys())+++@webhook_view("GoogleCodeIn", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_gci_webhook(request: HttpRequest,@@ -126,25 +142,11 @@ def api_gci_webhook(subject = GCI_TOPIC_TEMPLATE.format(student_name=payload["task_claimed_by"],)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, event)return json_success()-EVENTS_FUNCTION_MAPPER = {- "abandon": get_abandon_event_body,- "approve": get_approve_event_body,- "approve-pending-pc": get_approve_pending_pc_event_body,- "claim": get_claim_event_body,- "comment": get_comment_event_body,- "extend": get_extend_event_body,- "needswork": get_needswork_event_body,- "outoftime": get_outoftime_event_body,- "submit": get_submit_event_body,- "unassign": get_unassign_event_body,-}--def get_event(payload: Dict[str, Any]) -> Optional[str]:event = payload["event_type"]if event in EVENTS_FUNCTION_MAPPER:diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.pyindex f1f50dc1962..ebe5b972c8a 100644--- a/zerver/webhooks/gitlab/view.py+++ b/zerver/webhooks/gitlab/view.py@@ -390,8 +390,10 @@ EVENT_FUNCTION_MAPPER = {"Pipeline Hook": get_pipeline_event_body,}+ALL_EVENT_TYPES = list(EVENT_FUNCTION_MAPPER.keys())-@webhook_view("GitLab")++@webhook_view("GitLab", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_gitlab_webhook(request: HttpRequest,@@ -418,7 +420,7 @@ def api_gitlab_webhook(body = f"[{project_url}] {body}"topic = get_subject_based_on_event(event, payload, use_merge_request_title)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.pyindex a253fc84fed..4e4b1922735 100644--- a/zerver/webhooks/gogs/view.py+++ b/zerver/webhooks/gogs/view.py@@ -127,7 +127,10 @@ def format_release_event(payload: Dict[str, Any], include_title: bool = False) -return get_release_event_message(**data)-@webhook_view("Gogs")+ALL_EVENT_TYPES = ["issue_comment", "issues", "create", "pull_request", "push", "release"]+++@webhook_view("Gogs", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_gogs_webhook(request: HttpRequest,@@ -227,5 +230,5 @@ def gogs_webhook_main(else:raise UnsupportedWebhookEventType(event)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()diff --git a/zerver/webhooks/gosquared/view.py b/zerver/webhooks/gosquared/view.pyindex 7e2a2df5451..37f3f635eca 100644--- a/zerver/webhooks/gosquared/view.py+++ b/zerver/webhooks/gosquared/view.py@@ -19,7 +19,10 @@ The {status} **{name}** messaged:""".strip()-@webhook_view("GoSquared")+ALL_EVENT_TYPES = ["chat_message", "traffic_spike"]+++@webhook_view("GoSquared", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_gosquared_webhook(request: HttpRequest,@@ -41,7 +44,7 @@ def api_gosquared_webhook(website_name=domain_name, website_url=acc_url, user_num=user_num)topic = f"GoSquared - {domain_name}"- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, "traffic_spike")# Live chat message eventelif payload.get("message") is not None and payload.get("person") is not None:@@ -54,7 +57,7 @@ def api_gosquared_webhook(name=payload["person"]["_anon"]["name"],content=payload["message"]["content"],)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, "chat_message")else:raise UnsupportedWebhookEventType("unknown_event")diff --git a/zerver/webhooks/grafana/view.py b/zerver/webhooks/grafana/view.pyindex d873a55dcfa..ddcc3c5ba02 100644--- a/zerver/webhooks/grafana/view.py+++ b/zerver/webhooks/grafana/view.py@@ -16,8 +16,10 @@ GRAFANA_MESSAGE_TEMPLATE = ("{alert_status}[{rule_name}]({rule_url})\n\n{alert_message}{eval_matches}")+ALL_EVENT_TYPES = ["ok", "pending", "alerting", "paused"]-@webhook_view("Grafana")++@webhook_view("Grafana", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_grafana_webhook(request: HttpRequest,@@ -67,6 +69,6 @@ def api_grafana_webhook(body = body.strip()# send the message- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, payload.get("state"))return json_success()diff --git a/zerver/webhooks/groove/view.py b/zerver/webhooks/groove/view.pyindex 26b133228b5..c689edf6431 100644--- a/zerver/webhooks/groove/view.py+++ b/zerver/webhooks/groove/view.py@@ -79,7 +79,18 @@ def replied_body(payload: Dict[str, Any], actor: str, action: str) -> str:return body-@webhook_view("Groove")+EVENTS_FUNCTION_MAPPER: Dict[str, Callable[[Dict[str, Any]], Optional[str]]] = {+ "ticket_started": ticket_started_body,+ "ticket_assigned": ticket_assigned_body,+ "agent_replied": partial(replied_body, actor="agent", action="replied to"),+ "customer_replied": partial(replied_body, actor="customer", action="replied to"),+ "note_added": partial(replied_body, actor="agent", action="left a note on"),+}++ALL_EVENT_TYPES = list(EVENTS_FUNCTION_MAPPER.keys())+++@webhook_view("Groove", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_groove_webhook(request: HttpRequest,@@ -96,17 +107,9 @@ def api_groove_webhook(topic = "notifications"if body is not None:- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()-EVENTS_FUNCTION_MAPPER: Dict[str, Callable[[Dict[str, Any]], Optional[str]]] = {- "ticket_started": ticket_started_body,- "ticket_assigned": ticket_assigned_body,- "agent_replied": partial(replied_body, actor="agent", action="replied to"),- "customer_replied": partial(replied_body, actor="customer", action="replied to"),- "note_added": partial(replied_body, actor="agent", action="left a note on"),-}-fixture_to_headers = get_http_headers_from_filename("HTTP_X_GROOVE_EVENT")diff --git a/zerver/webhooks/harbor/view.py b/zerver/webhooks/harbor/view.pyindex 262e55c6791..658e1343b65 100644--- a/zerver/webhooks/harbor/view.py+++ b/zerver/webhooks/harbor/view.py@@ -83,8 +83,10 @@ EVENT_FUNCTION_MAPPER = {"scanningCompleted": handle_scanning_completed_event,}+ALL_EVENT_TYPES = list(EVENT_FUNCTION_MAPPER.keys())-@webhook_view("Harbor")++@webhook_view("Harbor", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_harbor_webhook(request: HttpRequest,@@ -113,5 +115,7 @@ def api_harbor_webhook(content: str = content_func(payload, user_profile, operator_username)- check_send_webhook_message(request, user_profile, topic, content, unquote_url_parameters=True)+ check_send_webhook_message(+ request, user_profile, topic, content, event, unquote_url_parameters=True+ )return json_success()diff --git a/zerver/webhooks/intercom/view.py b/zerver/webhooks/intercom/view.pyindex 0a0906eccaf..c0e6aac6d25 100644--- a/zerver/webhooks/intercom/view.py+++ b/zerver/webhooks/intercom/view.py@@ -301,8 +301,10 @@ EVENT_TO_FUNCTION_MAPPER: Dict[str, Callable[[Dict[str, Any]], Tuple[str, str]]]"visitor.signed_up": get_contact_signed_up_message,}+ALL_EVENT_TYPES = list(EVENT_TO_FUNCTION_MAPPER.keys())-@webhook_view("Intercom")++@webhook_view("Intercom", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_intercom_webhook(request: HttpRequest,@@ -318,5 +320,5 @@ def api_intercom_webhook(raise UnsupportedWebhookEventType(event_type)topic, body = handler(payload)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event_type)return json_success()diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.pyindex 16bb75468ce..9dedb130138 100644--- a/zerver/webhooks/jira/view.py+++ b/zerver/webhooks/jira/view.py@@ -325,9 +325,7 @@ def handle_comment_deleted_event(payload: Dict[str, Any], user_profile: UserProf)-JIRA_CONTENT_FUNCTION_MAPPER: Dict[- Optional[str], Optional[Callable[[Dict[str, Any], UserProfile], str]]-] = {+JIRA_CONTENT_FUNCTION_MAPPER: Dict[str, Optional[Callable[[Dict[str, Any], UserProfile], str]]] = {"jira:issue_created": handle_created_issue_event,"jira:issue_deleted": handle_deleted_issue_event,"jira:issue_updated": handle_updated_issue_event,@@ -336,8 +334,10 @@ JIRA_CONTENT_FUNCTION_MAPPER: Dict["comment_deleted": handle_comment_deleted_event,}+ALL_EVENT_TYPES = list(JIRA_CONTENT_FUNCTION_MAPPER.keys())-@webhook_view("Jira")++@webhook_view("Jira", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_jira_webhook(request: HttpRequest,@@ -349,7 +349,8 @@ def api_jira_webhook(if event in IGNORED_EVENTS:return json_success()- content_func = JIRA_CONTENT_FUNCTION_MAPPER.get(event)+ if event is not None:+ content_func = JIRA_CONTENT_FUNCTION_MAPPER.get(event)if content_func is None:raise UnsupportedWebhookEventType(event)@@ -357,5 +358,7 @@ def api_jira_webhook(subject = get_issue_subject(payload)content: str = content_func(payload, user_profile)- check_send_webhook_message(request, user_profile, subject, content, unquote_url_parameters=True)+ check_send_webhook_message(+ request, user_profile, subject, content, event, unquote_url_parameters=True+ )return json_success()diff --git a/zerver/webhooks/lidarr/view.py b/zerver/webhooks/lidarr/view.pyindex 9d8e92d5599..e16fbbd4822 100644--- a/zerver/webhooks/lidarr/view.py+++ b/zerver/webhooks/lidarr/view.py@@ -36,6 +36,8 @@ LIDARR_TRACKS_ROW_TEMPLATE = "* {track_title}\n"LIDARR_TRACKS_OTHERS_ROW_TEMPLATE = "[and {tracks_number} more tracks(s)]"LIDARR_TRACKS_LIMIT = 20+ALL_EVENT_TYPES = ["Test", "Grab", "Rename", "Retag", "Download"]+def get_tracks_content(tracks_data: List[Dict[str, Any]]) -> str:tracks_content = ""@@ -50,7 +52,7 @@ def get_tracks_content(tracks_data: List[Dict[str, Any]]) -> str:return tracks_content.rstrip()-@webhook_view("Lidarr")+@webhook_view("Lidarr", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_lidarr_webhook(request: HttpRequest,@@ -60,7 +62,7 @@ def api_lidarr_webhook(body = get_body_for_http_request(payload)subject = get_subject_for_http_request(payload)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, payload["eventType"])return json_success()diff --git a/zerver/webhooks/netlify/view.py b/zerver/webhooks/netlify/view.pyindex 64e5cd959f5..2bb012348a6 100644--- a/zerver/webhooks/netlify/view.py+++ b/zerver/webhooks/netlify/view.py@@ -1,4 +1,4 @@-from typing import Any, Dict, Sequence+from typing import Any, Dict, Sequence, Tuplefrom django.http import HttpRequest, HttpResponse@@ -13,12 +13,18 @@ from zerver.lib.webhooks.common import ()from zerver.models import UserProfile-EVENTS = ["deploy_failed", "deploy_locked", "deploy_unlocked", "deploy_building", "deploy_created"]+ALL_EVENT_TYPES = [+ "deploy_failed",+ "deploy_locked",+ "deploy_unlocked",+ "deploy_building",+ "deploy_created",+]fixture_to_headers = get_http_headers_from_filename("HTTP_X_NETLIFY_EVENT")-@webhook_view("Netlify")+@webhook_view("Netlify", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_netlify_webhook(request: HttpRequest,@@ -26,7 +32,7 @@ def api_netlify_webhook(payload: Dict[str, Sequence[Dict[str, Any]]] = REQ(argument_type="body"),) -> HttpResponse:- message_template = get_template(request, payload)+ message_template, event = get_template(request, payload)body = message_template.format(build_name=payload["name"],@@ -37,23 +43,25 @@ def api_netlify_webhook(topic = "{topic}".format(topic=payload["branch"])- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()-def get_template(request: HttpRequest, payload: Dict[str, Any]) -> str:+def get_template(request: HttpRequest, payload: Dict[str, Any]) -> Tuple[str, str]:message_template = "The build [{build_name}]({build_url}) on branch {branch_name} "event = validate_extract_webhook_http_header(request, "X_NETLIFY_EVENT", "Netlify")if event == "deploy_failed":- return message_template + payload["error_message"]+ message_template += payload["error_message"]elif event == "deploy_locked":- return message_template + "is now locked."+ message_template += "is now locked."elif event == "deploy_unlocked":- return message_template + "is now unlocked."- elif event in EVENTS:- return message_template + "is now {state}.".format(state=payload["state"])+ message_template += "is now unlocked."+ elif event in ALL_EVENT_TYPES:+ message_template += "is now {state}.".format(state=payload["state"])else:raise UnsupportedWebhookEventType(event)++ return message_template, eventdiff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.pyindex 110db4c0395..758d2bd9dd1 100644--- a/zerver/webhooks/newrelic/view.py+++ b/zerver/webhooks/newrelic/view.py@@ -24,8 +24,10 @@ DEFAULT_TEMPLATE = (TOPIC_TEMPLATE = """{policy_name} ({incident_id})""".strip()+ALL_EVENT_TYPES = ["closed", "acknowledged", "open"]-@webhook_view("NewRelic")++@webhook_view("NewRelic", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_newrelic_webhook(request: HttpRequest,@@ -73,5 +75,5 @@ def api_newrelic_webhook(}topic = TOPIC_TEMPLATE.format(**topic_info)- check_send_webhook_message(request, user_profile, topic, content)+ check_send_webhook_message(request, user_profile, topic, content, info["status"])return json_success()diff --git a/zerver/webhooks/opsgenie/view.py b/zerver/webhooks/opsgenie/view.pyindex ff55ecfe069..8a14d99279c 100644--- a/zerver/webhooks/opsgenie/view.py+++ b/zerver/webhooks/opsgenie/view.py@@ -8,8 +8,25 @@ from zerver.lib.response import json_successfrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile+ALL_EVENT_TYPES = [+ "AddTeam",+ "UnAcknowledge",+ "AddNote",+ "TestAction",+ "Close",+ "Escalate",+ "AddRecipient",+ "RemoveTags",+ "Acknowledge",+ "Delete",+ "AddTags",+ "TakeOwnership",+ "Create",+ "AssignOwnership",+]-@webhook_view("OpsGenie")++@webhook_view("OpsGenie", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_opsgenie_webhook(request: HttpRequest,@@ -82,6 +99,6 @@ def api_opsgenie_webhook(""".strip()body = body_template.format(**info)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, info["alert_type"])return json_success()diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.pyindex 8efbcc5e2ad..49e8be00bd2 100644--- a/zerver/webhooks/pagerduty/view.py+++ b/zerver/webhooks/pagerduty/view.py@@ -1,4 +1,3 @@-# Webhooks for external integrations.from typing import Any, Dictfrom django.http import HttpRequest, HttpResponse@@ -35,6 +34,15 @@ PAGER_DUTY_EVENT_NAMES_V3 = {"incident.reassigned": "reassigned",}+ALL_EVENT_TYPES = [+ "resolved",+ "assigned",+ "unacknowledged",+ "acknowledged",+ "triggered",+ "reassigned",+]+AGENT_TEMPLATE = "[{username}]({url})"INCIDENT_WITH_SERVICE_AND_ASSIGNEE = (@@ -206,10 +214,10 @@ def send_formated_pagerduty(subject = "Incident {incident_num_title}".format(**format_dict)body = template.format(**format_dict)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, format_dict["action"])-@webhook_view("PagerDuty")+@webhook_view("PagerDuty", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_pagerduty_webhook(request: HttpRequest,diff --git a/zerver/webhooks/pingdom/view.py b/zerver/webhooks/pingdom/view.pyindex c3a40e59c11..e60c680f64e 100644--- a/zerver/webhooks/pingdom/view.py+++ b/zerver/webhooks/pingdom/view.py@@ -36,8 +36,10 @@ SUPPORTED_CHECK_TYPES = ("PORT_TCP",)+ALL_EVENT_TYPES = list(SUPPORTED_CHECK_TYPES)-@webhook_view("Pingdom")++@webhook_view("Pingdom", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_pingdom_webhook(request: HttpRequest,@@ -52,7 +54,7 @@ def api_pingdom_webhook(else:raise UnsupportedWebhookEventType(check_type)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, check_type)return json_success()diff --git a/zerver/webhooks/pivotal/tests.py b/zerver/webhooks/pivotal/tests.pyindex b47b07db095..31bcca5a4fa 100644--- a/zerver/webhooks/pivotal/tests.py+++ b/zerver/webhooks/pivotal/tests.py@@ -4,6 +4,7 @@ from zerver.lib.test_classes import WebhookTestCaseclass PivotalV3HookTests(WebhookTestCase):STREAM_NAME = "pivotal"URL_TEMPLATE = "/api/v1/external/pivotal?stream={stream}&api_key={api_key}"+ WEBHOOK_DIR_NAME = "pivotal"def test_accepted(self) -> None:expected_topic = "My new Feature story"@@ -94,6 +95,7 @@ class PivotalV3HookTests(WebhookTestCase):class PivotalV5HookTests(WebhookTestCase):STREAM_NAME = "pivotal"URL_TEMPLATE = "/api/v1/external/pivotal?stream={stream}&api_key={api_key}"+ WEBHOOK_DIR_NAME = "pivotal"def test_accepted(self) -> None:expected_topic = "#63486316: Story of the Year"diff --git a/zerver/webhooks/pivotal/view.py b/zerver/webhooks/pivotal/view.pyindex 7f2ed55bf30..2732921dc37 100644--- a/zerver/webhooks/pivotal/view.py+++ b/zerver/webhooks/pivotal/view.py@@ -15,7 +15,7 @@ from zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile-def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str]:+def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str, str]:payload = xml_fromstring(request.body)def get_text(attrs: List[str]) -> str:@@ -60,7 +60,7 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Testimate = f" worth {estimate} story points"subject = namecontent = f"{description} ({issue_status} {issue_type}{estimate}):\n\n~~~ quote\n{issue_desc}\n~~~\n\n{more_info}"- return subject, content+ return subject, content, f"{event_type}_v3"UNSUPPORTED_EVENT_TYPES = [@@ -75,8 +75,18 @@ UNSUPPORTED_EVENT_TYPES = ["label_create_activity",]+ALL_EVENT_TYPES = [+ "story_update_v3",+ "note_create_v3",+ "story_create_v3",+ "story_move_activity_v5",+ "story_create_activity_v5",+ "story_update_activity_v5",+ "comment_create_activity_v5",+]+-def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str]:+def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str, str]:payload = orjson.loads(request.body)event_type = payload["kind"]@@ -162,21 +172,21 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> Telse:raise UnsupportedWebhookEventType(event_type)- return subject, content+ return subject, content, f"{event_type}_v5"-@webhook_view("Pivotal")+@webhook_view("Pivotal", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:subject = content = Nonetry:- subject, content = api_pivotal_webhook_v3(request, user_profile)+ subject, content, event_type = api_pivotal_webhook_v3(request, user_profile)except Exception:# Attempt to parse v5 JSON payload- subject, content = api_pivotal_webhook_v5(request, user_profile)+ subject, content, event_type = api_pivotal_webhook_v5(request, user_profile)if not content:raise JsonableError(_("Unable to handle Pivotal payload"))- check_send_webhook_message(request, user_profile, subject, content)+ check_send_webhook_message(request, user_profile, subject, content, event_type)return json_success()diff --git a/zerver/webhooks/radarr/view.py b/zerver/webhooks/radarr/view.pyindex c17947b9495..919c02ce079 100644--- a/zerver/webhooks/radarr/view.py+++ b/zerver/webhooks/radarr/view.py@@ -21,8 +21,10 @@ RADARR_MESSAGE_TEMPLATE_MOVIE_IMPORTED_UPGRADE = ()RADARR_MESSAGE_TEMPLATE_MOVIE_GRABBED = "The movie {movie_title} has been grabbed.".strip()+ALL_EVENT_TYPES = ["Rename", "Test", "Download", "Health", "Grab"]-@webhook_view("Radarr")++@webhook_view("Radarr", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_radarr_webhook(request: HttpRequest,@@ -32,7 +34,7 @@ def api_radarr_webhook(body = get_body_for_http_request(payload)subject = get_subject_for_http_request(payload)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, payload["eventType"])return json_success()diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.pyindex 6717c8e568b..4d6895df4d3 100644--- a/zerver/webhooks/raygun/view.py+++ b/zerver/webhooks/raygun/view.py@@ -10,8 +10,10 @@ from zerver.lib.response import json_successfrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile+ALL_EVENT_TYPES = ["error_notification", "error_activity"]-@webhook_view("Raygun")++@webhook_view("Raygun", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_raygun_webhook(request: HttpRequest,@@ -38,7 +40,7 @@ def api_raygun_webhook(topic = "test"- check_send_webhook_message(request, user_profile, topic, message)+ check_send_webhook_message(request, user_profile, topic, message, event)return json_success()diff --git a/zerver/webhooks/reviewboard/view.py b/zerver/webhooks/reviewboard/view.pyindex 0b66c1cc811..c0679b9255e 100644--- a/zerver/webhooks/reviewboard/view.py+++ b/zerver/webhooks/reviewboard/view.py@@ -172,8 +172,10 @@ RB_MESSAGE_FUNCTIONS = {"reply_published": get_reply_published_body,}+ALL_EVENT_TYPES = list(RB_MESSAGE_FUNCTIONS.keys())-@webhook_view("ReviewBoard")++@webhook_view("ReviewBoard", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_reviewboard_webhook(request: HttpRequest,@@ -187,7 +189,7 @@ def api_reviewboard_webhook(if body_function is not None:body = body_function(payload)topic = get_review_request_repo_title(payload)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event_type)else:raise UnsupportedWebhookEventType(event_type)diff --git a/zerver/webhooks/semaphore/view.py b/zerver/webhooks/semaphore/view.pyindex eb24958f267..66b780e4db6 100644--- a/zerver/webhooks/semaphore/view.py+++ b/zerver/webhooks/semaphore/view.py@@ -86,8 +86,10 @@ GITHUB_URL_TEMPLATES = {"user": "https://github.com/{username}",}+ALL_EVENT_TYPES = ["build", "tag", "unknown", "branch", "deploy", "pull_request"]-@webhook_view("Semaphore")++@webhook_view("Semaphore", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_semaphore_webhook(request: HttpRequest,@@ -95,7 +97,7 @@ def api_semaphore_webhook(payload: Dict[str, Any] = REQ(argument_type="body"),) -> HttpResponse:- content, project_name, branch_name = (+ content, project_name, branch_name, event = (semaphore_classic(payload) if "event" in payload else semaphore_2(payload))subject = (@@ -103,11 +105,11 @@ def api_semaphore_webhook(if branch_nameelse project_name)- check_send_webhook_message(request, user_profile, subject, content)+ check_send_webhook_message(request, user_profile, subject, content, event)return json_success()-def semaphore_classic(payload: Dict[str, Any]) -> Tuple[str, str, str]:+def semaphore_classic(payload: Dict[str, Any]) -> Tuple[str, str, str, str]:# semaphore only gives the last commit, even if there were multiple commits# since the last buildbranch_name = payload["branch_name"]@@ -154,10 +156,10 @@ def semaphore_classic(payload: Dict[str, Any]) -> Tuple[str, str, str]:else: # should never get herecontent = f"{event}: {result}"- return content, project_name, branch_name+ return content, project_name, branch_name, event-def semaphore_2(payload: Dict[str, Any]) -> Tuple[str, str, Optional[str]]:+def semaphore_2(payload: Dict[str, Any]) -> Tuple[str, str, Optional[str], str]:repo_url = payload["repository"]["url"]project_name = payload["project"]["name"]organization_name = payload["organization"]["name"]@@ -170,6 +172,7 @@ def semaphore_2(payload: Dict[str, Any]) -> Tuple[str, str, Optional[str]]:pipeline_result=payload["pipeline"]["result"],workflow_url=f"https://{organization_name}.semaphoreci.com/workflows/{workflow_id}",)+ event = payload["revision"]["reference_type"]if payload["revision"]["reference_type"] == "branch": # push eventcommit_id = payload["revision"]["commit_sha"]@@ -215,7 +218,7 @@ def semaphore_2(payload: Dict[str, Any]) -> Tuple[str, str, Optional[str]]:branch_name = ""context.update(event_name=payload["revision"]["reference_type"])content = DEFAULT_TEMPLATE.format(**context)- return content, project_name, branch_name+ return content, project_name, branch_name, eventdef is_github_repo(repo_url: str) -> bool:diff --git a/zerver/webhooks/solano/view.py b/zerver/webhooks/solano/view.pyindex a12342f8e0d..dc4a6080e8b 100644--- a/zerver/webhooks/solano/view.py+++ b/zerver/webhooks/solano/view.py@@ -16,8 +16,10 @@ Build update (see [build log]({build_log_url})):* **Status**: {status} {emoji}""".strip()+ALL_EVENT_TYPES = ["first-fail", "stop", "received"]-@webhook_view("SolanoLabs")++@webhook_view("SolanoLabs", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_solano_webhook(request: HttpRequest,@@ -67,7 +69,7 @@ def api_solano_webhook(emoji=emoji,)- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()diff --git a/zerver/webhooks/sonarr/view.py b/zerver/webhooks/sonarr/view.pyindex 3503f097333..d8e4d3617fa 100644--- a/zerver/webhooks/sonarr/view.py+++ b/zerver/webhooks/sonarr/view.py@@ -28,8 +28,18 @@ SONARR_MESSAGE_TEMPLATE_EPISODE_DELETED = ()SONARR_MESSAGE_TEMPLATE_EPISODE_DELETED_UPGRADE = "{series_title} - {series_number}x{episode_number} - {episode_name} has been deleted due to quality upgrade.".strip()--@webhook_view("Sonarr")+ALL_EVENT_TYPES = [+ "Grab",+ "EpisodeFileDelete",+ "Test",+ "Download",+ "SeriesDelete",+ "Health",+ "Rename",+]+++@webhook_view("Sonarr", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_sonarr_webhook(request: HttpRequest,@@ -39,7 +49,7 @@ def api_sonarr_webhook(body = get_body_for_http_request(payload)subject = get_subject_for_http_request(payload)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, payload["eventType"])return json_success()diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.pyindex e62a737302f..28b4fb285cf 100644--- a/zerver/webhooks/statuspage/view.py+++ b/zerver/webhooks/statuspage/view.py@@ -20,6 +20,8 @@ COMPONENT_TEMPLATE = "**{name}** has changed status from **{old_status}** to **{TOPIC_TEMPLATE = "{name}: {description}"+ALL_EVENT_TYPES = ["incident", "component"]+def get_incident_events_body(payload: Dict[str, Any]) -> str:return INCIDENT_TEMPLATE.format(@@ -51,7 +53,7 @@ def get_component_topic(payload: Dict[str, Any]) -> str:)-@webhook_view("Statuspage")+@webhook_view("Statuspage", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_statuspage_webhook(request: HttpRequest,@@ -60,13 +62,15 @@ def api_statuspage_webhook() -> HttpResponse:if "incident" in payload:+ event = "incident"topic = get_incident_topic(payload)body = get_incident_events_body(payload)elif "component" in payload:+ event = "component"topic = get_component_topic(payload)body = get_components_update_body(payload)else:raise UnsupportedWebhookEventType("unknown-event")- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, event)return json_success()diff --git a/zerver/webhooks/stripe/view.py b/zerver/webhooks/stripe/view.pyindex 0edae1d13a5..3e6f00b92d4 100644--- a/zerver/webhooks/stripe/view.py+++ b/zerver/webhooks/stripe/view.py@@ -21,7 +21,31 @@ class NotImplementedEventType(SuppressedEvent):pass-@webhook_view("Stripe")+ALL_EVENT_TYPES = [+ "charge.dispute.closed",+ "charge.dispute.created",+ "charge.failed",+ "charge.succeeded",+ "charge.succeeded",+ "customer.created",+ "customer.created",+ "customer.deleted",+ "customer.discount.created",+ "customer.subscription.created",+ "customer.subscription.deleted",+ "customer.subscription.trial_will_end",+ "customer.subscription.updated",+ "customer.updated",+ "invoice.created",+ "invoice.updated",+ "invoice.payment_failed",+ "invoiceitem.created",+ "charge.refund.updated",+ "charge.refund.updated",+]+++@webhook_view("Stripe", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_stripe_webhook(request: HttpRequest,@@ -33,7 +57,7 @@ def api_stripe_webhook(topic, body = topic_and_body(payload)except SuppressedEvent: # nocoveragereturn json_success()- check_send_webhook_message(request, user_profile, topic, body)+ check_send_webhook_message(request, user_profile, topic, body, payload["type"])return json_success()diff --git a/zerver/webhooks/transifex/view.py b/zerver/webhooks/transifex/view.pyindex 873328b2719..13048b38918 100644--- a/zerver/webhooks/transifex/view.py+++ b/zerver/webhooks/transifex/view.py@@ -11,8 +11,10 @@ from zerver.lib.validator import check_intfrom zerver.lib.webhooks.common import check_send_webhook_messagefrom zerver.models import UserProfile+All_EVENT_TYPES = ["translated", "review"]-@webhook_view("Transifex", notify_bot_owner_on_invalid_json=False)++@webhook_view("Transifex", notify_bot_owner_on_invalid_json=False, all_event_types=All_EVENT_TYPES)@has_request_variablesdef api_transifex_webhook(request: HttpRequest,@@ -25,10 +27,12 @@ def api_transifex_webhook() -> HttpResponse:subject = f"{project} in {language}"if translated:+ event = "translated"body = f"Resource {resource} fully translated."elif reviewed:+ event = "review"body = f"Resource {resource} fully reviewed."else:raise UnsupportedWebhookEventType("Unknown Event Type")- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, event)return json_success()diff --git a/zerver/webhooks/updown/view.py b/zerver/webhooks/updown/view.pyindex 088ff8c19de..d2d1b28b183 100644--- a/zerver/webhooks/updown/view.py+++ b/zerver/webhooks/updown/view.py@@ -20,7 +20,7 @@ def send_message_for_event(event_type = get_event_type(event)subject = TOPIC_TEMPLATE.format(service_url=event["check"]["url"])body = EVENT_TYPE_BODY_MAPPER[event_type](event)- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, event_type)def get_body_for_up_event(event: Dict[str, Any]) -> str:@@ -62,7 +62,14 @@ def get_body_for_down_event(event: Dict[str, Any]) -> str:)-@webhook_view("Updown")+EVENT_TYPE_BODY_MAPPER = {+ "up": get_body_for_up_event,+ "down": get_body_for_down_event,+}+ALL_EVENT_TYPES = list(EVENT_TYPE_BODY_MAPPER.keys())+++@webhook_view("Updown", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_updown_webhook(request: HttpRequest,@@ -74,12 +81,6 @@ def api_updown_webhook(return json_success()-EVENT_TYPE_BODY_MAPPER = {- "up": get_body_for_up_event,- "down": get_body_for_down_event,-}--def get_event_type(event: Dict[str, Any]) -> str:event_type_match = re.match("check.(.*)", event["event"])if event_type_match:diff --git a/zerver/webhooks/uptimerobot/view.py b/zerver/webhooks/uptimerobot/view.pyindex 14655048c63..020787d2dd1 100644--- a/zerver/webhooks/uptimerobot/view.py+++ b/zerver/webhooks/uptimerobot/view.py@@ -28,15 +28,20 @@ It was down for {alert_friendly_duration}.UPTIMEROBOT_MESSAGE_DOWN_TEMPLATE = ("{monitor_friendly_name} ({monitor_url}) is DOWN ({alert_details}).")+ALL_EVENT_TYPES = ["up", "down"]-@webhook_view("UptimeRobot")+@webhook_view("UptimeRobot", all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_uptimerobot_webhook(request: HttpRequest,user_profile: UserProfile,payload: Dict[str, Any] = REQ(argument_type="body"),) -> HttpResponse:+ if payload["alert_type_friendly_name"] == "Up":+ event = "up"+ elif payload["alert_type_friendly_name"] == "Down":+ event = "down"try:body = get_body_for_http_request(payload)@@ -50,7 +55,7 @@ def api_uptimerobot_webhook(raise JsonableError(_("Invalid payload"))- check_send_webhook_message(request, user_profile, subject, body)+ check_send_webhook_message(request, user_profile, subject, body, event)return json_success()diff --git a/zerver/webhooks/wordpress/view.py b/zerver/webhooks/wordpress/view.pyindex 09496d89681..d5d3e1b7447 100644--- a/zerver/webhooks/wordpress/view.py+++ b/zerver/webhooks/wordpress/view.py@@ -19,9 +19,15 @@ New blog user registered:* **Email**: {email}""".strip()WP_LOGIN_TEMPLATE = "User {name} logged in."+ALL_EVENT_TYPES = [+ "publish_post",+ "publish_page",+ "user_register",+ "wp_login",+]-@webhook_view("WordPress", notify_bot_owner_on_invalid_json=False)+@webhook_view("WordPress", notify_bot_owner_on_invalid_json=False, all_event_types=ALL_EVENT_TYPES)@has_request_variablesdef api_wordpress_webhook(request: HttpRequest,@@ -51,5 +57,5 @@ def api_wordpress_webhook(topic = "WordPress notification"- check_send_webhook_message(request, user_profile, topic, data)+ check_send_webhook_message(request, user_profile, topic, data, hook)return json_success()