Skip to content

Commit

Permalink
fix button question
Browse files Browse the repository at this point in the history
  • Loading branch information
Urkem committed Jun 20, 2023
1 parent 06128ba commit 3f0693b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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
15 changes: 15 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,17 @@ 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"),
]
)
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

0 comments on commit 3f0693b

Please sign in to comment.