Skip to content

Commit

Permalink
Merge pull request #113 from GoogleCloudPlatform/bug/misc
Browse files Browse the repository at this point in the history
Bug/misc
  • Loading branch information
kmaphoenix authored Mar 27, 2023
2 parents ec49fc4 + 98143ab commit 5c2a450
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/dfcx_scrapi/builders/intents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 + " "
Expand Down
8 changes: 5 additions & 3 deletions src/dfcx_scrapi/core/transition_route_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down
12 changes: 9 additions & 3 deletions src/dfcx_scrapi/tools/webhook_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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': {
Expand Down

0 comments on commit 5c2a450

Please sign in to comment.