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:
|
2024-01-17 15:53:30 +01:00
|
|
|
topic_name = payload["formTitle"].tame(check_string)
|
2022-10-08 19:20:18 +02:00
|
|
|
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()
|
|
|
|
|
2024-01-17 15:53:30 +01:00
|
|
|
check_send_webhook_message(request, user_profile, topic_name, message)
|
2022-01-31 13:44:02 +01:00
|
|
|
return json_success(request)
|