outgoing webhooks: Send additional useful data.

This adds the fields `trigger` and `service_email`
to each message event dispatched by outgoing webhook bots.
`trigger` will be used by the Botserver to determine if
a bot is mentioned in the message.
`service_email` will be used by the Botserver to determine
by which outgoing webhook bot the message should be handled.
This commit is contained in:
Robert Hönig 2018-05-23 16:14:22 +02:00 committed by Tim Abbott
parent cc0d0b55f1
commit 7a8c1ec9dc
2 changed files with 9 additions and 5 deletions

View File

@ -58,7 +58,9 @@ class GenericOutgoingWebhookService(OutgoingWebhookServiceInterface):
'request_kwargs': {}} 'request_kwargs': {}}
request_data = {"data": event['command'], request_data = {"data": event['command'],
"message": event['message'], "message": event['message'],
"token": self.token} "bot_email": self.user_profile.email,
"token": self.token,
"trigger": event['trigger']}
return rest_operation, json.dumps(request_data) return rest_operation, json.dumps(request_data)
def process_success(self, response: Response, def process_success(self, response: Response,

View File

@ -8,7 +8,7 @@ from requests.models import Response
from zerver.lib.outgoing_webhook import GenericOutgoingWebhookService, \ from zerver.lib.outgoing_webhook import GenericOutgoingWebhookService, \
SlackOutgoingWebhookService SlackOutgoingWebhookService
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.models import Service from zerver.models import Service, get_realm, get_user
class TestGenericOutgoingWebhookService(ZulipTestCase): class TestGenericOutgoingWebhookService(ZulipTestCase):
@ -16,13 +16,15 @@ class TestGenericOutgoingWebhookService(ZulipTestCase):
self.event = { self.event = {
u'command': '@**test**', u'command': '@**test**',
u'message': { u'message': {
'content': 'test_content', 'content': '@**test**',
} },
u'trigger': 'mention',
} }
self.bot_user = get_user("outgoing-webhook@zulip.com", get_realm("zulip"))
self.handler = GenericOutgoingWebhookService(service_name='test-service', self.handler = GenericOutgoingWebhookService(service_name='test-service',
base_url='http://example.domain.com', base_url='http://example.domain.com',
token='abcdef', token='abcdef',
user_profile=None) user_profile=self.bot_user)
def test_process_event(self) -> None: def test_process_event(self) -> None:
rest_operation, request_data = self.handler.process_event(self.event) rest_operation, request_data = self.handler.process_event(self.event)