Add Zapier integration.

This commit is contained in:
Tomasz Kolek 2017-01-17 19:41:29 +01:00 committed by Tim Abbott
parent 29799d93c6
commit cc13104780
11 changed files with 87 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -2940,6 +2940,51 @@ access_token_secret =</pre>
their own Zulip account email in the webhook URL.</p>
</div>
<div id="zapier" class="integration-instructions">
<p>Get notifications from every event supported by Zapier.</p>
<p>First, create the stream you'd like to use for Zapier notifications,
and subscribe all interested parties to this stream.</p>
<p><code>{{ external_api_uri_subdomain }}/v1/external/zapier?api_key=abcdefgh&amp;stream=zapier</code></p>
<p>
Next, create a ZAP, picking the service you'd like
to receive notifications from as <code>Trigger (Step 1)</code>
</p>
<img class="screenshot" src="/static/images/integrations/zapier/001.png" />
<p>and <code>Webhook</code> as <code>Action (Step 2)</code>.</p>
<img class="screenshot" src="/static/images/integrations/zapier/002.png" />
<p>As Step 2 action please choose <code>POST</code></p>
<img class="screenshot" src="/static/images/integrations/zapier/003.png" />
<p>
Configure <code>Set up Webhooks by Zapier POST</code> as follows:
<ul>
<li><code>URL</code> is the url we created above</li>
<li><code>Payload Type</code> set to <code>JSON</code></li>
</ul>
</p>
<p>
Finally, configure <code>Data</code>.
You have to add 2 fields:
<ul>
<li><code>subject</code> is field corresponding to a subject of the message</li>
<li><code>content</code> is field corresponding to a content of the message</li>
</ul>
</p>
<p>Example configuration:</p>
<img class="screenshot" src="/static/images/integrations/zapier/004.png" />
<p>You're done! Example message:</p>
<img class="screenshot" src="/static/images/integrations/zapier/005.png" />
</div>
<div id="zendesk" class="integration-instructions">
<p>First, create the stream you'd like to use for Zendesk notifications,
and subscribe all interested parties to this stream. We recommend the

View File

@ -0,0 +1,4 @@
{
"content": "Your email content is: \nMy Email content.\n",
"subject": "New email from zulip@zulip.com"
}

View File

@ -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]

View File

@ -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)

View File

@ -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()