diff --git a/actions/execute_transfer.py b/actions/execute_transfer.py index 34e4081..474d819 100644 --- a/actions/execute_transfer.py +++ b/actions/execute_transfer.py @@ -1,3 +1,4 @@ +import re from typing import Any, Dict from datetime import datetime from rasa_sdk import Action, Tracker @@ -6,6 +7,9 @@ from actions.db import get_account, write_account, add_transaction, Transaction +AMOUNT_OF_MONEY_REGEX = re.compile(r"\d*[.,]*\d+") + + class ExecuteTransfer(Action): def name(self) -> str: @@ -25,7 +29,7 @@ def run(self, dispatcher: CollectingDispatcher, if recipient == "Jack": return [SlotSet("transfer_money_transfer_successful", False)] - amount_of_money_value = float(amount_of_money.replace("$", "").replace("USD", "").strip()) + amount_of_money_value = float(re.findall(AMOUNT_OF_MONEY_REGEX, amount_of_money)[0]) account.funds -= amount_of_money_value new_transaction = \ Transaction(datetime=datetime.now().isoformat(), recipient=recipient,