Add integration for Yo App.

[includes some small tweaks by tabbott]
This commit is contained in:
Anindya Chakravarti
2016-03-25 21:49:18 +05:30
committed by Tim Abbott
parent 44ed9da7f0
commit f3d03d89b4
8 changed files with 79 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file.
- Added documentation on using Hubot to integrate with useful services - Added documentation on using Hubot to integrate with useful services
not yet integrated with Zulip directly (e.g. Google Hangouts). not yet integrated with Zulip directly (e.g. Google Hangouts).
- Added new management command to test sending email from Zulip. - Added new management command to test sending email from Zulip.
- Added Pingdom integration. - Added Pingdom and Yo integrations.
- Refactored the Zulip puppet modules to be more modular. - Refactored the Zulip puppet modules to be more modular.
- Refactored the Tornado event system, fixing old memory leaks. - Refactored the Tornado event system, fixing old memory leaks.
- Implemented running queue processors multithreaded in development, - Implemented running queue processors multithreaded in development,

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -224,6 +224,12 @@
<span class="integration-label">Twitter</span> <span class="integration-label">Twitter</span>
</a> </a>
</div> </div>
<div class="integration-lozenge integration-yo-app">
<a class="integration-link integration-yo-app" href="#yo-app">
<img class="integration-logo" src="/static/images/integrations/logos/yo-app.png" alt="Yo App logo" />
<span class="integration-label">Yo App</span>
</a>
</div>
<div class="integration-lozenge integration-zendesk"> <div class="integration-lozenge integration-zendesk">
<a class="integration-link integration-zendesk" href="#zendesk"> <a class="integration-link integration-zendesk" href="#zendesk">
<img class="integration-logo" src="/static/images/integrations/logos/zendesk.png" alt="Zendesk logo" /> <img class="integration-logo" src="/static/images/integrations/logos/zendesk.png" alt="Zendesk logo" />
@@ -1838,6 +1844,38 @@ notifications:
<img class="screenshot" src="/static/images/integrations/travis/001.png" /> <img class="screenshot" src="/static/images/integrations/travis/001.png" />
</div> </div>
<div id="yo-app" class="integration-instructions">
<p>See your Yo App notifications in Zulip!</p>
<p>Set up a bot for the integration. You'll need the bot's API key
to construct a URL for Yo App Callback.</p>
<p>You will receive your notifications as a private message between you and the bot.</p>
<pre>
Create URL using your bot's API key and the email address
associated with your Zulip account:
https://zulip.example.com/api/v1/external/yo?email=awesome@zulip.example.com&amp;api_key=abcdefgh
</pre>
<p>Copy the url created and go to <a href="https://yoapi.justyo.co">yoapi.justyo.co</a></p>
<p>Sign in using your username and password and go to Edit Profile.</p>
<img class="screenshot" src="/static/images/integrations/yo-app/001.png" />
<p>Paste the URL in Callback field and click on Update.</p>
<p><b>Congratulations! You're done!</b><br />When someone sends your username a Yo,
you'll receive a notification as a private message from the bot
like this:</p>
<img class="screenshot" src="/static/images/integrations/yo-app/002.png" />
<p>Multiple users can use the same Yo bot; each user should use
their own Zulip account email in the webhook URL.</p>
</div>
<div id="zendesk" class="integration-instructions"> <div id="zendesk" class="integration-instructions">
<p>First, create the stream you'd like to use for Zendesk notifications, <p>First, create the stream you'd like to use for Zendesk notifications,
and subscribe all interested parties to this stream. We recommend the and subscribe all interested parties to this stream. We recommend the

View File

@@ -932,3 +932,24 @@ class PingdomHookTests(AuthedTestCase):
def _send_post_request_with_params(self, json): def _send_post_request_with_params(self, json):
return self.client.post(self._url, json, stream_name=self.STREAM_NAME, content_type="application/json") return self.client.post(self._url, json, stream_name=self.STREAM_NAME, content_type="application/json")
class YoHookTests(AuthedTestCase):
def test_yo_message(self):
"""
Yo App sends notification whenever user receives a new Yo from another user.
"""
bot_email = "hamlet@zulip.com"
api_key = self.get_api_key(bot_email)
body = ""
email = "cordelia@zulip.com"
sender = "IAGO"
ip = "127.0.0.1"
url = "/api/v1/external/yo?email=%s&api_key=%s&username=%s&user_ip=%s" % (email, api_key, sender, ip)
self.client.get(url,
body,
content_type="application/x-www-form-urlencoded")
msg = Message.objects.filter().order_by('-id')[0]
self.assertEqual(msg.content, (u"Yo from IAGO"))

View File

@@ -0,0 +1,18 @@
# Webhooks for external integrations.
from __future__ import absolute_import
from zerver.models import get_client
from zerver.lib.actions import check_send_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
import ujson
@api_key_only_webhook_view
@has_request_variables
def api_yo_app_webhook(request, user_profile, email=REQ(default=None),
username=REQ(default='Yo Bot'), topic=REQ(default='None'),
user_ip=REQ(default='None')):
body = ('Yo from %s') % (username,)
check_send_message(user_profile, get_client('ZulipYoWebhook'), 'private', [email], topic, body)
return json_success()

View File

@@ -162,6 +162,7 @@ urlpatterns += patterns('zerver.views',
url(r'^api/v1/external/pagerduty$', 'webhooks.pagerduty.api_pagerduty_webhook'), url(r'^api/v1/external/pagerduty$', 'webhooks.pagerduty.api_pagerduty_webhook'),
url(r'^api/v1/external/travis$', 'webhooks.travis.api_travis_webhook'), url(r'^api/v1/external/travis$', 'webhooks.travis.api_travis_webhook'),
url(r'^api/v1/external/pingdom$', 'webhooks.pingdom.api_pingdom_webhook'), url(r'^api/v1/external/pingdom$', 'webhooks.pingdom.api_pingdom_webhook'),
url(r'^api/v1/external/yo$', 'webhooks.yo.api_yo_app_webhook'),
url(r'^user_uploads/(?P<realm_id>(\d*|unk))/(?P<filename>.*)', 'get_uploaded_file'), url(r'^user_uploads/(?P<realm_id>(\d*|unk))/(?P<filename>.*)', 'get_uploaded_file'),
) )