api: Add bot name to outgoing webhook payload.

Fixes: #12282
This commit is contained in:
PIG208 2021-04-07 03:24:57 +08:00 committed by Tim Abbott
parent e51344ab2d
commit c6dfe7bf40
3 changed files with 9 additions and 2 deletions

View File

@ -69,6 +69,7 @@ class GenericOutgoingWebhookService(OutgoingWebhookServiceInterface):
"data": event["command"], "data": event["command"],
"message": message_dict, "message": message_dict,
"bot_email": self.user_profile.email, "bot_email": self.user_profile.email,
"bot_full_name": self.user_profile.full_name,
"token": self.token, "token": self.token,
"trigger": event["trigger"], "trigger": event["trigger"],
} }

View File

@ -9302,6 +9302,10 @@ paths:
type: string type: string
description: | description: |
Email of the bot user. Email of the bot user.
bot_full_name:
type: string
description: |
The full name of the bot user.
data: data:
type: string type: string
description: | description: |
@ -9376,6 +9380,7 @@ paths:
"sender_realm_str": "zulip", "sender_realm_str": "zulip",
}, },
"bot_email": "outgoing-bot@localhost", "bot_email": "outgoing-bot@localhost",
"bot_full_name": "Outgoing webhook test",
} }
/calls/bigbluebutton/create: /calls/bigbluebutton/create:

View File

@ -18,10 +18,10 @@ class TestGenericOutgoingWebhookService(ZulipTestCase):
def setUp(self) -> None: def setUp(self) -> None:
super().setUp() super().setUp()
bot_user = get_user("outgoing-webhook@zulip.com", get_realm("zulip")) self.bot_user = get_user("outgoing-webhook@zulip.com", get_realm("zulip"))
service_class = get_service_interface_class("whatever") # GenericOutgoingWebhookService service_class = get_service_interface_class("whatever") # GenericOutgoingWebhookService
self.handler = service_class( self.handler = service_class(
service_name="test-service", token="abcdef", user_profile=bot_user service_name="test-service", token="abcdef", user_profile=self.bot_user
) )
def test_process_success_response(self) -> None: def test_process_success_response(self) -> None:
@ -113,6 +113,7 @@ class TestGenericOutgoingWebhookService(ZulipTestCase):
request_data = session.post.call_args[1]["json"] request_data = session.post.call_args[1]["json"]
validate_against_openapi_schema(request_data, "/zulip-outgoing-webhook", "post", "200") validate_against_openapi_schema(request_data, "/zulip-outgoing-webhook", "post", "200")
self.assertEqual(request_data["bot_full_name"], self.bot_user.full_name)
self.assertEqual(request_data["data"], "@**test**") self.assertEqual(request_data["data"], "@**test**")
self.assertEqual(request_data["token"], "abcdef") self.assertEqual(request_data["token"], "abcdef")
self.assertEqual(request_data["message"], expected_message_data) self.assertEqual(request_data["message"], expected_message_data)