Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
integrations: Create incoming webhook for Airbyte. Note about the documentation: There are currently two "Save changes" buttons on the Airbyte "Notifications" settings page, so the instructions specify which one to use for clarity.
aniebietafia257ce8bca22d
diff --git a/static/images/integrations/airbyte/001.png b/static/images/integrations/airbyte/001.pngnew file mode 100644index 00000000000..f90bf6e885cBinary files /dev/null and b/static/images/integrations/airbyte/001.png differdiff --git a/static/images/integrations/bot_avatars/airbyte.png b/static/images/integrations/bot_avatars/airbyte.pngnew file mode 100644index 00000000000..1c563d017daBinary files /dev/null and b/static/images/integrations/bot_avatars/airbyte.png differdiff --git a/static/images/integrations/logos/airbyte.svg b/static/images/integrations/logos/airbyte.svgnew file mode 100644index 00000000000..b81818d5770--- /dev/null+++ b/static/images/integrations/logos/airbyte.svg@@ -0,0 +1 @@+<svg xmlns="http://www.w3.org/2000/svg" width="866" height="650" viewBox="0 0 2048 1537"><path fill="#FEFFFF" d="M0 0h2048v1537H0z"/><path fill="#4A5BA7" d="M1146 212h21l28 2 30 4 28 6 31 9 26 10 24 11 25 13 22 14 17 12 16 13 11 9 16 15 12 12 7 8 11 13 12 16 16 24 11 19 13 25 8 19 10 28 7 25 5 22 5 35 1 15v54l-3 28-5 28-7 27-11 33-14 32-10 19-10 17-14 24-15 26-17 29-15 26-13 22-12 21-14 24-17 29-28 48-15 26-10 17-15 26-16 27-13 23-9 15-14 24-15 26-12 19-11 12-5 5-11 9-17 9-14 5-18 4-9 1h-9l-16-2-21-6-14-7 2-5 16-28 10-17 15-26 17-29 11-19 14-24 15-26 13-22 12-21 9-15 11-19 14-24 30-52 12-20 13-23 13-22 42-72 12-21 17-29 16-27 12-22 10-21 9-25 8-32 4-31v-43l-3-27-5-24-8-27-8-20-8-17-14-24-12-17-11-14-16-17-10-10-11-9-14-11-15-10-21-12-23-11-25-9-17-5-26-5-26-3h-35l-24 2-28 5-26 7-21 8-20 9-22 12-19 13-10 8-13 11-12 11-14 15-12 15-18 27-14 27-8 19-8 24-6 27-3 20-1 11v40l3 26 6 29 7 23 10 24 8 16 8 15 11 16 13 17 10 11 7 8 13 13-2 5-13 23-6 10-12 21-34 58-13 23-20 34-11 19-15 26-10 17-15 26-28 48-10 17-8 10-9 10-14 11-12 7-18 7-12 3-7 1h-28l-21-5-16-7-4-3 14-25 12-20 30-52 9-15 12-21 28-48 15-26 9-15 16-28 11-19 13-22 12-21 14-24 6-10-1-5-8-11-15-26-14-29-11-28-9-29-2-8-2-1-2 6-15 26-16 27-15 26-12 21-15 26-10 17-11 19-9 15-16 28-9 13-9 10-7 7-16 11-15 7-11 4-14 3-9 1h-14l-19-3-16-5-13-6 1-5 16-28 15-25 14-25 10-17 13-22 15-26 16-27 16-28 14-24 17-29 16-28 14-24 11-19 9-15 16-28 14-24 17-29 15-26 10-17 15-26 17-29 12-21 12-20 8-12 12-17 8-10 9-11 9-10 12-13 15-14 14-12 17-13 17-12 15-9 18-10 16-8 23-10 28-10 29-8 31-6 34-4z"/><path fill="#4A5BA7" d="M1130 501h20l21 3 19 5 20 8 18 10 16 12 12 11 11 12 12 18 9 17 7 19 5 23 1 7v33l-3 18-6 21-8 18-14 24-12 21-16 27-8 14-14 24-15 26-17 29-28 48-10 17-15 26-10 17-14 24-17 29-15 26-42 72-10 17-15 26-14 24-13 22-15 26-10 13-11 11-16 11-14 7-19 6-19 3h-9l-21-3-16-5-14-7 2-6 12-21 10-17 13-22 12-21 16-27 16-28 28-48 15-26 14-24 15-26 13-22 15-26 11-19 14-24 15-26 13-22 15-26 16-27 16-28 3-6-11-2-20-7-19-10-17-12-12-11-11-11-12-16-10-18-8-20-5-18-3-22v-19l3-22 5-19 6-15 8-16 10-15 9-11 14-14 17-13 17-10 19-8 22-6z"/><path fill="#FEFFFF" d="M1132 612h15l11 3 10 5 11 10 6 9 5 15v16l-4 13-6 10-10 10-14 7-7 2h-19l-10-3-11-6-7-6-7-10-4-9-2-8v-16l4-13 7-11 8-8 10-6z"/></svg>\ No newline at end of filediff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex 6c94734bb45..a8274eb413a 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -343,6 +343,7 @@ EMBEDDED_BOTS: list[EmbeddedBotIntegration] = [WEBHOOK_INTEGRATIONS: list[WebhookIntegration] = [WebhookIntegration("airbrake", ["monitoring"]),+ WebhookIntegration("airbyte", ["monitoring"]),WebhookIntegration("alertmanager",["monitoring"],@@ -712,6 +713,7 @@ NO_SCREENSHOT_WEBHOOKS = {DOC_SCREENSHOT_CONFIG: dict[str, list[BaseScreenshotConfig]] = {"airbrake": [ScreenshotConfig("error_message.json")],+ "airbyte": [ScreenshotConfig("airbyte_job_payload_success.json")],"alertmanager": [ScreenshotConfig("alert.json", extra_params={"name": "topic", "desc": "description"})],diff --git a/zerver/webhooks/airbyte/__init__.py b/zerver/webhooks/airbyte/__init__.pynew file mode 100644index 00000000000..e69de29bb2ddiff --git a/zerver/webhooks/airbyte/doc.md b/zerver/webhooks/airbyte/doc.mdnew file mode 100644index 00000000000..488384a0358--- /dev/null+++ b/zerver/webhooks/airbyte/doc.md@@ -0,0 +1,28 @@+# Zulip Airbyte integration++Get Zulip notifications from Airbyte.++{start_tabs}++1. {!create-channel.md!}++1. {!create-an-incoming-webhook.md!}++1. {!generate-webhook-url-basic.md!}++1. In Airbyte, go to your project settings. Click **Notifications**,+ and toggle the **Webhook** button for the notifications you'd like+ to receive.++1. Enter the URL generated above in the **Webhook URL** field. Click the+ **Save changes** button at the bottom of the page.++{end_tabs}++{!congrats.md!}++++### Related documentation++{!webhooks-url-specification.md!}diff --git a/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_failure.json b/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_failure.jsonnew file mode 100644index 00000000000..bb8a76f9d7b--- /dev/null+++ b/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_failure.json@@ -0,0 +1,83 @@+{+ "text": "Your connection Google Sheets → Postgres from Google Sheets to Postgres failed\nThis happened with Checking source connection failed - please review this connection's configuration to prevent future syncs from failing\n\nYou can access its logs here: https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720\n\nJob ID: 20441143",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "Sync completed: <https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720|Google Sheets \u2192 Postgres>"+ }+ },+ {+ "type": "section",+ "fields": [+ {+ "type": "mrkdwn",+ "text": "*Source:*"+ },+ {+ "type": "mrkdwn",+ "text": "<https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621|Google Sheets>"+ },+ {+ "type": "mrkdwn",+ "text": "*Destination:*"+ },+ {+ "type": "mrkdwn",+ "text": "<https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6|Postgres>"+ },+ {+ "type": "mrkdwn",+ "text": "*Duration:*"+ },+ {+ "type": "mrkdwn",+ "text": "1 min 23 sec"+ }+ ]+ },+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "*Sync Summary:*\n1400 record(s) extracted / 1400 record(s) loaded\n281 kB extracted / 281 kB loaded\n"+ }+ }+ ],+ "data": {+ "workspace": {+ "id": "84d2dd6e-82aa-406e-91f3-bf8dbf176e69",+ "name": "Zulip Airbyte Integration",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69"+ },+ "connection": {+ "id": "aa941643-07ea-48a2-9035-024575491720",+ "name": "Google Sheets → Postgres",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720"+ },+ "source": {+ "id": "363c0ea3-e989-4051-9f54-d41b794d6621",+ "name": "Google Sheets",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621"+ },+ "destination": {+ "id": "b3a05072-e3c8-435a-8e6e-4a5c601039c6",+ "name": "Postgres",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6"+ },+ "jobId": 20441143,+ "startedAt": "2024-10-22T20:27:59Z",+ "finishedAt": "2024-10-22T20:29:22Z",+ "bytesEmitted": 0,+ "bytesCommitted": 0,+ "recordsEmitted": 0,+ "recordsCommitted": 0,+ "errorMessage": "Checking source connection failed - please review this connection's configuration to prevent future syncs from failing",+ "durationFormatted": "28 sec",+ "bytesEmittedFormatted": "0 B",+ "bytesCommittedFormatted": "0 B",+ "success": false,+ "durationInSeconds": 28+ }+}diff --git a/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_success.json b/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_success.jsonnew file mode 100644index 00000000000..d573f8b63d2--- /dev/null+++ b/zerver/webhooks/airbyte/fixtures/airbyte_job_payload_success.json@@ -0,0 +1,83 @@+{+ "text": "Your connection Google Sheets → Postgres from Google Sheets to Postgres succeeded\nThis was for null\n\nYou can access its logs here: https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720\n\nJob ID: 20441143",+ "blocks": [+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "Sync completed: <https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720|Google Sheets \u2192 Postgres>"+ }+ },+ {+ "type": "section",+ "fields": [+ {+ "type": "mrkdwn",+ "text": "*Source:*"+ },+ {+ "type": "mrkdwn",+ "text": "<https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621|Google Sheets>"+ },+ {+ "type": "mrkdwn",+ "text": "*Destination:*"+ },+ {+ "type": "mrkdwn",+ "text": "<https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6|Postgres>"+ },+ {+ "type": "mrkdwn",+ "text": "*Duration:*"+ },+ {+ "type": "mrkdwn",+ "text": "1 min 23 sec"+ }+ ]+ },+ {+ "type": "section",+ "text": {+ "type": "mrkdwn",+ "text": "*Sync Summary:*\n1400 record(s) extracted / 1400 record(s) loaded\n281 kB extracted / 281 kB loaded\n"+ }+ }+ ],+ "data": {+ "workspace": {+ "id": "84d2dd6e-82aa-406e-91f3-bf8dbf176e69",+ "name": "Zulip Airbyte Integration",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69"+ },+ "connection": {+ "id": "aa941643-07ea-48a2-9035-024575491720",+ "name": "Google Sheets → Postgres",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720"+ },+ "source": {+ "id": "363c0ea3-e989-4051-9f54-d41b794d6621",+ "name": "Google Sheets",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621"+ },+ "destination": {+ "id": "b3a05072-e3c8-435a-8e6e-4a5c601039c6",+ "name": "Postgres",+ "url": "https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6"+ },+ "jobId": 20441143,+ "startedAt": "2024-10-22T20:27:59Z",+ "finishedAt": "2024-10-22T20:29:22Z",+ "bytesEmitted": 288179,+ "bytesCommitted": 288179,+ "recordsEmitted": 1400,+ "recordsCommitted": 1400,+ "errorMessage": null,+ "durationFormatted": "1 min 23 sec",+ "bytesEmittedFormatted": "281 kB",+ "bytesCommittedFormatted": "281 kB",+ "success": true,+ "durationInSeconds": 83+ }+}diff --git a/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_failure.json b/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_failure.jsonnew file mode 100644index 00000000000..5df5ad4aedd--- /dev/null+++ b/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_failure.json@@ -0,0 +1,3 @@+{+ "text": "Hello World! This is a test from Airbyte to try slack notification settings for sync failures."+}diff --git a/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_success.json b/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_success.jsonnew file mode 100644index 00000000000..1323fd41c0f--- /dev/null+++ b/zerver/webhooks/airbyte/fixtures/test_airbyte_job_hello_world_success.json@@ -0,0 +1,4 @@+{+ "text": "Hello World! This is a test from Airbyte to try slack notification settings for sync successes."+}+diff --git a/zerver/webhooks/airbyte/tests.py b/zerver/webhooks/airbyte/tests.pynew file mode 100644index 00000000000..1a997bc292c--- /dev/null+++ b/zerver/webhooks/airbyte/tests.py@@ -0,0 +1,70 @@+from zerver.lib.test_classes import WebhookTestCase+++class AirbyteHookTests(WebhookTestCase):+ STREAM_NAME = "airbyte"+ URL_TEMPLATE = "/api/v1/external/airbyte?api_key={api_key}&stream={stream}"+ FIXTURE_DIR_NAME = "airbyte"+ CHANNEL_NAME = "test"+ WEBHOOK_DIR_NAME = "airbyte"++ def test_airbyte_job_success(self) -> None:+ expected_topic = "Zulip Airbyte Integration - Google Sheets → Postgres"++ expected_message = """:green_circle: Airbyte sync **succeeded** for [Google Sheets → Postgres](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720).+++* **Source:** [Google Sheets](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621)+* **Destination:** [Postgres](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6)+* **Records:** 1400 emitted, 1400 committed+* **Bytes:** 281 kB emitted, 281 kB committed+* **Duration:** 1 min 23 sec"""++ self.check_webhook(+ "airbyte_job_payload_success",+ expected_topic,+ expected_message,+ content_type="application/json",+ )++ def test_airbyte_job_failure(self) -> None:+ expected_topic = "Zulip Airbyte Integration - Google Sheets → Postgres"+ expected_message = """:red_circle: Airbyte sync **failed** for [Google Sheets → Postgres](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/connections/aa941643-07ea-48a2-9035-024575491720).+++* **Source:** [Google Sheets](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/source/363c0ea3-e989-4051-9f54-d41b794d6621)+* **Destination:** [Postgres](https://cloud.airbyte.com/workspaces/84d2dd6e-82aa-406e-91f3-bf8dbf176e69/destination/b3a05072-e3c8-435a-8e6e-4a5c601039c6)+* **Records:** 0 emitted, 0 committed+* **Bytes:** 0 B emitted, 0 B committed+* **Duration:** 28 sec++**Error message:** Checking source connection failed - please review this connection's configuration to prevent future syncs from failing"""++ self.check_webhook(+ "airbyte_job_payload_failure",+ expected_topic,+ expected_message,+ content_type="application/json",+ )++ def test_airbyte_job_hello_world_success(self) -> None:+ expected_topic = "Airbyte notification"+ expected_message = """Hello World! This is a test from Airbyte to try slack notification settings for sync successes."""++ self.check_webhook(+ "test_airbyte_job_hello_world_success",+ expected_topic,+ expected_message,+ content_type="application/json",+ )++ def test_airbyte_job_hello_world_failure(self) -> None:+ expected_topic = "Airbyte notification"+ expected_message = """Hello World! This is a test from Airbyte to try slack notification settings for sync failures."""++ self.check_webhook(+ "test_airbyte_job_hello_world_failure",+ expected_topic,+ expected_message,+ content_type="application/json",+ )diff --git a/zerver/webhooks/airbyte/view.py b/zerver/webhooks/airbyte/view.pynew file mode 100644index 00000000000..f422d0b1446--- /dev/null+++ b/zerver/webhooks/airbyte/view.py@@ -0,0 +1,97 @@+# Webhooks for external integrations.++from django.http import HttpRequest, HttpResponse++from zerver.decorator import webhook_view+from zerver.lib.response import json_success+from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint+from zerver.lib.validator import WildValue, check_bool, check_int, check_string+from zerver.lib.webhooks.common import check_send_webhook_message+from zerver.models import UserProfile++AIRBYTE_TOPIC_TEMPLATE = "{workspace} - {connection}"++AIRBYTE_MESSAGE_TEMPLATE = """\+{sync_status_emoji} Airbyte sync **{status}** for [{connection_name}]({connection_url}).+++* **Source:** [{source_name}]({source_url})+* **Destination:** [{destination_name}]({destination_url})+* **Records:** {records_emitted} emitted, {records_committed} committed+* **Bytes:** {bytes_emitted} emitted, {bytes_committed} committed+* **Duration:** {duration}+"""+++def extract_data_from_payload(payload_data: WildValue) -> dict[str, str | int | bool]:+ data: dict[str, str | int | bool] = {+ "workspace_name": payload_data["workspace"]["name"].tame(check_string),+ "connection_name": payload_data["connection"]["name"].tame(check_string),+ "source_name": payload_data["source"]["name"].tame(check_string),+ "destination_name": payload_data["destination"]["name"].tame(check_string),+ "connection_url": payload_data["connection"]["url"].tame(check_string),+ "source_url": payload_data["source"]["url"].tame(check_string),+ "destination_url": payload_data["destination"]["url"].tame(check_string),+ "successful_sync": payload_data["success"].tame(check_bool),+ "duration_formatted": payload_data["durationFormatted"].tame(check_string),+ "records_emitted": payload_data["recordsEmitted"].tame(check_int),+ "records_committed": payload_data["recordsCommitted"].tame(check_int),+ "bytes_emitted_formatted": payload_data["bytesEmittedFormatted"].tame(check_string),+ "bytes_committed_formatted": payload_data["bytesCommittedFormatted"].tame(check_string),+ }++ if not data["successful_sync"]:+ data["error_message"] = payload_data["errorMessage"].tame(check_string)++ return data+++def format_message_from_data(data: dict[str, str | int | bool]) -> str:+ content = AIRBYTE_MESSAGE_TEMPLATE.format(+ sync_status_emoji=":green_circle:" if data["successful_sync"] else ":red_circle:",+ status="succeeded" if data["successful_sync"] else "failed",+ connection_name=data["connection_name"],+ connection_url=data["connection_url"],+ source_name=data["source_name"],+ source_url=data["source_url"],+ destination_name=data["destination_name"],+ destination_url=data["destination_url"],+ duration=data["duration_formatted"],+ records_emitted=data["records_emitted"],+ records_committed=data["records_committed"],+ bytes_emitted=data["bytes_emitted_formatted"],+ bytes_committed=data["bytes_committed_formatted"],+ )++ if not data["successful_sync"]:+ error_message = data["error_message"]+ content += f"\n**Error message:** {error_message}"++ return content+++def create_topic_from_data(data: dict[str, str | int | bool]) -> str:+ return AIRBYTE_TOPIC_TEMPLATE.format(+ workspace=data["workspace_name"],+ connection=data["connection_name"],+ )+++@webhook_view("Airbyte")+@typed_endpoint+def api_airbyte_webhook(+ request: HttpRequest,+ user_profile: UserProfile,+ *,+ payload: JsonBodyPayload[WildValue],+) -> HttpResponse:+ if "data" in payload:+ data = extract_data_from_payload(payload["data"])+ content = format_message_from_data(data)+ topic = create_topic_from_data(data)+ else:+ # Test Airbyte notification payloads only contain this field.+ content = payload["text"].tame(check_string)+ topic = "Airbyte notification"+ check_send_webhook_message(request, user_profile, topic, content)+ return json_success(request)