Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/gong: Add include_public_comments URL option.
sathwikshetty334b8e77357510
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex 5c9d2fcb7d1..4e3a4d2c10c 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -738,6 +738,11 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [label="Include participant contact information (requires participant names)",input_type="checkbox_enabled",),+ WebhookUrlOption(+ "include_public_comments",+ label="Include public comments in the notifications",+ input_type="checkbox",+ ),],),IncomingWebhookIntegration(diff --git a/zerver/webhooks/gong/tests.py b/zerver/webhooks/gong/tests.pyindex 05358bbb7d1..325dfc77e8d 100644--- a/zerver/webhooks/gong/tests.py+++ b/zerver/webhooks/gong/tests.py@@ -6,6 +6,7 @@ from zerver.webhooks.fixtureless_integrations import BO_EMAIL, BO_NAME, KEVIN_EMfrom zerver.webhooks.gong.view import (format_duration_to_string,get_participants,+ get_public_comments,get_topics,get_trackers,)@@ -186,6 +187,18 @@ class GongHookTests(WebhookTestCase):content_type="application/json",)+ def test_call_with_public_comments_enabled(self) -> None:+ self.url = self.build_webhook_url(include_public_comments="true")+ comments = (+ "**Comments**:\n* Might be helpful to loop us in on Outreach issue with Outreach team"+ )+ self.check_webhook(+ "call_completed",+ self.EXPECTED_TOPIC,+ f"{self.EXPECTED_CALL_MESSAGE.format(title=self.CALL_TITLE)}\n\n{comments}",+ content_type="application/json",+ )+def test_get_participants(self) -> None:name = KEVIN_NAMEtitle = "Customer Success Manager"@@ -312,6 +325,23 @@ class GongHookTests(WebhookTestCase):self.assertEqual(get_topics(wrap_wild_value("topics", [])), "")+ def test_get_public_comments(self) -> None:+ payload = wrap_wild_value(+ "publicComments",+ [+ {"comment": "Third", "posted": "2019-10-19T03:00:00+00:00"},+ {"comment": "First", "posted": "2019-10-19T01:00:00+00:00"},+ {"comment": "Second", "posted": "2019-10-19T02:00:00+00:00"},+ {"comment": "Fourth", "posted": "2019-10-19T04:00:00+00:00"},+ ],+ )+ self.assertEqual(+ get_public_comments(payload),+ "* Fourth\n* Third\n* Second\n* and 1 more",+ )++ self.assertEqual(get_public_comments(wrap_wild_value("publicComments", [])), "")+def test_format_duration_to_string(self) -> None:test_cases = [(0, "0 seconds"),diff --git a/zerver/webhooks/gong/view.py b/zerver/webhooks/gong/view.pyindex 63733028d82..07e322ee1ba 100644--- a/zerver/webhooks/gong/view.py+++ b/zerver/webhooks/gong/view.py@@ -23,6 +23,7 @@ SECTION_TEMPLATE = "**{heading}**:\n{body}"TOPICS_TEMPLATE = "**Topics**: {topics}"TOP_CONTENT_LIMIT = 3PARTICIPANTS_LIMIT = 5+COMMENTS_LIMIT = 3class Helper:@@ -33,12 +34,14 @@ class Helper:include_topics: bool,include_participants: bool,include_participant_contacts: bool,+ include_public_comments: bool,) -> None:self.payload = payloadself.include_trackers = include_trackersself.include_topics = include_topicsself.include_participants = include_participantsself.include_participant_contacts = include_participant_contacts+ self.include_public_comments = include_public_commentsdef format_duration_to_string(duration: int) -> str:@@ -143,6 +146,22 @@ def get_topics(topics_payload: WildValue) -> str:return topics_line + "." if topics_line else ""+def get_public_comments(comments_payload: WildValue) -> str:+ comments = sorted(+ comments_payload,+ key=lambda comment: comment["posted"].tame(check_iso_datetime),+ reverse=True,+ )+ lines = []+ for comment in comments[:COMMENTS_LIMIT]:+ text = comment["comment"].tame(check_string)+ lines.append(f"* {text}")+ additional_comments = len(comments) - len(lines)+ if additional_comments:+ lines.append(f"* and {additional_comments} more")+ return "\n".join(lines)++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.@@ -190,6 +209,13 @@ def handle_call_processed_message(helper: Helper) -> tuple[str, str]:and (topics := get_topics(content["topics"]))):body += "\n\n" + TOPICS_TEMPLATE.format(topics=topics)++ if (+ helper.include_public_comments+ and (public_comments_list := call_data["collaboration"].get("publicComments"))+ and (public_comments := get_public_comments(public_comments_list))+ ):+ body += "\n\n" + SECTION_TEMPLATE.format(heading="Comments", body=public_comments)return topic, body@@ -204,6 +230,7 @@ def api_gong_webhook(include_topics: Json[bool] = True,include_participants: Json[bool] = True,include_participant_contacts: Json[bool] = True,+ include_public_comments: Json[bool] = False,) -> HttpResponse:helper = Helper(payload,@@ -211,6 +238,7 @@ def api_gong_webhook(include_topics,include_participants,include_participant_contacts,+ include_public_comments,)if payload.get("isTest").tame(check_bool):topic, body = handle_test_message(helper)