diff --git a/src/dfcx_scrapi/builders/intents.py b/src/dfcx_scrapi/builders/intents.py index 124dbe05..0a99f3bc 100644 --- a/src/dfcx_scrapi/builders/intents.py +++ b/src/dfcx_scrapi/builders/intents.py @@ -60,6 +60,7 @@ def _include_spaces_to_phrase(self, phrase: List[str], annots: List[str]): A list of strings that represents parameter_id of each part in phrase. """ + chars_to_ignore_at_beginning = ["'", ",", ".", "?", "!"] i = 0 while True: p_curr, a_curr = phrase[i], annots[i] @@ -73,7 +74,13 @@ def _include_spaces_to_phrase(self, phrase: List[str], annots: List[str]): annots.insert(i+1, "") i += 2 elif a_curr and not a_next: - phrase[i+1] = " " + p_next + flag = any( + ch + for ch in chars_to_ignore_at_beginning + if p_next.startswith(ch) + ) + if not flag: + phrase[i+1] = " " + p_next i += 1 elif not a_curr and a_next: phrase[i] = p_curr + " " diff --git a/src/dfcx_scrapi/core/transition_route_groups.py b/src/dfcx_scrapi/core/transition_route_groups.py index 0d9990c9..96e6343e 100644 --- a/src/dfcx_scrapi/core/transition_route_groups.py +++ b/src/dfcx_scrapi/core/transition_route_groups.py @@ -320,9 +320,11 @@ def route_groups_to_dataframe( temp_dict.update({"route_group_name": route_group.display_name}) if route.target_page: - temp_dict.update( - {"target_page": all_pages_map[route.target_page]} - ) + t_p = all_pages_map.get(route.target_page) + if not t_p: + t_p = str(route.target_page).rsplit("/", maxsplit=1)[-1] + + temp_dict.update({"target_page": t_p}) if route.intent: temp_dict.update({"intent": intents_map[route.intent]}) diff --git a/src/dfcx_scrapi/tools/webhook_util.py b/src/dfcx_scrapi/tools/webhook_util.py index 6bddb296..197a93c8 100644 --- a/src/dfcx_scrapi/tools/webhook_util.py +++ b/src/dfcx_scrapi/tools/webhook_util.py @@ -74,7 +74,9 @@ def build_session_info(parameters): return session_info @staticmethod - def build_response(response_text=None, page_info=None, session_info=None): + def build_response( + response_text=None, page_info=None, session_info=None, append=False + ): """Builds a Response object for Dialogflow CX. Provides the JSON object structure expected by DFCX for the Response @@ -85,12 +87,16 @@ def build_response(response_text=None, page_info=None, session_info=None): response_text: The text response to be displayed to the user. Can also be empty string if no response to the user is required. page_info: (Optional) The JSON object returned by build_page_info() - session_info: (Optiona) The JSON object returned by + session_info: (Optional) The JSON object returned by build_session_info() + append: (Optional) Whether messages will append or replace to + the list of messages waiting to be sent to the user. If append + set to False it will replace the messages. """ + action = 'APPEND' if append else 'REPLACE' if response_text: response_object = { - 'mergeBehavior': 'REPLACE', + 'mergeBehavior': action, 'messages': [ { 'text': {