Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/docs: Document how integrations support event filtering.
Niloth P6bef8cb6bdc0
diff --git a/docs/documentation/integrations.md b/docs/documentation/integrations.mdindex 094b1e01bde..c53a0a814df 100644--- a/docs/documentation/integrations.md+++ b/docs/documentation/integrations.md@@ -130,11 +130,11 @@ Here are a few common macros used to document Zulip's integrations:[the docs for Zulip's GitHub integration][github-integration].- `{!event-filtering-additional-feature.md!}` macro - If a webhook integration- supports event filtering, then this adds a section with the specific- events that can be filtered for the integration. Should be included in- the documentation if `all_event_types` is set in the webhook integration- view. For an example see, the **Filtering incoming events** section in- [Zulip's GitLab integration][gitlab].+ supports [event filtering][event-filtering], then this adds a section with+ the specific events that can be filtered for the integration. Should be+ included in the documentation if `all_event_types` is set in the webhook+ integration view. For an example see, the **Filtering incoming events**+ section in [Zulip's GitLab integration][gitlab].- `{!download-python-bindings.md!}` macro - Links to Zulip's[API page](https://zulip.com/api/) to download and install Zulip's@@ -167,6 +167,7 @@ Here are a few common macros used to document Zulip's integrations:[beanstalk]: https://zulip.com/integrations/beanstalk[front]: https://zulip.com/integrations/front[gitlab]: https://zulip.com/integrations/gitlab+[event-filtering]: ../webhooks/incoming-webhooks-reference.md#event-filtering[integrations-file]: https://github.com/zulip/zulip/blob/main/zerver/lib/integrations.py## Writing guidelinesdiff --git a/docs/webhooks/incoming-webhooks-reference.md b/docs/webhooks/incoming-webhooks-reference.mdindex 32931e9701c..58c5382977a 100644--- a/docs/webhooks/incoming-webhooks-reference.md+++ b/docs/webhooks/incoming-webhooks-reference.md@@ -245,6 +245,32 @@ needs to be constructed in an unusual way.For more, see the definition for the base class, `WebhookTestCase`in `zerver/lib/test_classes.py`, or just grep for examples.+## Event filtering++Users can choose which events trigger notifications with the+[`only_events` and `exclude_events` URL+parameters](incoming-webhooks-overview.md#only_events-exclude_events).+To support them in an integration:++- Register its event types in `view.py`, with+ `@webhook_view(..., all_event_types=ALL_EVENT_TYPES)`. The web app+ offers these when [generating the integration+ URL](https://zulip.com/help/generate-integration-url).+- Pass the event type of each message to `check_send_webhook_message`,+ as `complete_event_type`. For a message that should ignore filters,+ such as a warning about a misconfigured payload, pass+ `complete_event_type=None` explicitly.+- List the event types in `doc.md`, with the+ `{!event-filtering-additional-feature.md!}` macro.++Event type names end up in users' webhook URLs, so renaming one breaks+existing filters. Hierarchical names like `git.pullrequest.created` let+users select related events with a wildcard, like `git.pullrequest.*`.++`WebhookTestCase` fails a test if an integration that registers event+types sends a message without `complete_event_type`, or with an+unregistered event type.+## Negative testsA negative test is one that should result in an error, such as incorrectdiff --git a/docs/webhooks/incoming-webhooks-walkthrough.md b/docs/webhooks/incoming-webhooks-walkthrough.mdindex 570d0d23b9a..2fca5986818 100644--- a/docs/webhooks/incoming-webhooks-walkthrough.md+++ b/docs/webhooks/incoming-webhooks-walkthrough.md@@ -215,6 +215,10 @@ will validate the message and do the following:- Send a direct message to the owner of the webhook bot if the `stream`query parameter isn't specified.+If the third-party service sends several types of events, also pass the+event type of each message, so that users can [filter which events+trigger notifications](incoming-webhooks-reference.md#event-filtering).+Finally, a response is sent with a 200 HTTP status with a JSON formatsuccess message via `json_success(request)`.