Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
onboarding: Modify message that welcome bot does not understand.
codewithnickb926ae0904a6
diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.pyindex a841a77bcd4..e1fd3f62e52 100644--- a/zerver/lib/onboarding.py+++ b/zerver/lib/onboarding.py@@ -197,7 +197,25 @@ def send_welcome_bot_response(send_request: SendMessageRequest) -> None:to welcome-bot, trigger the welcome-bot reply."""welcome_bot = get_system_bot(settings.WELCOME_BOT, send_request.realm.id)human_response_lower = send_request.message.content.lower()+ human_user_recipient_id = send_request.message.sender.recipient_id+ assert human_user_recipient_id is not Nonecontent = select_welcome_bot_response(human_response_lower)+ realm_id = send_request.realm.id+ commands = bot_commands()+ if (+ commands in content+ and Message.objects.filter(+ realm_id=realm_id,+ sender_id=welcome_bot.id,+ recipient_id=human_user_recipient_id,+ content__icontains=commands,+ ).exists()+ # Uses index 'zerver_message_realm_sender_recipient'+ ):+ # If the bot has already sent bot commands to this user and+ # if the bot does not understand the current message sent by this user then+ # do not send any message+ returninternal_send_private_message(welcome_bot,diff --git a/zerver/models/messages.py b/zerver/models/messages.pyindex 0ae380d3a6d..6b2b9d8c18c 100644--- a/zerver/models/messages.py+++ b/zerver/models/messages.py@@ -186,6 +186,7 @@ class Message(AbstractMessage):# receiver. The prefix of this index (realm_id,# sender_id) can be used for scrubbing users and/or# deleting users' messages.+ # Also used in send_welcome_bot_response"realm_id","sender_id","recipient_id",diff --git a/zerver/tests/test_tutorial.py b/zerver/tests/test_tutorial.pyindex 43f67ea065e..df04fe05d06 100644--- a/zerver/tests/test_tutorial.py+++ b/zerver/tests/test_tutorial.py@@ -164,14 +164,27 @@ class TutorialTests(ZulipTestCase):bot = get_system_bot(settings.WELCOME_BOT, user.realm_id)messages = ["Hello", "HAHAHA", "OKOK", "LalulaLapas"]self.login_user(user)+ # First undefined message sent.+ self.send_personal_message(user, bot, "Hello")+ expected_response = (+ "You can chat with me as much as you like! To get help, try one of the following messages: "+ "`apps`, `profile`, `theme`, `channels`, "+ "`topics`, `message formatting`, `keyboard shortcuts`, `help`."+ )+ self.assertEqual(most_recent_message(user).content, expected_response)++ # For future undefined messages, welcome bot won't send a reply.for content in messages:self.send_personal_message(user, bot, content)- expected_response = (- "You can chat with me as much as you like! To get help, try one of the following messages: "- "`apps`, `profile`, `theme`, `channels`, "- "`topics`, `message formatting`, `keyboard shortcuts`, `help`."- )- self.assertEqual(most_recent_message(user).content, expected_response)+ self.assertEqual(most_recent_message(user).content, content)++ # Check if Welcome bot still replies for bot commands+ self.send_personal_message(user, bot, "apps")+ expected_response = (+ "You can [download](/apps/) the [mobile and desktop apps](/apps/). "+ "Zulip also works great in a browser."+ )+ self.assertEqual(most_recent_message(user).content, expected_response)def test_no_response_to_group_pm(self) -> None:user1 = self.example_user("hamlet")