Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/gong: Add include_participant_contacts URL option.
sathwikshetty3326a7c540c336
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex d85e5318daf..5c9d2fcb7d1 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -733,6 +733,11 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [label="Include participant names in the notifications",input_type="checkbox_enabled",),+ WebhookUrlOption(+ "include_participant_contacts",+ label="Include participant contact information (requires participant names)",+ input_type="checkbox_enabled",+ ),],),IncomingWebhookIntegration(diff --git a/zerver/webhooks/gong/tests.py b/zerver/webhooks/gong/tests.pyindex 7124e84d067..05358bbb7d1 100644--- a/zerver/webhooks/gong/tests.py+++ b/zerver/webhooks/gong/tests.py@@ -159,6 +159,33 @@ class GongHookTests(WebhookTestCase):content_type="application/json",)+ def test_call_with_participant_contacts_disabled(self) -> None:+ self.url = self.build_webhook_url(include_participant_contacts="false")+ intro = self.MESSAGE_INTRO.format(title=self.CALL_TITLE)+ participants = (+ "**Participants**:\n"+ f"* {BO_NAME}: Sales Enablement Manager - Sales Development\n"+ f"* {KEVIN_NAME}: Customer Success Manager"+ )+ self.check_webhook(+ "call_completed",+ self.EXPECTED_TOPIC,+ f"{intro}\n\n{participants}\n\n{self.TRACKERS_SECTION}\n\n{self.TOPICS_SECTION}",+ content_type="application/json",+ )++ def test_call_with_participants_off_but_contacts_on(self) -> None:+ self.url = self.build_webhook_url(+ include_participants="false", include_participant_contacts="true"+ )+ intro = self.MESSAGE_INTRO.format(title=self.CALL_TITLE)+ self.check_webhook(+ "call_completed",+ self.EXPECTED_TOPIC,+ f"{intro}\n\n{self.TRACKERS_SECTION}\n\n{self.TOPICS_SECTION}",+ content_type="application/json",+ )+def test_get_participants(self) -> None:name = KEVIN_NAMEtitle = "Customer Success Manager"@@ -219,7 +246,24 @@ class GongHookTests(WebhookTestCase):for parties, expected_output in test_cases:with self.subTest(parties=parties):payload = wrap_wild_value("parties", parties)- self.assertEqual(get_participants(payload), expected_output)+ self.assertEqual(get_participants(payload, True), expected_output)++ no_contacts_cases = [+ ([{"name": name, "title": title, "emailAddress": email}], f"* {name}: {title}"),+ ([{"name": name, "emailAddress": email, "phoneNumber": phone}], f"* {name}"),+ (+ [{"name": "Alice"}, {"emailAddress": email}, {"phoneNumber": phone}],+ "* Alice\n* and 2 more participants",+ ),+ ([{"title": title, "emailAddress": email}], "* 1 participant"),+ ]+ for parties, expected_output in no_contacts_cases:+ with self.subTest(parties=parties, include_participant_contacts=False):+ payload = wrap_wild_value("parties", parties)+ self.assertEqual(+ get_participants(payload, False),+ expected_output,+ )def test_get_trackers(self) -> None:payload = wrap_wild_value(diff --git a/zerver/webhooks/gong/view.py b/zerver/webhooks/gong/view.pyindex 6f8579fbf78..63733028d82 100644--- a/zerver/webhooks/gong/view.py+++ b/zerver/webhooks/gong/view.py@@ -32,11 +32,13 @@ class Helper:include_trackers: bool,include_topics: bool,include_participants: bool,+ include_participant_contacts: bool,) -> None:self.payload = payloadself.include_trackers = include_trackersself.include_topics = include_topicsself.include_participants = include_participants+ self.include_participant_contacts = include_participant_contactsdef format_duration_to_string(duration: int) -> str:@@ -54,7 +56,7 @@ def format_duration_to_string(duration: int) -> str:return f"{minutes} {minute_word}"-def get_participants(parties_payload: WildValue) -> str:+def get_participants(parties_payload: WildValue, include_participant_contacts: bool) -> str:# Gong may omit a party's name, email, and phone for unidentified callers# (https://help.gong.io/docs/uploading-calls-from-a-non-integrated-telephony-system).labels: list[str] = []@@ -63,11 +65,16 @@ def get_participants(parties_payload: WildValue) -> str:if len(labels) == PARTICIPANTS_LIMIT:breakname = party.get("name")- contact_parts = [- party[key].tame(check_string)- for key in ("emailAddress", "phoneNumber")- if party.get(key)- ]+ contact_parts = (+ [+ party[key].tame(check_string)+ for key in ("emailAddress", "phoneNumber")+ if party.get(key)+ ]+ if include_participant_contacts+ else []+ )+label = name.tame(check_string) if name else (contact_parts[0] if contact_parts else None)if label is None:unidentified += 1@@ -163,7 +170,9 @@ def handle_call_processed_message(helper: Helper) -> tuple[str, str]:time=datetime_to_global_time(meta_data["started"].tame(check_iso_datetime)),duration=format_duration_to_string(meta_data["duration"].tame(check_int)),)- if helper.include_participants and (participants := get_participants(call_data["parties"])):+ if helper.include_participants and (+ participants := get_participants(call_data["parties"], helper.include_participant_contacts)+ ):body += "\n\n" + SECTION_TEMPLATE.format(heading="Participants", body=participants)if content := call_data.get("content"):@@ -194,8 +203,15 @@ def api_gong_webhook(include_trackers: Json[bool] = True,include_topics: Json[bool] = True,include_participants: Json[bool] = True,+ include_participant_contacts: Json[bool] = True,) -> HttpResponse:- helper = Helper(payload, include_trackers, include_topics, include_participants)+ helper = Helper(+ payload,+ include_trackers,+ include_topics,+ include_participants,+ include_participant_contacts,+ )if payload.get("isTest").tame(check_bool):topic, body = handle_test_message(helper)else: