Files
zulip/zerver/webhooks/dropbox/view.py
Zixuan James Li 9377080f1f webhooks: Migrate most webhooks to use @typed_endpoint.
This converts most webhook integration views to use @typed_endpoint instead
of @has_request_variables, rewriting REQ parameters. For these
webhooks, it simply requires switching the decorator, rewriting the
type annotation of payload/message to WebhookPayload[WildValue], and
removing the REQ default that defines the to_wild_value converter.
2023-09-08 08:20:17 -07:00

31 lines
1011 B
Python

from typing import Optional
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.request import RequestVariableMissingError
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import typed_endpoint
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@webhook_view("Dropbox", notify_bot_owner_on_invalid_json=False)
@typed_endpoint
def api_dropbox_webhook(
request: HttpRequest,
user_profile: UserProfile,
*,
challenge: Optional[str] = None,
) -> HttpResponse:
if request.method == "POST":
topic = "Dropbox"
check_send_webhook_message(
request, user_profile, topic, "File has been updated on Dropbox!"
)
return json_success(request)
else:
if challenge is None:
raise RequestVariableMissingError("challenge")
return HttpResponse(challenge, content_type="text/plain; charset=UTF-8")