We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Rename Recent topics to Recent conversations
Once #19449 has been resolved, we should rename Recent topics to Recent conversations across the board. This includes the left sidebar, documentation, settings menus, marketing pages, and anywhere else this term may be used.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `zerver/lib/onboarding.py`
Content:
```
1 from typing import Dict, List
2 
3 from django.conf import settings
4 from django.db import transaction
5 from django.db.models import Count
6 from django.utils.translation import gettext as _
7 from django.utils.translation import override as override_language
8 
9 from zerver.actions.create_realm import setup_realm_internal_bots
10 from zerver.actions.message_send import (
11     do_send_messages,
12     internal_prep_stream_message_by_name,
13     internal_send_private_message,
14 )
15 from zerver.actions.reactions import do_add_reaction
16 from zerver.lib.emoji import emoji_name_to_emoji_code
17 from zerver.lib.message import SendMessageRequest
18 from zerver.models import Message, Realm, UserProfile, get_system_bot
19 
20 
21 def missing_any_realm_internal_bots() -> bool:
22     bot_emails = [
23         bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,)
24         for bot in settings.REALM_INTERNAL_BOTS
25     ]
26     bot_counts = {
27         email: count
28         for email, count in UserProfile.objects.filter(email__in=bot_emails)
29         .values_list("email")
30         .annotate(Count("id"))
31     }
32     realm_count = Realm.objects.count()
33     return any(bot_counts.get(email, 0) < realm_count for email in bot_emails)
34 
35 
36 def create_if_missing_realm_internal_bots() -> None:
37     """This checks if there is any realm internal bot missing.
38 
39     If that is the case, it creates the missing realm internal bots.
40     """
41     if missing_any_realm_internal_bots():
42         for realm in Realm.objects.all():
43             setup_realm_internal_bots(realm)
44 
45 
46 def send_initial_pms(user: UserProfile) -> None:
47     organization_setup_text = ""
48 
49     # We need to override the language in this code path, because it's
50     # called from account registration, which is a pre-account API
51     # request and thus may not have the user's language context yet.
52     with override_language(user.default_language):
53         if user.is_realm_admin:
54             help_url = user.realm.uri + "/help/getting-your-organization-started-with-zulip"
55             organization_setup_text = (
56                 " " + _("We also have a guide for [Setting up your organization]({help_url}).")
57             ).format(help_url=help_url)
58 
59         welcome_msg = _("Hello, and welcome to Zulip!") + "👋"
60         demo_org_warning = ""
61         if user.realm.demo_organization_scheduled_deletion_date is not None:
62             demo_org_warning = (
63                 _(
64                     "Note that this is a [demo organization]({demo_org_help_url}) and will be "
65                     "**automatically deleted** in 30 days."
66                 )
67                 + "\n\n"
68             )
69 
70         content = "".join(
71             [
72                 welcome_msg + " ",
73                 _("This is a private message from me, Welcome Bot.") + "\n\n",
74                 _(
75                     "If you are new to Zulip, check out our [Getting started guide]({getting_started_url})!"
76                 ),
77                 "{organization_setup_text}" + "\n\n",
78                 "{demo_org_warning}",
79                 _(
80                     "I can also help you get set up! Just click anywhere on this message or press `r` to reply."
81                 )
82                 + "\n\n",
83                 _("Here are a few messages I understand:") + " ",
84                 bot_commands(),
85             ]
86         )
87 
88     content = content.format(
89         organization_setup_text=organization_setup_text,
90         demo_org_warning=demo_org_warning,
91         demo_org_help_url="/help/demo-organizations",
92         getting_started_url="/help/getting-started-with-zulip",
93     )
94 
95     internal_send_private_message(
96         get_system_bot(settings.WELCOME_BOT, user.realm_id), user, content
97     )
98 
99 
100 def bot_commands(no_help_command: bool = False) -> str:
101     commands = [
102         "apps",
103         "profile",
104         "theme",
105         "streams",
106         "topics",
107         "message formatting",
108         "keyboard shortcuts",
109     ]
110     if not no_help_command:
111         commands.append("help")
112     return ", ".join(["`" + command + "`" for command in commands]) + "."
113 
114 
115 def select_welcome_bot_response(human_response_lower: str) -> str:
116     # Given the raw (pre-markdown-rendering) content for a private
117     # message from the user to Welcome Bot, select the appropriate reply.
118     if human_response_lower in ["app", "apps"]:
119         return _(
120             "You can [download](/apps) the [mobile and desktop apps](/apps). "
121             "Zulip also works great in a browser."
122         )
123     elif human_response_lower == "profile":
124         return _(
125             "Go to [Profile settings](#settings/profile) "
126             "to add a [profile picture](/help/change-your-profile-picture) "
127             "and edit your [profile information](/help/edit-your-profile)."
128         )
129     elif human_response_lower == "theme":
130         return _(
131             "Go to [Display settings](#settings/display-settings) "
132             "to [switch between the light and dark themes](/help/dark-theme), "
133             "[pick your favorite emoji theme](/help/emoji-and-emoticons#change-your-emoji-set), "
134             "[change your language](/help/change-your-language), "
135             "and make other tweaks to your Zulip experience."
136         )
137     elif human_response_lower in ["stream", "streams", "channel", "channels"]:
138         return "".join(
139             [
140                 _(
141                     "In Zulip, streams [determine who gets a message](/help/streams-and-topics). "
142                     "They are similar to channels in other chat apps."
143                 )
144                 + "\n\n",
145                 _("[Browse and subscribe to streams](#streams/all)."),
146             ]
147         )
148     elif human_response_lower in ["topic", "topics"]:
149         return "".join(
150             [
151                 _(
152                     "In Zulip, topics [tell you what a message is about](/help/streams-and-topics). "
153                     "They are light-weight subjects, very similar to the subject line of an email."
154                 )
155                 + "\n\n",
156                 _(
157                     "Check out [Recent conversations](#recent_topics) to see what's happening! "
158                     'You can return to this conversation by clicking "Private messages" in the upper left.'
159                 ),
160             ]
161         )
162     elif human_response_lower in ["keyboard", "shortcuts", "keyboard shortcuts"]:
163         return "".join(
164             [
165                 _(
166                     "Zulip's [keyboard shortcuts](#keyboard-shortcuts) "
167                     "let you navigate the app quickly and efficiently."
168                 )
169                 + "\n\n",
170                 _("Press `?` any time to see a [cheat sheet](#keyboard-shortcuts)."),
171             ]
172         )
173     elif human_response_lower in ["formatting", "message formatting"]:
174         return "".join(
175             [
176                 _(
177                     "Zulip uses [Markdown](/help/format-your-message-using-markdown), "
178                     "an intuitive format for **bold**, *italics*, bulleted lists, and more. "
179                     "Click [here](#message-formatting) for a cheat sheet."
180                 )
181                 + "\n\n",
182                 _(
183                     "Check out our [messaging tips](/help/messaging-tips) "
184                     "to learn about emoji reactions, code blocks and much more!"
185                 ),
186             ]
187         )
188     elif human_response_lower in ["help", "?"]:
189         return "".join(
190             [
191                 _("Here are a few messages I understand:") + " ",
192                 bot_commands(no_help_command=True) + "\n\n",
193                 _(
194                     "Check out our [Getting started guide](/help/getting-started-with-zulip), "
195                     "or browse the [Help center](/help/) to learn more!"
196                 ),
197             ]
198         )
199     else:
200         return "".join(
201             [
202                 _(
203                     "I’m sorry, I did not understand your message. Please try one of the following commands:"
204                 )
205                 + " ",
206                 bot_commands(),
207             ]
208         )
209 
210 
211 def send_welcome_bot_response(send_request: SendMessageRequest) -> None:
212     """Given the send_request object for a private message from the user
213     to welcome-bot, trigger the welcome-bot reply."""
214     welcome_bot = get_system_bot(settings.WELCOME_BOT, send_request.message.sender.realm_id)
215     human_response_lower = send_request.message.content.lower()
216     content = select_welcome_bot_response(human_response_lower)
217     internal_send_private_message(welcome_bot, send_request.message.sender, content)
218 
219 
220 @transaction.atomic
221 def send_initial_realm_messages(realm: Realm) -> None:
222     welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)
223     # Make sure each stream created in the realm creation process has at least one message below
224     # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home
225     # view slightly less overwhelming
226     content_of_private_streams_topic = (
227         _("This is a private stream, as indicated by the lock icon next to the stream name.")
228         + " "
229         + _("Private streams are only visible to stream members.")
230         + "\n"
231         "\n"
232         + _(
233             "To manage this stream, go to [Stream settings]({stream_settings_url}) "
234             "and click on `{initial_private_stream_name}`."
235         )
236     ).format(
237         stream_settings_url="#streams/subscribed",
238         initial_private_stream_name=Realm.INITIAL_PRIVATE_STREAM_NAME,
239     )
240 
241     content1_of_topic_demonstration_topic = (
242         _(
243             "This is a message on stream #**{default_notification_stream_name}** with the "
244             "topic `topic demonstration`."
245         )
246     ).format(default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME)
247 
248     content2_of_topic_demonstration_topic = (
249         _("Topics are a lightweight tool to keep conversations organized.")
250         + " "
251         + _("You can learn more about topics at [Streams and topics]({about_topics_help_url}).")
252     ).format(about_topics_help_url="/help/streams-and-topics")
253 
254     content_of_swimming_turtles_topic = (
255         _(
256             "This is a message on stream #**{default_notification_stream_name}** with the "
257             "topic `swimming turtles`."
258         )
259         + "\n"
260         "\n"
261         "[](/static/images/cute/turtle.png)"
262         "\n"
263         "\n"
264         + _(
265             "[Start a new topic]({start_topic_help_url}) any time you're not replying to a \
266         previous message."
267         )
268     ).format(
269         default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
270         start_topic_help_url="/help/start-a-new-topic",
271     )
272 
273     welcome_messages: List[Dict[str, str]] = [
274         {
275             "stream": Realm.INITIAL_PRIVATE_STREAM_NAME,
276             "topic": "private streams",
277             "content": content_of_private_streams_topic,
278         },
279         {
280             "stream": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
281             "topic": "topic demonstration",
282             "content": content1_of_topic_demonstration_topic,
283         },
284         {
285             "stream": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
286             "topic": "topic demonstration",
287             "content": content2_of_topic_demonstration_topic,
288         },
289         {
290             "stream": realm.DEFAULT_NOTIFICATION_STREAM_NAME,
291             "topic": "swimming turtles",
292             "content": content_of_swimming_turtles_topic,
293         },
294     ]
295 
296     messages = [
297         internal_prep_stream_message_by_name(
298             realm,
299             welcome_bot,
300             message["stream"],
301             message["topic"],
302             message["content"],
303         )
304         for message in welcome_messages
305     ]
306     message_ids = do_send_messages(messages)
307 
308     # We find the one of our just-sent messages with turtle.png in it,
309     # and react to it.  This is a bit hacky, but works and is kinda a
310     # 1-off thing.
311     turtle_message = Message.objects.select_for_update().get(
312         id__in=message_ids, content__icontains="cute/turtle.png"
313     )
314     (emoji_code, reaction_type) = emoji_name_to_emoji_code(realm, "turtle")
315     do_add_reaction(welcome_bot, turtle_message, "turtle", emoji_code, reaction_type)
316
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.py
--- a/zerver/lib/onboarding.py
+++ b/zerver/lib/onboarding.py
@@ -154,7 +154,7 @@
                 )
                 + "\n\n",
                 _(
-                    "Check out [Recent conversations](#recent_topics) to see what's happening! "
+                    "Check out [Recent conversations](#recent) to see what's happening! "
                     'You can return to this conversation by clicking "Private messages" in the upper left.'
                 ),
             ]

{"golden_diff": "diff --git a/zerver/lib/onboarding.py b/zerver/lib/onboarding.py\n--- a/zerver/lib/onboarding.py\n+++ b/zerver/lib/onboarding.py\n@@ -154,7 +154,7 @@\n                 )\n                 + \"\\n\\n\",\n                 _(\n-                    \"Check out [Recent conversations](#recent_topics) to see what's happening! \"\n+                    \"Check out [Recent conversations](#recent) to see what's happening! \"\n                     'You can return to this conversation by clicking \"Private messages\" in the upper left.'\n                 ),\n             ]\n", "issue": "Rename Recent topics to Recent conversations\nOnce #19449 has been resolved, we should rename Recent topics to Recent conversations across the board. This includes the left sidebar, documentation, settings menus, marketing pages, and anywhere else this term may be used.\n", "before_files": [{"content": "from typing import Dict, List\n\nfrom django.conf import settings\nfrom django.db import transaction\nfrom django.db.models import Count\nfrom django.utils.translation import gettext as _\nfrom django.utils.translation import override as override_language\n\nfrom zerver.actions.create_realm import setup_realm_internal_bots\nfrom zerver.actions.message_send import (\n    do_send_messages,\n    internal_prep_stream_message_by_name,\n    internal_send_private_message,\n)\nfrom zerver.actions.reactions import do_add_reaction\nfrom zerver.lib.emoji import emoji_name_to_emoji_code\nfrom zerver.lib.message import SendMessageRequest\nfrom zerver.models import Message, Realm, UserProfile, get_system_bot\n\n\ndef missing_any_realm_internal_bots() -> bool:\n    bot_emails = [\n        bot[\"email_template\"] % (settings.INTERNAL_BOT_DOMAIN,)\n        for bot in settings.REALM_INTERNAL_BOTS\n    ]\n    bot_counts = {\n        email: count\n        for email, count in UserProfile.objects.filter(email__in=bot_emails)\n        .values_list(\"email\")\n        .annotate(Count(\"id\"))\n    }\n    realm_count = Realm.objects.count()\n    return any(bot_counts.get(email, 0) < realm_count for email in bot_emails)\n\n\ndef create_if_missing_realm_internal_bots() -> None:\n    \"\"\"This checks if there is any realm internal bot missing.\n\n    If that is the case, it creates the missing realm internal bots.\n    \"\"\"\n    if missing_any_realm_internal_bots():\n        for realm in Realm.objects.all():\n            setup_realm_internal_bots(realm)\n\n\ndef send_initial_pms(user: UserProfile) -> None:\n    organization_setup_text = \"\"\n\n    # We need to override the language in this code path, because it's\n    # called from account registration, which is a pre-account API\n    # request and thus may not have the user's language context yet.\n    with override_language(user.default_language):\n        if user.is_realm_admin:\n            help_url = user.realm.uri + \"/help/getting-your-organization-started-with-zulip\"\n            organization_setup_text = (\n                \" \" + _(\"We also have a guide for [Setting up your organization]({help_url}).\")\n            ).format(help_url=help_url)\n\n        welcome_msg = _(\"Hello, and welcome to Zulip!\") + \"\ud83d\udc4b\"\n        demo_org_warning = \"\"\n        if user.realm.demo_organization_scheduled_deletion_date is not None:\n            demo_org_warning = (\n                _(\n                    \"Note that this is a [demo organization]({demo_org_help_url}) and will be \"\n                    \"**automatically deleted** in 30 days.\"\n                )\n                + \"\\n\\n\"\n            )\n\n        content = \"\".join(\n            [\n                welcome_msg + \" \",\n                _(\"This is a private message from me, Welcome Bot.\") + \"\\n\\n\",\n                _(\n                    \"If you are new to Zulip, check out our [Getting started guide]({getting_started_url})!\"\n                ),\n                \"{organization_setup_text}\" + \"\\n\\n\",\n                \"{demo_org_warning}\",\n                _(\n                    \"I can also help you get set up! Just click anywhere on this message or press `r` to reply.\"\n                )\n                + \"\\n\\n\",\n                _(\"Here are a few messages I understand:\") + \" \",\n                bot_commands(),\n            ]\n        )\n\n    content = content.format(\n        organization_setup_text=organization_setup_text,\n        demo_org_warning=demo_org_warning,\n        demo_org_help_url=\"/help/demo-organizations\",\n        getting_started_url=\"/help/getting-started-with-zulip\",\n    )\n\n    internal_send_private_message(\n        get_system_bot(settings.WELCOME_BOT, user.realm_id), user, content\n    )\n\n\ndef bot_commands(no_help_command: bool = False) -> str:\n    commands = [\n        \"apps\",\n        \"profile\",\n        \"theme\",\n        \"streams\",\n        \"topics\",\n        \"message formatting\",\n        \"keyboard shortcuts\",\n    ]\n    if not no_help_command:\n        commands.append(\"help\")\n    return \", \".join([\"`\" + command + \"`\" for command in commands]) + \".\"\n\n\ndef select_welcome_bot_response(human_response_lower: str) -> str:\n    # Given the raw (pre-markdown-rendering) content for a private\n    # message from the user to Welcome Bot, select the appropriate reply.\n    if human_response_lower in [\"app\", \"apps\"]:\n        return _(\n            \"You can [download](/apps) the [mobile and desktop apps](/apps). \"\n            \"Zulip also works great in a browser.\"\n        )\n    elif human_response_lower == \"profile\":\n        return _(\n            \"Go to [Profile settings](#settings/profile) \"\n            \"to add a [profile picture](/help/change-your-profile-picture) \"\n            \"and edit your [profile information](/help/edit-your-profile).\"\n        )\n    elif human_response_lower == \"theme\":\n        return _(\n            \"Go to [Display settings](#settings/display-settings) \"\n            \"to [switch between the light and dark themes](/help/dark-theme), \"\n            \"[pick your favorite emoji theme](/help/emoji-and-emoticons#change-your-emoji-set), \"\n            \"[change your language](/help/change-your-language), \"\n            \"and make other tweaks to your Zulip experience.\"\n        )\n    elif human_response_lower in [\"stream\", \"streams\", \"channel\", \"channels\"]:\n        return \"\".join(\n            [\n                _(\n                    \"In Zulip, streams [determine who gets a message](/help/streams-and-topics). \"\n                    \"They are similar to channels in other chat apps.\"\n                )\n                + \"\\n\\n\",\n                _(\"[Browse and subscribe to streams](#streams/all).\"),\n            ]\n        )\n    elif human_response_lower in [\"topic\", \"topics\"]:\n        return \"\".join(\n            [\n                _(\n                    \"In Zulip, topics [tell you what a message is about](/help/streams-and-topics). \"\n                    \"They are light-weight subjects, very similar to the subject line of an email.\"\n                )\n                + \"\\n\\n\",\n                _(\n                    \"Check out [Recent conversations](#recent_topics) to see what's happening! \"\n                    'You can return to this conversation by clicking \"Private messages\" in the upper left.'\n                ),\n            ]\n        )\n    elif human_response_lower in [\"keyboard\", \"shortcuts\", \"keyboard shortcuts\"]:\n        return \"\".join(\n            [\n                _(\n                    \"Zulip's [keyboard shortcuts](#keyboard-shortcuts) \"\n                    \"let you navigate the app quickly and efficiently.\"\n                )\n                + \"\\n\\n\",\n                _(\"Press `?` any time to see a [cheat sheet](#keyboard-shortcuts).\"),\n            ]\n        )\n    elif human_response_lower in [\"formatting\", \"message formatting\"]:\n        return \"\".join(\n            [\n                _(\n                    \"Zulip uses [Markdown](/help/format-your-message-using-markdown), \"\n                    \"an intuitive format for **bold**, *italics*, bulleted lists, and more. \"\n                    \"Click [here](#message-formatting) for a cheat sheet.\"\n                )\n                + \"\\n\\n\",\n                _(\n                    \"Check out our [messaging tips](/help/messaging-tips) \"\n                    \"to learn about emoji reactions, code blocks and much more!\"\n                ),\n            ]\n        )\n    elif human_response_lower in [\"help\", \"?\"]:\n        return \"\".join(\n            [\n                _(\"Here are a few messages I understand:\") + \" \",\n                bot_commands(no_help_command=True) + \"\\n\\n\",\n                _(\n                    \"Check out our [Getting started guide](/help/getting-started-with-zulip), \"\n                    \"or browse the [Help center](/help/) to learn more!\"\n                ),\n            ]\n        )\n    else:\n        return \"\".join(\n            [\n                _(\n                    \"I\u2019m sorry, I did not understand your message. Please try one of the following commands:\"\n                )\n                + \" \",\n                bot_commands(),\n            ]\n        )\n\n\ndef send_welcome_bot_response(send_request: SendMessageRequest) -> None:\n    \"\"\"Given the send_request object for a private message from the user\n    to welcome-bot, trigger the welcome-bot reply.\"\"\"\n    welcome_bot = get_system_bot(settings.WELCOME_BOT, send_request.message.sender.realm_id)\n    human_response_lower = send_request.message.content.lower()\n    content = select_welcome_bot_response(human_response_lower)\n    internal_send_private_message(welcome_bot, send_request.message.sender, content)\n\n\n@transaction.atomic\ndef send_initial_realm_messages(realm: Realm) -> None:\n    welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)\n    # Make sure each stream created in the realm creation process has at least one message below\n    # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home\n    # view slightly less overwhelming\n    content_of_private_streams_topic = (\n        _(\"This is a private stream, as indicated by the lock icon next to the stream name.\")\n        + \" \"\n        + _(\"Private streams are only visible to stream members.\")\n        + \"\\n\"\n        \"\\n\"\n        + _(\n            \"To manage this stream, go to [Stream settings]({stream_settings_url}) \"\n            \"and click on `{initial_private_stream_name}`.\"\n        )\n    ).format(\n        stream_settings_url=\"#streams/subscribed\",\n        initial_private_stream_name=Realm.INITIAL_PRIVATE_STREAM_NAME,\n    )\n\n    content1_of_topic_demonstration_topic = (\n        _(\n            \"This is a message on stream #**{default_notification_stream_name}** with the \"\n            \"topic `topic demonstration`.\"\n        )\n    ).format(default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME)\n\n    content2_of_topic_demonstration_topic = (\n        _(\"Topics are a lightweight tool to keep conversations organized.\")\n        + \" \"\n        + _(\"You can learn more about topics at [Streams and topics]({about_topics_help_url}).\")\n    ).format(about_topics_help_url=\"/help/streams-and-topics\")\n\n    content_of_swimming_turtles_topic = (\n        _(\n            \"This is a message on stream #**{default_notification_stream_name}** with the \"\n            \"topic `swimming turtles`.\"\n        )\n        + \"\\n\"\n        \"\\n\"\n        \"[](/static/images/cute/turtle.png)\"\n        \"\\n\"\n        \"\\n\"\n        + _(\n            \"[Start a new topic]({start_topic_help_url}) any time you're not replying to a \\\n        previous message.\"\n        )\n    ).format(\n        default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n        start_topic_help_url=\"/help/start-a-new-topic\",\n    )\n\n    welcome_messages: List[Dict[str, str]] = [\n        {\n            \"stream\": Realm.INITIAL_PRIVATE_STREAM_NAME,\n            \"topic\": \"private streams\",\n            \"content\": content_of_private_streams_topic,\n        },\n        {\n            \"stream\": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"topic demonstration\",\n            \"content\": content1_of_topic_demonstration_topic,\n        },\n        {\n            \"stream\": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"topic demonstration\",\n            \"content\": content2_of_topic_demonstration_topic,\n        },\n        {\n            \"stream\": realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"swimming turtles\",\n            \"content\": content_of_swimming_turtles_topic,\n        },\n    ]\n\n    messages = [\n        internal_prep_stream_message_by_name(\n            realm,\n            welcome_bot,\n            message[\"stream\"],\n            message[\"topic\"],\n            message[\"content\"],\n        )\n        for message in welcome_messages\n    ]\n    message_ids = do_send_messages(messages)\n\n    # We find the one of our just-sent messages with turtle.png in it,\n    # and react to it.  This is a bit hacky, but works and is kinda a\n    # 1-off thing.\n    turtle_message = Message.objects.select_for_update().get(\n        id__in=message_ids, content__icontains=\"cute/turtle.png\"\n    )\n    (emoji_code, reaction_type) = emoji_name_to_emoji_code(realm, \"turtle\")\n    do_add_reaction(welcome_bot, turtle_message, \"turtle\", emoji_code, reaction_type)\n", "path": "zerver/lib/onboarding.py"}], "after_files": [{"content": "from typing import Dict, List\n\nfrom django.conf import settings\nfrom django.db import transaction\nfrom django.db.models import Count\nfrom django.utils.translation import gettext as _\nfrom django.utils.translation import override as override_language\n\nfrom zerver.actions.create_realm import setup_realm_internal_bots\nfrom zerver.actions.message_send import (\n    do_send_messages,\n    internal_prep_stream_message_by_name,\n    internal_send_private_message,\n)\nfrom zerver.actions.reactions import do_add_reaction\nfrom zerver.lib.emoji import emoji_name_to_emoji_code\nfrom zerver.lib.message import SendMessageRequest\nfrom zerver.models import Message, Realm, UserProfile, get_system_bot\n\n\ndef missing_any_realm_internal_bots() -> bool:\n    bot_emails = [\n        bot[\"email_template\"] % (settings.INTERNAL_BOT_DOMAIN,)\n        for bot in settings.REALM_INTERNAL_BOTS\n    ]\n    bot_counts = {\n        email: count\n        for email, count in UserProfile.objects.filter(email__in=bot_emails)\n        .values_list(\"email\")\n        .annotate(Count(\"id\"))\n    }\n    realm_count = Realm.objects.count()\n    return any(bot_counts.get(email, 0) < realm_count for email in bot_emails)\n\n\ndef create_if_missing_realm_internal_bots() -> None:\n    \"\"\"This checks if there is any realm internal bot missing.\n\n    If that is the case, it creates the missing realm internal bots.\n    \"\"\"\n    if missing_any_realm_internal_bots():\n        for realm in Realm.objects.all():\n            setup_realm_internal_bots(realm)\n\n\ndef send_initial_pms(user: UserProfile) -> None:\n    organization_setup_text = \"\"\n\n    # We need to override the language in this code path, because it's\n    # called from account registration, which is a pre-account API\n    # request and thus may not have the user's language context yet.\n    with override_language(user.default_language):\n        if user.is_realm_admin:\n            help_url = user.realm.uri + \"/help/getting-your-organization-started-with-zulip\"\n            organization_setup_text = (\n                \" \" + _(\"We also have a guide for [Setting up your organization]({help_url}).\")\n            ).format(help_url=help_url)\n\n        welcome_msg = _(\"Hello, and welcome to Zulip!\") + \"\ud83d\udc4b\"\n        demo_org_warning = \"\"\n        if user.realm.demo_organization_scheduled_deletion_date is not None:\n            demo_org_warning = (\n                _(\n                    \"Note that this is a [demo organization]({demo_org_help_url}) and will be \"\n                    \"**automatically deleted** in 30 days.\"\n                )\n                + \"\\n\\n\"\n            )\n\n        content = \"\".join(\n            [\n                welcome_msg + \" \",\n                _(\"This is a private message from me, Welcome Bot.\") + \"\\n\\n\",\n                _(\n                    \"If you are new to Zulip, check out our [Getting started guide]({getting_started_url})!\"\n                ),\n                \"{organization_setup_text}\" + \"\\n\\n\",\n                \"{demo_org_warning}\",\n                _(\n                    \"I can also help you get set up! Just click anywhere on this message or press `r` to reply.\"\n                )\n                + \"\\n\\n\",\n                _(\"Here are a few messages I understand:\") + \" \",\n                bot_commands(),\n            ]\n        )\n\n    content = content.format(\n        organization_setup_text=organization_setup_text,\n        demo_org_warning=demo_org_warning,\n        demo_org_help_url=\"/help/demo-organizations\",\n        getting_started_url=\"/help/getting-started-with-zulip\",\n    )\n\n    internal_send_private_message(\n        get_system_bot(settings.WELCOME_BOT, user.realm_id), user, content\n    )\n\n\ndef bot_commands(no_help_command: bool = False) -> str:\n    commands = [\n        \"apps\",\n        \"profile\",\n        \"theme\",\n        \"streams\",\n        \"topics\",\n        \"message formatting\",\n        \"keyboard shortcuts\",\n    ]\n    if not no_help_command:\n        commands.append(\"help\")\n    return \", \".join([\"`\" + command + \"`\" for command in commands]) + \".\"\n\n\ndef select_welcome_bot_response(human_response_lower: str) -> str:\n    # Given the raw (pre-markdown-rendering) content for a private\n    # message from the user to Welcome Bot, select the appropriate reply.\n    if human_response_lower in [\"app\", \"apps\"]:\n        return _(\n            \"You can [download](/apps) the [mobile and desktop apps](/apps). \"\n            \"Zulip also works great in a browser.\"\n        )\n    elif human_response_lower == \"profile\":\n        return _(\n            \"Go to [Profile settings](#settings/profile) \"\n            \"to add a [profile picture](/help/change-your-profile-picture) \"\n            \"and edit your [profile information](/help/edit-your-profile).\"\n        )\n    elif human_response_lower == \"theme\":\n        return _(\n            \"Go to [Display settings](#settings/display-settings) \"\n            \"to [switch between the light and dark themes](/help/dark-theme), \"\n            \"[pick your favorite emoji theme](/help/emoji-and-emoticons#change-your-emoji-set), \"\n            \"[change your language](/help/change-your-language), \"\n            \"and make other tweaks to your Zulip experience.\"\n        )\n    elif human_response_lower in [\"stream\", \"streams\", \"channel\", \"channels\"]:\n        return \"\".join(\n            [\n                _(\n                    \"In Zulip, streams [determine who gets a message](/help/streams-and-topics). \"\n                    \"They are similar to channels in other chat apps.\"\n                )\n                + \"\\n\\n\",\n                _(\"[Browse and subscribe to streams](#streams/all).\"),\n            ]\n        )\n    elif human_response_lower in [\"topic\", \"topics\"]:\n        return \"\".join(\n            [\n                _(\n                    \"In Zulip, topics [tell you what a message is about](/help/streams-and-topics). \"\n                    \"They are light-weight subjects, very similar to the subject line of an email.\"\n                )\n                + \"\\n\\n\",\n                _(\n                    \"Check out [Recent conversations](#recent) to see what's happening! \"\n                    'You can return to this conversation by clicking \"Private messages\" in the upper left.'\n                ),\n            ]\n        )\n    elif human_response_lower in [\"keyboard\", \"shortcuts\", \"keyboard shortcuts\"]:\n        return \"\".join(\n            [\n                _(\n                    \"Zulip's [keyboard shortcuts](#keyboard-shortcuts) \"\n                    \"let you navigate the app quickly and efficiently.\"\n                )\n                + \"\\n\\n\",\n                _(\"Press `?` any time to see a [cheat sheet](#keyboard-shortcuts).\"),\n            ]\n        )\n    elif human_response_lower in [\"formatting\", \"message formatting\"]:\n        return \"\".join(\n            [\n                _(\n                    \"Zulip uses [Markdown](/help/format-your-message-using-markdown), \"\n                    \"an intuitive format for **bold**, *italics*, bulleted lists, and more. \"\n                    \"Click [here](#message-formatting) for a cheat sheet.\"\n                )\n                + \"\\n\\n\",\n                _(\n                    \"Check out our [messaging tips](/help/messaging-tips) \"\n                    \"to learn about emoji reactions, code blocks and much more!\"\n                ),\n            ]\n        )\n    elif human_response_lower in [\"help\", \"?\"]:\n        return \"\".join(\n            [\n                _(\"Here are a few messages I understand:\") + \" \",\n                bot_commands(no_help_command=True) + \"\\n\\n\",\n                _(\n                    \"Check out our [Getting started guide](/help/getting-started-with-zulip), \"\n                    \"or browse the [Help center](/help/) to learn more!\"\n                ),\n            ]\n        )\n    else:\n        return \"\".join(\n            [\n                _(\n                    \"I\u2019m sorry, I did not understand your message. Please try one of the following commands:\"\n                )\n                + \" \",\n                bot_commands(),\n            ]\n        )\n\n\ndef send_welcome_bot_response(send_request: SendMessageRequest) -> None:\n    \"\"\"Given the send_request object for a private message from the user\n    to welcome-bot, trigger the welcome-bot reply.\"\"\"\n    welcome_bot = get_system_bot(settings.WELCOME_BOT, send_request.message.sender.realm_id)\n    human_response_lower = send_request.message.content.lower()\n    content = select_welcome_bot_response(human_response_lower)\n    internal_send_private_message(welcome_bot, send_request.message.sender, content)\n\n\n@transaction.atomic\ndef send_initial_realm_messages(realm: Realm) -> None:\n    welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)\n    # Make sure each stream created in the realm creation process has at least one message below\n    # Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home\n    # view slightly less overwhelming\n    content_of_private_streams_topic = (\n        _(\"This is a private stream, as indicated by the lock icon next to the stream name.\")\n        + \" \"\n        + _(\"Private streams are only visible to stream members.\")\n        + \"\\n\"\n        \"\\n\"\n        + _(\n            \"To manage this stream, go to [Stream settings]({stream_settings_url}) \"\n            \"and click on `{initial_private_stream_name}`.\"\n        )\n    ).format(\n        stream_settings_url=\"#streams/subscribed\",\n        initial_private_stream_name=Realm.INITIAL_PRIVATE_STREAM_NAME,\n    )\n\n    content1_of_topic_demonstration_topic = (\n        _(\n            \"This is a message on stream #**{default_notification_stream_name}** with the \"\n            \"topic `topic demonstration`.\"\n        )\n    ).format(default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME)\n\n    content2_of_topic_demonstration_topic = (\n        _(\"Topics are a lightweight tool to keep conversations organized.\")\n        + \" \"\n        + _(\"You can learn more about topics at [Streams and topics]({about_topics_help_url}).\")\n    ).format(about_topics_help_url=\"/help/streams-and-topics\")\n\n    content_of_swimming_turtles_topic = (\n        _(\n            \"This is a message on stream #**{default_notification_stream_name}** with the \"\n            \"topic `swimming turtles`.\"\n        )\n        + \"\\n\"\n        \"\\n\"\n        \"[](/static/images/cute/turtle.png)\"\n        \"\\n\"\n        \"\\n\"\n        + _(\n            \"[Start a new topic]({start_topic_help_url}) any time you're not replying to a \\\n        previous message.\"\n        )\n    ).format(\n        default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n        start_topic_help_url=\"/help/start-a-new-topic\",\n    )\n\n    welcome_messages: List[Dict[str, str]] = [\n        {\n            \"stream\": Realm.INITIAL_PRIVATE_STREAM_NAME,\n            \"topic\": \"private streams\",\n            \"content\": content_of_private_streams_topic,\n        },\n        {\n            \"stream\": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"topic demonstration\",\n            \"content\": content1_of_topic_demonstration_topic,\n        },\n        {\n            \"stream\": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"topic demonstration\",\n            \"content\": content2_of_topic_demonstration_topic,\n        },\n        {\n            \"stream\": realm.DEFAULT_NOTIFICATION_STREAM_NAME,\n            \"topic\": \"swimming turtles\",\n            \"content\": content_of_swimming_turtles_topic,\n        },\n    ]\n\n    messages = [\n        internal_prep_stream_message_by_name(\n            realm,\n            welcome_bot,\n            message[\"stream\"],\n            message[\"topic\"],\n            message[\"content\"],\n        )\n        for message in welcome_messages\n    ]\n    message_ids = do_send_messages(messages)\n\n    # We find the one of our just-sent messages with turtle.png in it,\n    # and react to it.  This is a bit hacky, but works and is kinda a\n    # 1-off thing.\n    turtle_message = Message.objects.select_for_update().get(\n        id__in=message_ids, content__icontains=\"cute/turtle.png\"\n    )\n    (emoji_code, reaction_type) = emoji_name_to_emoji_code(realm, \"turtle\")\n    do_add_reaction(welcome_bot, turtle_message, \"turtle\", emoji_code, reaction_type)\n", "path": "zerver/lib/onboarding.py"}]}