refactor: Update true/false response methods to return None (#5001)

* ♻️ (conditional_router.py): refactor ConditionalRouterComponent to return None instead of self.message when condition is not met to improve code clarity and consistency

* 🐛 (conditional_router.py): fix issue where None was being returned instead of an empty string in certain cases to improve consistency and avoid potential errors

* ♻️ (conditional_router.py): Update return type of true_response and false_response methods to allow returning either Message or str for better flexibility and compatibility with different response types.
This commit is contained in:
Cristhian Zanforlin Lousa 2024-12-03 16:58:23 -03:00 committed by GitHub
commit 5145b7496c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -94,7 +94,7 @@ class ConditionalRouterComponent(Component):
route_to_stop = "true_result" if route_to_stop == "false_result" else "false_result"
self.stop(route_to_stop)
def true_response(self) -> Message:
def true_response(self) -> Message | str:
result = self.evaluate_condition(
self.input_text, self.match_text, self.operator, case_sensitive=self.case_sensitive
)
@ -103,9 +103,9 @@ class ConditionalRouterComponent(Component):
self.iterate_and_stop_once("false_result")
return self.message
self.iterate_and_stop_once("true_result")
return self.message
return ""
def false_response(self) -> Message:
def false_response(self) -> Message | str:
result = self.evaluate_condition(
self.input_text, self.match_text, self.operator, case_sensitive=self.case_sensitive
)
@ -114,4 +114,4 @@ class ConditionalRouterComponent(Component):
self.iterate_and_stop_once("true_result")
return self.message
self.iterate_and_stop_once("false_result")
return self.message
return ""