Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
welcome-bot: Only send message with custom text when testing.
Sahil Batrabcdfcf909d17
diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.pyindex 6c3a00672db..1c15ed01ea5 100644--- a/zerver/lib/onboarding.py+++ b/zerver/lib/onboarding.py@@ -50,6 +50,22 @@ def create_if_missing_realm_internal_bots() -> None:setup_realm_internal_bots(realm)+def get_custom_welcome_message_string(welcome_message_custom_text: str) -> str:+ fence = get_unused_fence(welcome_message_custom_text)+ welcome_bot_custom_message_intro_string = _(+ "The administrators for this organization would also like to share the following information:"+ )++ welcome_bot_custom_message_string = f"""+{welcome_bot_custom_message_intro_string}+{fence}quote+{welcome_message_custom_text}+{fence}+"""++ return welcome_bot_custom_message_string++def send_initial_direct_messages_to_user(user: UserProfile,*,@@ -113,16 +129,9 @@ You can always come back to the [Welcome to Zulip video]({navigation_tour_video_welcome_bot_custom_message_string = ""# Add welcome bot custom message.if welcome_message_custom_text:- fence = get_unused_fence(welcome_message_custom_text)- welcome_bot_custom_message_intro_string = _("""-The administrators for this organization would also like to share the following information:""")-- welcome_bot_custom_message_string = f"""-{welcome_bot_custom_message_intro_string}-{fence}quote-{welcome_message_custom_text}-{fence}-"""+ welcome_bot_custom_message_string = get_custom_welcome_message_string(+ welcome_message_custom_text+ )content = _("""Hello, and welcome to Zulip!👋 {inform_about_tracked_onboarding_messages_text}diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 80e06574b3b..25df49cd515 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -15833,9 +15833,9 @@ paths:tags: ["server_and_organizations"]x-requires-administrator: truedescription: |- Sends a test Welcome Bot message with custom text to the acting administrator.- This allows administrators to preview how the welcome message will appear when- received by new users upon joining the organization.+ Sends a test Welcome Bot custom message to the acting administrator.+ This allows administrators to preview how the custom welcome message will+ appear when received by new users upon joining the organization.**Changes**: New in Zulip 11.0 (feature level 416).requestBody:diff --git a/zerver/tests/test_welcome_bot_custom_message.py b/zerver/tests/test_welcome_bot_custom_message.pyindex 15ee20509f6..655d72dbd1a 100644--- a/zerver/tests/test_welcome_bot_custom_message.py+++ b/zerver/tests/test_welcome_bot_custom_message.py@@ -31,13 +31,11 @@ class WelcomeBotCustomMessageTest(ZulipTestCase):response_dict = self.assert_json_success(result)welcome_bot_custom_message_id = response_dict["message_id"]- received_welcome_bot_message = self.get_second_to_last_message()- received_welcome_bot_custom_message = self.get_last_message()+ # Make sure that only message with custom text is sent.+ previous_message = self.get_second_to_last_message()+ self.assertNotEqual(previous_message.sender.email, "[email protected]")- self.assertEqual(received_welcome_bot_message.sender.email, "[email protected]")- self.assertTrue(- received_welcome_bot_message.content.startswith("Hello, and welcome to Zulip!")- )+ received_welcome_bot_custom_message = self.get_last_message()self.assertEqual(received_welcome_bot_custom_message.sender.email, "[email protected]")self.assertIn(welcome_message_custom_text, received_welcome_bot_custom_message.content)diff --git a/zerver/views/welcome_bot_custom_message.py b/zerver/views/welcome_bot_custom_message.pyindex 7eef4cb9495..9c9541980cd 100644--- a/zerver/views/welcome_bot_custom_message.py+++ b/zerver/views/welcome_bot_custom_message.py@@ -1,16 +1,18 @@from typing import Annotated+from django.conf import settingsfrom django.http import HttpRequest, HttpResponsefrom django.utils.translation import gettext as _from pydantic import StringConstraints+from zerver.actions.message_send import internal_send_private_messagefrom zerver.decorator import require_realm_adminfrom zerver.lib.exceptions import JsonableError-from zerver.lib.onboarding import send_initial_direct_messages_to_user+from zerver.lib.onboarding import get_custom_welcome_message_stringfrom zerver.lib.response import json_successfrom zerver.lib.typed_endpoint import typed_endpointfrom zerver.models.realms import Realm-from zerver.models.users import UserProfile+from zerver.models.users import UserProfile, get_system_bot@require_realm_admin@@ -29,9 +31,14 @@ def send_test_welcome_bot_custom_message(if len(welcome_message_custom_text) == 0:raise JsonableError(_("Message must not be empty"))- message_ids = send_initial_direct_messages_to_user(- user_profile, welcome_message_custom_text=welcome_message_custom_text+ welcome_bot_custom_message_string = get_custom_welcome_message_string(+ welcome_message_custom_text)- welcome_bot_custom_message_id = message_ids.welcome_bot_custom_message_id- assert welcome_bot_custom_message_id is not None- return json_success(request, data={"message_id": welcome_bot_custom_message_id})+ message_id = internal_send_private_message(+ get_system_bot(settings.WELCOME_BOT, user_profile.realm_id),+ user_profile,+ welcome_bot_custom_message_string,+ disable_external_notifications=True,+ )+ assert message_id is not None+ return json_success(request, data={"message_id": message_id})