Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ATO-1151] Parentheses in button title overwrite button payload in rasa shell #12534

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/12534.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rich responses containing buttons with parentheses characters are now correctly parsed.
Previously any characters found between the first identified pair of `()` in response button took precedence.
2 changes: 1 addition & 1 deletion rasa/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ async def payload_from_button_question(button_question: "Question") -> Text:
response = await button_question.ask_async()
if response != FREE_TEXT_INPUT_PROMPT:
# Extract intent slash command if it's a button
response = response[response.find("(") + 1 : response.find(")")]
response = response[response.rfind("(") + 1 : response.rfind(")")]
return response


Expand Down
16 changes: 16 additions & 0 deletions tests/cli/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
import rasa.shared.utils.io
from tests.cli.conftest import RASA_EXE
from tests.conftest import AsyncMock


@contextlib.contextmanager
Expand Down Expand Up @@ -355,3 +356,18 @@ def test_validate_assistant_id_in_config_preserves_comment() -> None:

# reset input files to original state
rasa.shared.utils.io.write_yaml(original_config_data, config_file, True)


@pytest.mark.parametrize(
"text_input, button",
[
("hi this is test text\n", "hi this is test text"),
("hi this is test text (/button_one)", "/button_one"),
("hi this is test text (and something) (/button_one)", "/button_one"),
ancalita marked this conversation as resolved.
Show resolved Hide resolved
],
)
async def test_payload_from_button_question(text_input: str, button: str) -> None:
question = AsyncMock()
question.ask_async.return_value = text_input
result = await rasa.cli.utils.payload_from_button_question(question)
assert result == button