Greg Thompson commited on
Commit
25fedb7
1 Parent(s): 9da4a02

Update conversation_manager functions to handle a new event data object

Browse files
Files changed (2) hide show
  1. app.py +25 -7
  2. mathtext_fastapi/conversation_manager.py +0 -4
app.py CHANGED
@@ -52,6 +52,31 @@ def text2int_ep(content: Text = None):
52
 
53
  @app.post("/manager")
54
  async def programmatic_message_manager(request: Request):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  data_dict = await request.json()
56
  context = manage_conversational_response(data_dict)
57
  return JSONResponse(context)
@@ -68,15 +93,8 @@ async def evaluate_user_message_with_nlu_api(request: Request):
68
  {'type':'integer', 'data': '8'}
69
  {'type':'sentiment', 'data': 'negative'}
70
  """
71
-
72
- print("REQUEST")
73
- print(request)
74
-
75
  data_dict = await request.json()
76
 
77
- print("DATA DICT")
78
- print(data_dict)
79
-
80
  message_data = data_dict.get('message_data', '')
81
  message_text = message_data['message']['text']['body']
82
 
 
52
 
53
  @app.post("/manager")
54
  async def programmatic_message_manager(request: Request):
55
+ """
56
+ Calls the conversation management function to determine what to send to the user based on the current state and user response
57
+
58
+ Input
59
+ request.body: dict - a json object of message data for the most recent user response
60
+ {
61
+ author_id: "+47897891",
62
+ author_type: "OWNER",
63
+ message_body: "a test message",
64
+ message_direction: "inbound",
65
+ message_id: "ABJAK64jlk3-agjkl2QHFAFH",
66
+ message_inserted_at: "2022-07-05T04:00:34.03352Z",
67
+ message_updated_at: "2023-02-14T03:54:19.342950Z",
68
+ }
69
+
70
+ Output
71
+ context: dict - a json object that holds the information for the current state
72
+ {
73
+ "user": "47897891",
74
+ "state": "welcome-message-state",
75
+ "bot_message": "Welcome to Rori!",
76
+ "user_message": "",
77
+ "type": "ask"
78
+ }
79
+ """
80
  data_dict = await request.json()
81
  context = manage_conversational_response(data_dict)
82
  return JSONResponse(context)
 
93
  {'type':'integer', 'data': '8'}
94
  {'type':'sentiment', 'data': 'negative'}
95
  """
 
 
 
 
96
  data_dict = await request.json()
97
 
 
 
 
98
  message_data = data_dict.get('message_data', '')
99
  message_text = message_data['message']['text']['body']
100
 
mathtext_fastapi/conversation_manager.py CHANGED
@@ -40,7 +40,6 @@ def create_button_objects(button_options):
40
  - button_arr: list - a list of button objects that use a template filled with the input values
41
 
42
  NOTE: Not fully implemented and tested
43
-
44
  """
45
  button_arr = []
46
  for option in button_options:
@@ -66,7 +65,6 @@ def create_interactive_message(message_text, button_options, whatsapp_id):
66
  - message_text: str - the content that the message should display
67
  - button_options: list - what each button option should display
68
  - whatsapp_id: str - the message recipient's phone number
69
-
70
  """
71
  button_arr = create_button_objects(button_options)
72
 
@@ -98,7 +96,6 @@ def return_next_conversational_state(context_data, user_message):
98
  Output
99
  - message_package: dict - a series of messages and user input to send the user
100
  """
101
-
102
  if context_data['user_message'] == '' and context_data['state'] == 'start-conversation':
103
  message_package = {
104
  'messages': [],
@@ -159,7 +156,6 @@ def manage_conversational_response(data_json):
159
  - review ways for more robust error handling
160
  - need to make util functions that apply to both /nlu and /conversation_manager
161
  """
162
-
163
  message_data = data_json.get('message_data', '')
164
  context_data = data_json.get('context_data', '')
165
 
 
40
  - button_arr: list - a list of button objects that use a template filled with the input values
41
 
42
  NOTE: Not fully implemented and tested
 
43
  """
44
  button_arr = []
45
  for option in button_options:
 
65
  - message_text: str - the content that the message should display
66
  - button_options: list - what each button option should display
67
  - whatsapp_id: str - the message recipient's phone number
 
68
  """
69
  button_arr = create_button_objects(button_options)
70
 
 
96
  Output
97
  - message_package: dict - a series of messages and user input to send the user
98
  """
 
99
  if context_data['user_message'] == '' and context_data['state'] == 'start-conversation':
100
  message_package = {
101
  'messages': [],
 
156
  - review ways for more robust error handling
157
  - need to make util functions that apply to both /nlu and /conversation_manager
158
  """
 
159
  message_data = data_json.get('message_data', '')
160
  context_data = data_json.get('context_data', '')
161