Skip to content

Commit 1c627fe

Browse files
authored
Merge pull request RasaHQ#5362 from RasaHQ/empty-message
strip responses before splitting them on newlines
2 parents c62b0db + 7a8e6c7 commit 1c627fe

File tree

13 files changed

+35
-18
lines changed

13 files changed

+35
-18
lines changed

changelog/5361.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed bug where starting or ending a response with ``\n\n`` led to one of the responses returned being empty.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"fixed_sidebar": True,
140140
"product": "Rasa",
141141
"base_url": "https://rasa.com/docs/rasa/",
142-
"canonical_url": "https://rasa.com/docs/rasa/"
142+
"canonical_url": "https://rasa.com/docs/rasa/",
143143
}
144144
# html_theme_options = {}
145145

rasa/core/channels/botframework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def send(self, message_data: Dict[Text, Any]) -> None:
109109
async def send_text_message(
110110
self, recipient_id: Text, text: Text, **kwargs: Any
111111
) -> None:
112-
for message_part in text.split("\n\n"):
112+
for message_part in text.strip().split("\n\n"):
113113
text_message = {"text": message_part}
114114
message = self.prepare_message(recipient_id, text_message)
115115
await self.send(message)

rasa/core/channels/channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ async def _persist_message(self, message: Dict[Text, Any]) -> None:
324324
async def send_text_message(
325325
self, recipient_id: Text, text: Text, **kwargs: Any
326326
) -> None:
327-
for message_part in text.split("\n\n"):
327+
for message_part in text.strip().split("\n\n"):
328328
await self._persist_message(self._message(recipient_id, text=message_part))
329329

330330
async def send_image_url(

rasa/core/channels/facebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async def send_text_message(
148148
) -> None:
149149
"""Send a message through this channel."""
150150

151-
for message_part in text.split("\n\n"):
151+
for message_part in text.strip().split("\n\n"):
152152
self.send(recipient_id, FBText(text=message_part))
153153

154154
async def send_image_url(

rasa/core/channels/mattermost.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _post_data_to_channel(self, data) -> Response:
6565
async def send_text_message(
6666
self, recipient_id: Text, text: Text, **kwargs: Any
6767
) -> None:
68-
for message_part in text.split("\n\n"):
68+
for message_part in text.strip().split("\n\n"):
6969
self._post_message_to_channel(self.bot_channel, message_part)
7070

7171
async def send_custom_json(

rasa/core/channels/rocketchat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def send_text_message(
3636
) -> None:
3737
"""Send message to output channel"""
3838

39-
for message_part in text.split("\n\n"):
39+
for message_part in text.strip().split("\n\n"):
4040
self.rocket.chat_post_message(message_part, room_id=recipient_id)
4141

4242
async def send_image_url(

rasa/core/channels/slack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def send_text_message(
3434
self, recipient_id: Text, text: Text, **kwargs: Any
3535
) -> None:
3636
recipient = self.slack_channel or recipient_id
37-
for message_part in text.split("\n\n"):
37+
for message_part in text.strip().split("\n\n"):
3838
await self.client.chat_postMessage(
3939
channel=recipient, as_user=True, text=message_part, type="mrkdwn",
4040
)

rasa/core/channels/socketio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async def send_text_message(
4343
) -> None:
4444
"""Send a message through this channel."""
4545

46-
for message_part in text.split("\n\n"):
46+
for message_part in text.strip().split("\n\n"):
4747
await self._send_message(self.sid, {"text": message_part})
4848

4949
async def send_image_url(
@@ -66,7 +66,7 @@ async def send_text_with_buttons(
6666
# split text and create a message for each text fragment
6767
# the `or` makes sure there is at least one message we can attach the quick
6868
# replies to
69-
message_parts = text.split("\n\n") or [text]
69+
message_parts = text.strip().split("\n\n") or [text]
7070
messages = [{"text": message, "quick_replies": []} for message in message_parts]
7171

7272
# attach all buttons to the last text fragment

rasa/core/channels/telegram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, access_token: Optional[Text]) -> None:
3232
async def send_text_message(
3333
self, recipient_id: Text, text: Text, **kwargs: Any
3434
) -> None:
35-
for message_part in text.split("\n\n"):
35+
for message_part in text.strip().split("\n\n"):
3636
self.send_message(recipient_id, message_part)
3737

3838
async def send_image_url(

0 commit comments

Comments
 (0)