3
3
4
4
from datetime import datetime , timedelta
5
5
from threading import Lock
6
+ from warnings import warn
6
7
7
8
from botbuilder .core import (
8
9
BotAdapter ,
12
13
TurnContext ,
13
14
)
14
15
from botbuilder .core .skills import SkillConversationReference , SkillHandler
15
- from botbuilder .dialogs .memory import (
16
- DialogStateManager ,
17
- DialogStateManagerConfiguration ,
18
- )
16
+ from botbuilder .dialogs .memory import DialogStateManagerConfiguration
19
17
from botbuilder .schema import Activity , ActivityTypes , EndOfConversationCodes
20
18
from botframework .connector .auth import (
21
19
AuthenticationConstants ,
27
25
from .dialog import Dialog
28
26
from .dialog_context import DialogContext
29
27
from .dialog_events import DialogEvents
28
+ from .dialog_extensions import DialogExtensions
30
29
from .dialog_set import DialogSet
31
30
from .dialog_state import DialogState
32
31
from .dialog_manager_result import DialogManagerResult
@@ -142,60 +141,10 @@ async def on_turn(self, context: TurnContext) -> DialogManagerResult:
142
141
# Create DialogContext
143
142
dialog_context = DialogContext (self .dialogs , context , dialog_state )
144
143
145
- # promote initial TurnState into dialog_context.services for contextual services
146
- for key , service in dialog_context .services .items ():
147
- dialog_context .services [key ] = service
148
-
149
- # map TurnState into root dialog context.services
150
- for key , service in context .turn_state .items ():
151
- dialog_context .services [key ] = service
152
-
153
- # get the DialogStateManager configuration
154
- dialog_state_manager = DialogStateManager (
155
- dialog_context , self .state_configuration
144
+ # Call the common dialog "continue/begin" execution pattern shared with the classic RunAsync extension method
145
+ turn_result = await DialogExtensions ._internal_run ( # pylint: disable=protected-access
146
+ context , self ._root_dialog_id , dialog_context
156
147
)
157
- await dialog_state_manager .load_all_scopes ()
158
- dialog_context .context .turn_state [
159
- dialog_state_manager .__class__ .__name__
160
- ] = dialog_state_manager
161
-
162
- turn_result : DialogTurnResult = None
163
-
164
- # Loop as long as we are getting valid OnError handled we should continue executing the actions for the turn.
165
-
166
- # NOTE: We loop around this block because each pass through we either complete the turn and break out of the
167
- # loop or we have had an exception AND there was an OnError action which captured the error. We need to
168
- # continue the turn based on the actions the OnError handler introduced.
169
- end_of_turn = False
170
- while not end_of_turn :
171
- try :
172
- claims_identity : ClaimsIdentity = context .turn_state .get (
173
- BotAdapter .BOT_IDENTITY_KEY , None
174
- )
175
- if isinstance (
176
- claims_identity , ClaimsIdentity
177
- ) and SkillValidation .is_skill_claim (claims_identity .claims ):
178
- # The bot is running as a skill.
179
- turn_result = await self .handle_skill_on_turn (dialog_context )
180
- else :
181
- # The bot is running as root bot.
182
- turn_result = await self .handle_bot_on_turn (dialog_context )
183
-
184
- # turn successfully completed, break the loop
185
- end_of_turn = True
186
- except Exception as err :
187
- # fire error event, bubbling from the leaf. <
57D8
/div>
188
- handled = await dialog_context .emit_event (
189
- DialogEvents .error , err , bubble = True , from_leaf = True
190
- )
191
-
192
- if not handled :
193
- # error was NOT handled, throw the exception and end the turn. (This will trigger the
194
- # Adapter.OnError handler and end the entire dialog stack)
195
- raise
196
-
197
- # save all state scopes to their respective botState locations.
198
- await dialog_state_manager .save_all_changes ()
199
148
200
149
# save BotState changes
201
150
await bot_state_set .save_all_changes (dialog_context .context , False )
@@ -204,25 +153,22 @@ async def on_turn(self, context: TurnContext) -> DialogManagerResult:
204
153
205
154
@staticmethod
206
155
async def send_state_snapshot_trace (
207
- dialog_context : DialogContext , trace_label : str
156
+ dialog_context : DialogContext ,
157
+ trace_label : str = None , # pylint: disable=unused-argument
208
158
):
209
159
"""
210
160
Helper to send a trace activity with a memory snapshot of the active dialog DC.
211
161
:param dialog_context:
212
162
:param trace_label:
213
163
:return:
214
164
"""
215
- # send trace of memory
216
- snapshot = DialogManager .get_active_dialog_context (
165
+ warn (
166
+ "This method will be deprecated as no longer is necesary" ,
167
+ PendingDeprecationWarning ,
168
+ )
169
+ await DialogExtensions ._send_state_snapshot_trace ( # pylint: disable=protected-access
217
170
dialog_context
218
- ).state .get_memory_snapshot ()
219
- trace_activity = Activity .create_trace_activity (
220
- "BotState" ,
221
- "https://www.botframework.com/schemas/botState" ,
222
- snapshot ,
223
- trace_label ,
224
171
)
225
- await dialog_context .context .send_activity (trace_activity )
226
172
227
173
@staticmethod
228
174
def is_from_parent_to_skill (turn_context : TurnContext ) -> bool :
@@ -246,11 +192,13 @@ def get_active_dialog_context(dialog_context: DialogContext) -> DialogContext:
246
192
:param dialog_context:
247
193
:return:
248
194
"""
249
- child = dialog_context .child
250
- if not child :
251
- return dialog_context
252
-
253
- return DialogManager .get_active_dialog_context (child )
195
+ warn (
196
+ "This method will be deprecated as no longer is necesary" ,
197
+ PendingDeprecationWarning ,
198
+ )
199
+ return DialogExtensions ._get_active_dialog_context ( # pylint: disable=protected-access
200
+ dialog_context
201
+ )
254
202
255
203
@staticmethod
256
204
def should_send_end_of_conversation_to_parent (
@@ -294,6 +242,10 @@ def should_send_end_of_conversation_to_parent(
294
242
async def handle_skill_on_turn (
295
243
self , dialog_context : DialogContext
296
244
) -> DialogTurnResult :
245
+ warn (
246
+ "This method will be deprecated as no longer is necesary" ,
247
+ PendingDeprecationWarning ,
248
+ )
297
249
# the bot is running as a skill.
298
250
turn_context = dialog_context .context
299
251
@@ -348,6 +300,10 @@ async def handle_skill_on_turn(
348
300
async def handle_bot_on_turn (
349
301
self , dialog_context : DialogContext
350
302
) -> DialogTurnResult :
303
+ warn (
304
+ "This method will be deprecated as no longer is necesary" ,
305
+ PendingDeprecationWarning ,
306
+ )
351
307
# the bot is running as a root bot.
352
308
if dialog_context .active_dialog is None :
353
309
# start root dialog
0 commit comments