2016-03-25 17:19:18 +01:00
|
|
|
# Webhooks for external integrations.
|
2016-06-06 00:14:45 +02:00
|
|
|
from typing import Optional
|
2016-03-25 17:19:18 +01:00
|
|
|
|
2017-11-16 00:43:10 +01:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
|
2020-08-20 00:32:15 +02:00
|
|
|
from zerver.decorator import webhook_view
|
2017-11-16 00:43:10 +01:00
|
|
|
from zerver.lib.actions import check_send_private_message
|
2021-07-09 18:10:51 +02:00
|
|
|
from zerver.lib.request import REQ, get_request_notes, has_request_variables
|
2017-11-16 00:43:10 +01:00
|
|
|
from zerver.lib.response import json_success
|
|
|
|
from zerver.models import UserProfile, get_user
|
2016-03-25 17:19:18 +01:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@webhook_view("Yo", notify_bot_owner_on_invalid_json=False)
|
2016-03-25 17:19:18 +01:00
|
|
|
@has_request_variables
|
2021-02-12 08:19:30 +01:00
|
|
|
def api_yo_app_webhook(
|
|
|
|
request: HttpRequest,
|
|
|
|
user_profile: UserProfile,
|
|
|
|
email: str = REQ(default=""),
|
2021-02-12 08:20:45 +01:00
|
|
|
username: str = REQ(default="Yo Bot"),
|
2021-02-12 08:19:30 +01:00
|
|
|
topic: Optional[str] = REQ(default=None),
|
|
|
|
user_ip: Optional[str] = REQ(default=None),
|
|
|
|
) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
body = f"Yo from {username}"
|
2017-10-03 00:28:44 +02:00
|
|
|
receiving_user = get_user(email, user_profile.realm)
|
2021-07-09 18:10:51 +02:00
|
|
|
client = get_request_notes(request).client
|
|
|
|
assert client is not None
|
|
|
|
check_send_private_message(user_profile, client, receiving_user, body)
|
2016-03-25 17:19:18 +01:00
|
|
|
return json_success()
|