2020-05-13 05:55:22 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2017-12-18 01:56:03 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2021-07-16 22:11:10 +02:00
|
|
|
from zerver.decorator import webhook_view
|
|
|
|
from zerver.lib.request import REQ, RequestVariableMissingError, has_request_variables
|
2017-12-18 01:56:03 +01:00
|
|
|
from zerver.lib.response import json_success
|
2018-03-13 23:43:02 +01:00
|
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
2017-12-18 01:56:03 +01:00
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@webhook_view("Dropbox", notify_bot_owner_on_invalid_json=False)
|
2017-12-18 01:56:03 +01:00
|
|
|
@has_request_variables
|
2020-05-13 05:55:22 +02:00
|
|
|
def api_dropbox_webhook(
|
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
2021-02-12 08:19:30 +01:00
|
|
|
challenge: Optional[str] = REQ(default=None),
|
2020-05-13 05:55:22 +02:00
|
|
|
) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
if request.method == "POST":
|
|
|
|
topic = "Dropbox"
|
2021-02-12 08:19:30 +01:00
|
|
|
check_send_webhook_message(
|
|
|
|
request, user_profile, topic, "File has been updated on Dropbox!"
|
|
|
|
)
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|
2019-08-12 05:44:35 +02:00
|
|
|
else:
|
2020-05-13 05:55:22 +02:00
|
|
|
if challenge is None:
|
|
|
|
raise RequestVariableMissingError("challenge")
|
|
|
|
return HttpResponse(challenge, content_type="text/plain; charset=UTF-8")
|