4
4
from copy import deepcopy
5
5
from typing import List
6
6
7
+ from botframework .connector .token_api .models import TokenExchangeRequest
7
8
from botbuilder .schema import (
8
9
Activity ,
9
10
ActivityTypes ,
22
23
DialogReason ,
23
24
DialogInstance ,
24
25
)
25
- from botframework .connector .token_api .models import TokenExchangeRequest
26
26
27
27
from .begin_skill_dialog_options import BeginSkillDialogOptions
28
28
from .skill_dialog_options import SkillDialogOptions
29
29
30
30
31
31
class SkillDialog (Dialog ):
32
+ SKILLCONVERSATIONIDSTATEKEY = (
33
+ "Microsoft.Bot.Builder.Dialogs.SkillDialog.SkillConversationId"
34
+ )
35
+
32
36
def __init__ (self , dialog_options : SkillDialogOptions , dialog_id : str ):
33
37
super ().__init__ (dialog_id )
34
38
if not dialog_options :
@@ -65,8 +69,18 @@ async def begin_dialog(self, dialog_context: DialogContext, options: object = No
65
69
self ._deliver_mode_state_key
66
70
] = dialog_args .activity .delivery_mode
67
71
72
+ # Create the conversationId and store it in the dialog context state so we can use it later
73
+ skill_conversation_id = await self ._create_skill_conversation_id (
74
+ dialog_context .context , dialog_context .context .activity
75
+ )
76
+ dialog_context .active_dialog .state [
77
+ SkillDialog .SKILLCONVERSATIONIDSTATEKEY
78
+ ] = skill_conversation_id
79
+
68
80
# Send the activity to the skill.
69
- eoc_activity = await self ._send_to_skill (dialog_context .context , skill_activity )
81
+ eoc_activity = await self ._send_to_skill (
82
+ dialog_context .context , skill_activity , skill_conversation_id
83
+ )
70
84
if eoc_activity :
71
85
return await dialog_context .end_dialog (eoc_activity .value )
72
86
@@ -101,7 +115,12 @@ async def continue_dialog(self, dialog_context: DialogContext):
101
115
]
102
116
103
117
# Just forward to the remote skill
104
- eoc_activity = await self ._send_to_skill (dialog_context .context , skill_activity )
118
+ skill_conversation_id = dialog_context .active_dialog .state [
119
+ SkillDialog .SKILLCONVERSATIONIDSTATEKEY
120
+ ]
121
+ eoc_activity = await self ._send_to_skill (
122
+ dialog_context .context , skill_activity , skill_conversation_id
123
+ )
105
124
if eoc_activity :
106
125
return await dialog_context .end_dialog (eoc_activity .value )
107
126
@@ -123,7 +142,8 @@ async def reprompt_dialog( # pylint: disable=unused-argument
123
142
)
124
143
125
144
# connection Name is not applicable for a RePrompt, as we don't expect as OAuthCard in response.
126
- await self ._send_to_skill (context , reprompt_event )
145
+ skill_conversation_id = instance .state [SkillDialog .SKILLCONVERSATIONIDSTATEKEY ]
146
+ await self ._send_to_skill (context , reprompt_event , skill_conversation_id )
127
147
128
148
async def resume_dialog ( # pylint: disable=unused-argument
129
149
self , dialog_context : "DialogContext" , reason : DialogReason , result : object
@@ -152,7 +172,10 @@ async def end_dialog(
152
172
activity .additional_properties = context .activity .additional_properties
153
173
154
174
# connection Name is not applicable for an EndDialog, as we don't expect as OAuthCard in response.
155
- await self ._send_to_skill (context , activity )
175
+ skill_conversation_id = instance .state [
176
+ SkillDialog .SKILLCONVERSATIONIDSTATEKEY
177
+ ]
178
+ await self ._send_to_skill (context , activity , skill_conversation_id )
156
179
157
180
await super ().end_dialog (context , instance , reason )
158
181
@@ -187,18 +210,14 @@ def _on_validate_activity(
187
210
return True
188
211
189
212
async def _send_to_skill (
190
- self , context : TurnContext , activity : Activity
213
+ self , context : TurnContext , activity : Activity , skill_conversation_id : str
191
214
) -> Activity :
192
215
if activity .type == ActivityTypes .invoke :
193
216
# Force ExpectReplies for invoke activities so we can get the replies right away and send
194
217
# them back to the channel if needed. This makes sure that the dialog will receive the Invoke
195
218
# response from the skill and any other activities sent, including EoC.
196
219
activity .delivery_mode = DeliveryModes .expect_replies
197
220
198
- skill_conversation_id = await self ._create_skill_conversation_id (
199
- context , activity
200
- )
201
-
202
221
# Always save state before forwarding
203
222
# (the dialog stack won't get updated with the skillDialog and things won't work if you don't)
204
223
await self .dialog_options .conversation_state .save_changes (context , True )
0 commit comments