mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
This is preparatory work towards adding a Topic model. We plan to use the local variable name as 'topic' for the Topic model objects. Currently, we use *topic as the local variable name for topic names. We rename local variables of the form *topic to *topic_name so that we don't need to think about type collisions in individual code paths where we might want to talk about both Topic objects and strings for the topic name.
33 lines
1002 B
Python
33 lines
1002 B
Python
from django.http import HttpRequest, HttpResponse
|
|
|
|
from zerver.decorator import webhook_view
|
|
from zerver.lib.response import json_success
|
|
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
|
from zerver.lib.validator import WildValue, check_string
|
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
|
from zerver.models import UserProfile
|
|
|
|
|
|
@webhook_view("HomeAssistant")
|
|
@typed_endpoint
|
|
def api_homeassistant_webhook(
|
|
request: HttpRequest,
|
|
user_profile: UserProfile,
|
|
*,
|
|
payload: JsonBodyPayload[WildValue],
|
|
) -> HttpResponse:
|
|
# construct the body of the message
|
|
body = payload["message"].tame(check_string)
|
|
|
|
# set the topic to the topic parameter, if given
|
|
if "topic" in payload:
|
|
topic_name = payload["topic"].tame(check_string)
|
|
else:
|
|
topic_name = "homeassistant"
|
|
|
|
# send the message
|
|
check_send_webhook_message(request, user_profile, topic_name, body)
|
|
|
|
# return json result
|
|
return json_success(request)
|