Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
dialogflow: Strengthen types using WildValue.
Christopher Chong66fd6b1e55ac
diff --git a/zerver/webhooks/dialogflow/view.py b/zerver/webhooks/dialogflow/view.pyindex 005f74a1a7f..61dddf106d5 100644--- a/zerver/webhooks/dialogflow/view.py+++ b/zerver/webhooks/dialogflow/view.py@@ -1,12 +1,11 @@# Webhooks for external integrations.-from typing import Any, Dict-from django.http import HttpRequest, HttpResponsefrom zerver.actions.message_send import check_send_private_messagefrom zerver.decorator import webhook_viewfrom zerver.lib.request import REQ, RequestNotes, has_request_variablesfrom zerver.lib.response import json_success+from zerver.lib.validator import WildValue, check_int, check_string, to_wild_valuefrom zerver.models import UserProfile, get_user@@ -15,15 +14,17 @@ from zerver.models import UserProfile, get_userdef api_dialogflow_webhook(request: HttpRequest,user_profile: UserProfile,- payload: Dict[str, Any] = REQ(argument_type="body"),+ payload: WildValue = REQ(argument_type="body", converter=to_wild_value),email: str = REQ(),) -> HttpResponse:- status = payload["status"]["code"]+ status = payload["status"]["code"].tame(check_int)if status == 200:- result = payload["result"]["fulfillment"]["speech"]+ result = payload["result"]["fulfillment"]["speech"].tame(check_string)if not result:- alternate_result = payload["alternateResult"]["fulfillment"]["speech"]+ alternate_result = payload["alternateResult"]["fulfillment"]["speech"].tame(+ check_string+ )if not alternate_result:body = "Dialogflow couldn't process your query."else:@@ -31,7 +32,7 @@ def api_dialogflow_webhook(else:body = resultelse:- error_status = payload["status"]["errorDetails"]+ error_status = payload["status"]["errorDetails"].tame(check_string)body = f"{status} - {error_status}"receiving_user = get_user(email, user_profile.realm)