2020-10-21 20:56:33 +02:00
|
|
|
# Webhooks for external integrations.
|
|
|
|
|
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
|
|
|
from zerver.decorator import webhook_view
|
|
|
|
from zerver.lib.response import json_success
|
2023-09-27 19:01:31 +02:00
|
|
|
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
2023-08-12 09:34:31 +02:00
|
|
|
from zerver.lib.validator import WildValue, check_string
|
2020-10-21 20:56:33 +02:00
|
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
|
|
|
from zerver.models import UserProfile
|
|
|
|
|
|
|
|
|
|
|
|
@webhook_view("Jotform")
|
2023-08-12 09:34:31 +02:00
|
|
|
@typed_endpoint
|
2020-10-21 20:56:33 +02:00
|
|
|
def api_jotform_webhook(
|
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
2023-08-12 09:34:31 +02:00
|
|
|
*,
|
2023-09-27 19:01:31 +02:00
|
|
|
payload: JsonBodyPayload[WildValue],
|
2020-10-21 20:56:33 +02:00
|
|
|
) -> HttpResponse:
|
2022-10-08 19:20:18 +02:00
|
|
|
topic = payload["formTitle"].tame(check_string)
|
|
|
|
submission_id = payload["submissionID"].tame(check_string)
|
2023-09-12 23:19:57 +02:00
|
|
|
fields = payload["pretty"].tame(check_string).split(", ")
|
2020-10-21 20:56:33 +02:00
|
|
|
|
|
|
|
form_response = f"A new submission (ID {submission_id}) was received:\n"
|
2023-09-12 23:19:57 +02:00
|
|
|
for field in fields:
|
2020-10-21 20:56:33 +02:00
|
|
|
form_response += f"* {field}\n"
|
|
|
|
|
|
|
|
message = form_response.strip()
|
|
|
|
|
|
|
|
check_send_webhook_message(request, user_profile, topic, message)
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|