webhooks/zapier: Remove code related to our official Zapier app.

Our official Zapier app now uses our JS bindings (zulip-js) to
call the API directly and doesn't need to go through the webhook
anymore for anything.
This commit is contained in:
Eeshan Garg
2019-02-28 15:10:48 -03:30
committed by Tim Abbott
parent 4603cdba7e
commit 85f453998e
6 changed files with 1 additions and 91 deletions

View File

@@ -1980,15 +1980,6 @@ def check_send_private_message(sender: UserProfile, client: Client,
return do_send_messages([message])[0]
def check_send_private_message_from_emails(
sender: UserProfile, client: Client,
receiving_emails: Sequence[str], body: str
) -> int:
addressee = Addressee.for_private(receiving_emails, sender.realm)
message = check_message(sender, client, addressee, body)
return do_send_messages([message])[0]
# check_send_message:
# Returns the id of the sent message. Has same argspec as check_message.
def check_send_message(sender: UserProfile, client: Client, message_type_name: str,

View File

@@ -1,3 +0,0 @@
{
"type": "auth"
}

View File

@@ -1,8 +0,0 @@
{
"type": "private",
"content": "Sample content for private huddle message",
"to": [
"iago@zulip.com",
"cordelia@zulip.com"
]
}

View File

@@ -1,5 +0,0 @@
{
"type": "stream",
"topic": "Sample message from Zapier!",
"content": "Hi! I am a new sample message from Zapier!"
}

View File

@@ -20,38 +20,3 @@ class ZapierHookTests(WebhookTestCase):
expected_topic = u"Here is your weather update for the day:"
expected_message = u"Foggy in the morning.\nMaximum temperature to be 24.\nMinimum temperature to be 12"
self.send_and_test_stream_message('weather_update', expected_topic, expected_message)
class ZapierZulipAppTests(WebhookTestCase):
STREAM_NAME = 'zapier'
URL_TEMPLATE = "/api/v1/external/zapier?api_key={api_key}&stream={stream}"
FIXTURE_DIR_NAME = 'zapier'
def test_auth(self) -> None:
payload = self.get_body('zapier_zulip_app_auth')
headers = {'HTTP_USER_AGENT': 'ZapierZulipApp'}
result = self.client_post(self.url, payload,
content_type='application/json',
**headers)
json_result = self.assert_json_success(result)
self.assertEqual(json_result['bot_name'], 'Zulip Webhook Bot')
self.assertEqual(json_result['bot_email'], 'webhook-bot@zulip.com')
self.assertIn('bot_id', json_result)
def test_stream(self) -> None:
expected_topic = u"Sample message from Zapier!"
expected_message = u"Hi! I am a new sample message from Zapier!"
self.send_and_test_stream_message('zapier_zulip_app_stream',
expected_topic, expected_message,
HTTP_USER_AGENT='ZapierZulipApp')
def test_private(self) -> None:
payload = self.get_body('zapier_zulip_app_private')
headers = {'HTTP_USER_AGENT': 'ZapierZulipApp'}
result = self.client_post(self.url, payload,
content_type='application/json',
**headers)
self.assert_json_success(result)
expected_message = "Sample content for private huddle message"
msg = self.get_last_message()
self.assertEqual(msg.content, expected_message)

View File

@@ -4,11 +4,9 @@ from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.actions import check_send_private_message_from_emails
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \
validate_extract_webhook_http_header
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@api_key_only_webhook_view('Zapier', notify_bot_owner_on_invalid_json=False)
@@ -16,34 +14,6 @@ from zerver.models import UserProfile
def api_zapier_webhook(request: HttpRequest, user_profile: UserProfile,
payload: Dict[str, Any]=REQ(argument_type='body')) -> HttpResponse:
# A request with the ZapierZulipApp user agent is a request from
# the official Zulip app for Zapier
user_agent = validate_extract_webhook_http_header(
request, 'USER_AGENT', 'Zapier', fatal=False)
if user_agent == 'ZapierZulipApp':
event_type = payload.get('type')
if event_type == 'auth':
# The bot's details are used by Zapier to format a connection
# label for users to be able to distinguish between different
# Zulip bots and API keys in their UI
return json_success({
'bot_name': user_profile.full_name,
'bot_email': user_profile.email,
'bot_id': user_profile.id
})
elif event_type == 'stream':
check_send_webhook_message(
request, user_profile,
payload['topic'], payload['content']
)
elif event_type == 'private':
check_send_private_message_from_emails(
user_profile, request.client,
payload['to'], payload['content']
)
return json_success()
topic = payload.get('topic')
content = payload.get('content')