mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 23:19:10 +00:00
webhooks: Enable custom topics and default PM notifications.
This commit adds a generic function called check_send_webhook_message that does the following: * If a stream is specified in the webhook URL, it sends a stream message, otherwise sends a PM to the owner of the bot. * In the case of a stream message, if a custom topic is specified in the webhook URL, it uses that topic as the subject of the stream message. Also, note that we need not test this anywhere except for the helloworld webhook. Since helloworld is our default example for webhooks, it is here to stay and it made sense that tests for a generic function such as check_send_webhook_message be tested with an actual generic webhook! Fixes #8607.
This commit is contained in:
24
zerver/lib/webhooks/common.py
Normal file
24
zerver/lib/webhooks/common.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.http import HttpRequest
|
||||
from typing import Optional, Text
|
||||
|
||||
from zerver.lib.actions import check_send_stream_message, \
|
||||
check_send_private_message
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.models import UserProfile
|
||||
|
||||
@has_request_variables
|
||||
def check_send_webhook_message(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
topic: Text, body: Text, stream: Optional[Text]=REQ(default=None),
|
||||
user_specified_topic: Optional[Text]=REQ("topic", default=None)
|
||||
) -> None:
|
||||
|
||||
if stream is None:
|
||||
assert user_profile.bot_owner is not None
|
||||
check_send_private_message(user_profile, request.client,
|
||||
user_profile.bot_owner, body)
|
||||
else:
|
||||
if user_specified_topic is not None:
|
||||
topic = user_specified_topic
|
||||
check_send_stream_message(user_profile, request.client,
|
||||
stream, topic, body)
|
||||
Reference in New Issue
Block a user