Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/gong: Add include_trackers URL option.
sathwikshetty33d0c040ac8a03
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex 8ed079cea21..73b75ab34de 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -717,6 +717,13 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = ["gong",["customer-support", "marketing"],[WebhookScreenshotConfig("call_completed.json")],+ url_options=[+ WebhookUrlOption(+ "include_trackers",+ label="Include primary trackers in the notifications",+ input_type="checkbox_enabled",+ )+ ],),IncomingWebhookIntegration("gosquared",diff --git a/zerver/webhooks/gong/tests.py b/zerver/webhooks/gong/tests.pyindex e62e00954d5..a7ef2fa5d9e 100644--- a/zerver/webhooks/gong/tests.py+++ b/zerver/webhooks/gong/tests.py@@ -129,6 +129,16 @@ class GongHookTests(WebhookTestCase):content=f"{intro}\n\n{self.PARTICIPANTS_SECTION}\n\n{self.TRACKERS_SECTION}",)+ def test_call_with_top_trackers_disabled(self) -> None:+ self.url = self.build_webhook_url(include_trackers="false")+ intro = self.MESSAGE_INTRO.format(title=self.CALL_TITLE)+ self.check_webhook(+ "call_completed",+ self.EXPECTED_TOPIC,+ f"{intro}\n\n{self.PARTICIPANTS_SECTION}\n\n{self.TOPICS_SECTION}",+ content_type="application/json",+ )+def test_get_participants(self) -> None:name = KEVIN_NAMEtitle = "Customer Success Manager"diff --git a/zerver/webhooks/gong/view.py b/zerver/webhooks/gong/view.pyindex ef3c73dfe90..548b7b8c3bc 100644--- a/zerver/webhooks/gong/view.py+++ b/zerver/webhooks/gong/view.py@@ -1,4 +1,5 @@from django.http import HttpRequest, HttpResponse+from pydantic import Jsonfrom zerver.decorator import webhook_viewfrom zerver.lib.response import json_success@@ -24,6 +25,12 @@ TOP_CONTENT_LIMIT = 3PARTICIPANTS_LIMIT = 5+class Helper:+ def __init__(self, payload: WildValue, include_trackers: bool) -> None:+ self.payload = payload+ self.include_trackers = include_trackers++def format_duration_to_string(duration: int) -> str:# The duration value is in seconds.if duration < 60:@@ -121,18 +128,18 @@ def get_topics(topics_payload: WildValue) -> str:return topics_line + "." if topics_line else ""-def handle_test_message(payload: WildValue) -> tuple[str, str]:+def handle_test_message(helper: Helper) -> tuple[str, str]:# Gong's "Test now" sends a real, already-processed call, so render the# actual message and prefix it with the standard setup confirmation.- _, body = handle_call_processed_message(payload)+ _, body = handle_call_processed_message(helper)return ("Gong Test",f"{get_setup_webhook_message('Gong')}\n\n{body}",)-def handle_call_processed_message(payload: WildValue) -> tuple[str, str]:- call_data = payload["callData"]+def handle_call_processed_message(helper: Helper) -> tuple[str, str]:+ call_data = helper.payload["callData"]meta_data = call_data["metaData"]# call_title can be an optional field and can be omitted if not present.call_title = meta_data.get("title").tame(check_none_or(check_string))@@ -153,7 +160,11 @@ def handle_call_processed_message(payload: WildValue) -> tuple[str, str]:body += "\n\n" + SECTION_TEMPLATE.format(heading="Participants", body=participants)if content := call_data.get("content"):- if "trackers" in content and (top_trackers := get_trackers(content["trackers"])):+ if (+ helper.include_trackers+ and "trackers" in content+ and (top_trackers := get_trackers(content["trackers"]))+ ):body += "\n\n" + SECTION_TEMPLATE.format(heading="Top Trackers (by count)", body=top_trackers)@@ -169,10 +180,12 @@ def api_gong_webhook(user_profile: UserProfile,*,payload: JsonBodyPayload[WildValue],+ include_trackers: Json[bool] = True,) -> HttpResponse:+ helper = Helper(payload, include_trackers)if payload.get("isTest").tame(check_bool):- topic, body = handle_test_message(payload)+ topic, body = handle_test_message(helper)else:- topic, body = handle_call_processed_message(payload)+ topic, body = handle_call_processed_message(helper)check_send_webhook_message(request, user_profile, topic, body)return json_success(request)