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
|
|
|
|
|
|
|
|
from zerver.decorator import api_key_only_webhook_view
|
|
|
|
from zerver.lib.actions import check_send_private_message
|
|
|
|
from zerver.lib.request import REQ, has_request_variables
|
|
|
|
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
|
|
|
|
2018-11-20 18:52:25 +01:00
|
|
|
@api_key_only_webhook_view('Yo', notify_bot_owner_on_invalid_json=False)
|
2016-03-25 17:19:18 +01:00
|
|
|
@has_request_variables
|
2017-12-19 18:53:28 +01:00
|
|
|
def api_yo_app_webhook(request: HttpRequest, user_profile: UserProfile,
|
|
|
|
email: str = REQ(default=""),
|
|
|
|
username: str = REQ(default='Yo Bot'),
|
|
|
|
topic: Optional[str] = REQ(default=None),
|
|
|
|
user_ip: Optional[str] = REQ(default=None)) -> HttpResponse:
|
2016-03-25 17:19:18 +01:00
|
|
|
body = ('Yo from %s') % (username,)
|
2017-10-03 00:28:44 +02:00
|
|
|
receiving_user = get_user(email, user_profile.realm)
|
2017-10-02 07:24:59 +02:00
|
|
|
check_send_private_message(user_profile, request.client, receiving_user, body)
|
2016-03-25 17:19:18 +01:00
|
|
|
return json_success()
|