Add Dropbox webhook integration.

This is just a basic Dropbox webhook integration. It just
notifies a user when something has changed, it does not
specify what changed. Doing so would require storing data,
as Dropbox API was created mainly for file managers, not
integrations like this.
Closes #5672
This commit is contained in:
Angelika Serwa
2017-12-18 01:56:03 +01:00
committed by showell
parent 096088969d
commit 2f575cca72
9 changed files with 77 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235.45 200"><defs><style>.cls-1{fill:#0061ff;}</style></defs><title>DropboxGlyph</title><polygon class="cls-1" points="58.86 0 0 37.5 58.86 75 117.73 37.5 58.86 0"/><polygon class="cls-1" points="176.59 0 117.73 37.5 176.59 75 235.45 37.5 176.59 0"/><polygon class="cls-1" points="0 112.5 58.86 150 117.73 112.5 58.86 75 0 112.5"/><polygon class="cls-1" points="176.59 75 117.73 112.5 176.59 150 235.45 112.5 176.59 75"/><polygon class="cls-1" points="58.86 162.5 117.73 200 176.59 162.5 117.73 125 58.86 162.5"/></svg>

After

Width:  |  Height:  |  Size: 605 B

View File

@@ -284,6 +284,7 @@ WEBHOOK_INTEGRATIONS = [
display_name='Desk.com',
stream_name='desk'
),
WebhookIntegration('dropbox', ['productivity'], display_name='Dropbox'),
WebhookIntegration('freshdesk', ['customer-support']),
GithubIntegration(
'github',

View File

View File

@@ -0,0 +1,17 @@
{!create-stream.md!}
{!create-bot-construct-url.md!}
{!append-topic.md!}
Next, log into your account on [Dropbox](https://www.dropbox.com), go
[there](https://www.dropbox.com/developers/apps) and click **Create app**.
Follow the steps, and in **Webhooks** section add the webhook address you created above.
Click **Add** button. The status of the webhook should say **Enabled**.
In **Generated access token** section click **Generate** button.
![](/static/images/integrations/dropbox/001.png)
{!congrats.md!}
![](/static/images/integrations/dropbox/002.png)

View File

@@ -0,0 +1,12 @@
{
"list_folder": {
"accounts": [
"dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc"
]
},
"delta": {
"users": [
12345678
]
}
}

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from typing import Text
from zerver.lib.test_classes import WebhookTestCase
class DropboxHookTests(WebhookTestCase):
STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}"
FIXTURE_DIR_NAME = 'dropbox'
def test_file_updated(self) -> None:
expected_subject = u"Dropbox"
expected_message = u"File has been updated on Dropbox!"
self.send_and_test_stream_message('file_updated', expected_subject, expected_message,
content_type="application/x-www-form-urlencoded")
def get_body(self, fixture_name: Text) -> Text:
return self.fixture_data("dropbox", fixture_name, file_type="json")
def test_verification_request(self) -> None:
self.subscribe(self.test_user, self.STREAM_NAME)
get_params = {'stream_name': self.STREAM_NAME,
'challenge': '9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E',
'api_key': self.test_user.api_key}
result = self.client_get(self.url, get_params)
self.assert_in_response('9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E', result)

View File

@@ -0,0 +1,18 @@
from typing import Text
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@api_key_only_webhook_view('Dropbox')
@has_request_variables
def api_dropbox_webhook(request: HttpRequest, user_profile: UserProfile,
stream: Text=REQ(default='test'),
topic: Text=REQ(default='Dropbox')) -> HttpResponse:
if request.method == 'GET':
return HttpResponse(request.GET['challenge'])
elif request.method == 'POST':
check_send_stream_message(user_profile, request.client,
stream, topic, "File has been updated on Dropbox!")
return json_success()