36
36
ReminderScheduled ,
37
37
SlotSet ,
38
38
UserUttered ,
39
+ SessionStarted ,
39
40
)
40
41
from rasa .core .interpreter import (
41
42
INTENT_MESSAGE_PREFIX ,
@@ -149,7 +150,10 @@ async def predict_next(self, sender_id: Text) -> Optional[Dict[Text, Any]]:
149
150
}
150
151
151
152
async def _update_tracker_session (
152
- self , tracker : DialogueStateTracker , output_channel : OutputChannel
153
+ self ,
154
+ tracker : DialogueStateTracker ,
155
+ output_channel : OutputChannel ,
156
+ metadata : Optional [Dict ] = None ,
153
157
) -> None :
154
158
"""Check the current session in `tracker` and update it if expired.
155
159
@@ -158,6 +162,7 @@ async def _update_tracker_session(
158
162
restart are considered).
159
163
160
164
Args:
165
+ metadata: Data sent from client associated with the incoming user message.
161
166
tracker: Tracker to inspect.
162
167
output_channel: Output channel for potential utterances in a custom
163
168
`ActionSessionStart`.
@@ -167,6 +172,9 @@ async def _update_tracker_session(
167
172
f"Starting a new session for conversation ID '{ tracker .sender_id } '."
168
173
)
169
174
175
+ if metadata :
176
+ tracker .events .append (SessionStarted (metadata = metadata ))
177
+
170
178
await self ._run_action (
171
179
action = self ._get_action (ACTION_SESSION_START_NAME ),
172
180
tracker = tracker ,
@@ -175,13 +183,17 @@ async def _update_tracker_session(
175
183
)
176
184
177
185
async def get_tracker_with_session_start (
178
- self , sender_id : Text , output_channel : Optional [OutputChannel ] = None
186
+ self ,
187
+ sender_id : Text ,
188
+ output_channel : Optional [OutputChannel ] = None ,
189
+ metadata : Optional [Dict ] = None ,
179
190
) -> Optional [DialogueStateTracker ]:
180
191
"""Get tracker for `sender_id` or create a new tracker for `sender_id`.
181
192
182
193
If a new tracker is created, `action_session_start` is run.
183
194
184
195
Args:
196
+ metadata: Data sent from client associated with the incoming user message.
185
197
output_channel: Output channel associated with the incoming user message.
186
198
sender_id: Conversation ID for which to fetch the tracker.
187
199
@@ -193,7 +205,7 @@ async def get_tracker_with_session_start(
193
205
if not tracker :
194
206
return None
195
207
196
- await self ._update_tracker_session (tracker , output_channel )
208
+ await self ._update_tracker_session (tracker , output_channel , metadata )
197
209
198
210
return tracker
199
211
@@ -233,7 +245,7 @@ async def log_message(
233
245
# we have a Tracker instance for each user
234
246
# which maintains conversation state
235
247
tracker = await self .get_tracker_with_session_start (
236
- message .sender_id , message .output_channel
248
+ message .sender_id , message .output_channel , message . metadata
237
249
)
238
250
239
251
if tracker :
@@ -291,10 +303,12 @@ def predict_next_action(
291
303
action = self .domain .action_for_index (
292
304
max_confidence_index , self .action_endpoint
293
305
)
306
+
294
307
logger .debug (
295
308
f"Predicted next action '{ action .name ()} ' with confidence "
296
309
f"{ action_confidences [max_confidence_index ]:.2f} ."
297
310
)
311
+
298
312
return action , policy , action_confidences [max_confidence_index ]
299
313
300
314
@staticmethod
0 commit comments