diff --git a/static/images/integrations/logos/zapier.png b/static/images/integrations/logos/zapier.png new file mode 100644 index 0000000000..99b5e72890 Binary files /dev/null and b/static/images/integrations/logos/zapier.png differ diff --git a/static/images/integrations/zapier/001.png b/static/images/integrations/zapier/001.png new file mode 100644 index 0000000000..4a81d88c40 Binary files /dev/null and b/static/images/integrations/zapier/001.png differ diff --git a/static/images/integrations/zapier/002.png b/static/images/integrations/zapier/002.png new file mode 100644 index 0000000000..91616cb450 Binary files /dev/null and b/static/images/integrations/zapier/002.png differ diff --git a/static/images/integrations/zapier/003.png b/static/images/integrations/zapier/003.png new file mode 100644 index 0000000000..163c52ead9 Binary files /dev/null and b/static/images/integrations/zapier/003.png differ diff --git a/static/images/integrations/zapier/004.png b/static/images/integrations/zapier/004.png new file mode 100644 index 0000000000..63879a52e1 Binary files /dev/null and b/static/images/integrations/zapier/004.png differ diff --git a/static/images/integrations/zapier/005.png b/static/images/integrations/zapier/005.png new file mode 100644 index 0000000000..b1cc46d957 Binary files /dev/null and b/static/images/integrations/zapier/005.png differ diff --git a/templates/zerver/integrations.html b/templates/zerver/integrations.html index ac09da075e..052aca1b34 100644 --- a/templates/zerver/integrations.html +++ b/templates/zerver/integrations.html @@ -2940,6 +2940,51 @@ access_token_secret = their own Zulip account email in the webhook URL.

+
+

Get notifications from every event supported by Zapier.

+

First, create the stream you'd like to use for Zapier notifications, + and subscribe all interested parties to this stream.

+ +

{{ external_api_uri_subdomain }}/v1/external/zapier?api_key=abcdefgh&stream=zapier

+ +

+ Next, create a ZAP, picking the service you'd like + to receive notifications from as Trigger (Step 1) +

+ + +

and Webhook as Action (Step 2).

+ + +

As Step 2 action please choose POST

+ + +

+ Configure Set up Webhooks by Zapier POST as follows: + +

+

+ +

+ Finally, configure Data. + You have to add 2 fields: +

+

+ +

Example configuration:

+ + +

You're done! Example message:

+ + +
+

First, create the stream you'd like to use for Zendesk notifications, and subscribe all interested parties to this stream. We recommend the diff --git a/zerver/fixtures/zapier/zapier_correct_subject_and_body.json b/zerver/fixtures/zapier/zapier_correct_subject_and_body.json new file mode 100644 index 0000000000..5a1561b785 --- /dev/null +++ b/zerver/fixtures/zapier/zapier_correct_subject_and_body.json @@ -0,0 +1,4 @@ +{ + "content": "Your email content is: \nMy Email content.\n", + "subject": "New email from zulip@zulip.com" +} diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index a4045832be..4c895902ea 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -156,6 +156,7 @@ WEBHOOK_INTEGRATIONS = [ logo='static/images/integrations/logos/yo-app.png', display_name='Yo App' ), + WebhookIntegration('zapier'), WebhookIntegration('zendesk') ] # type: List[WebhookIntegration] diff --git a/zerver/tests/webhooks/test_zapier.py b/zerver/tests/webhooks/test_zapier.py new file mode 100644 index 0000000000..1ac05915e0 --- /dev/null +++ b/zerver/tests/webhooks/test_zapier.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +from zerver.lib.test_classes import WebhookTestCase + +class ZapierHookTests(WebhookTestCase): + STREAM_NAME = 'zapier' + URL_TEMPLATE = "/api/v1/external/zapier?stream={stream}&api_key={api_key}" + FIXTURE_DIR_NAME = 'zapier' + + def test_zapier_when_subject_and_body_are_correct(self): + # type: () -> None + expected_subject = u"New email from zulip@zulip.com" + expected_message = u"Your email content is: \nMy Email content.\n" + self.send_and_test_stream_message('correct_subject_and_body', expected_subject, expected_message) diff --git a/zerver/views/webhooks/zapier.py b/zerver/views/webhooks/zapier.py new file mode 100644 index 0000000000..13f785e784 --- /dev/null +++ b/zerver/views/webhooks/zapier.py @@ -0,0 +1,24 @@ +from __future__ import absolute_import +from django.utils.translation import ugettext as _ +from typing import Any, Callable, Dict +from django.http import HttpRequest, HttpResponse +from zerver.lib.actions import check_send_message +from zerver.lib.response import json_success, json_error +from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view +from zerver.models import UserProfile, Client + + +@api_key_only_webhook_view('Zapier') +@has_request_variables +def api_zapier_webhook(request, user_profile, client, + payload=REQ(argument_type='body'), + stream=REQ(default='zapier')): + # type: (HttpRequest, UserProfile, Client, Dict[str, Any], str) -> HttpResponse + subject = payload.get('subject') + content = payload.get('content') + if subject is None: + return json_error(_("Subject can't be empty")) + if content is None: + return json_error(_("Content can't be empty")) + check_send_message(user_profile, client, "stream", [stream], subject, content) + return json_success()