@@ -52,7 +52,7 @@ public SkillDialog(
5252 _serviceClientCredentials = serviceClientCredentials ?? throw new ArgumentNullException ( nameof ( serviceClientCredentials ) ) ;
5353 _telemetryClient = telemetryClient ?? throw new ArgumentNullException ( nameof ( telemetryClient ) ) ;
5454 _userState = userState ;
55- _skillTransport = skillTransport ?? new SkillWebSocketTransport ( _skillManifest , _serviceClientCredentials , telemetryClient ) ;
55+ _skillTransport = skillTransport ?? new SkillWebSocketTransport ( telemetryClient ) ;
5656
5757 if ( authDialog != null )
5858 {
@@ -69,7 +69,7 @@ public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstan
6969 // to cancel all dialogs on the skill side
7070 if ( _skillTransport != null )
7171 {
72- await _skillTransport . CancelRemoteDialogsAsync ( turnContext ) ;
72+ await _skillTransport . CancelRemoteDialogsAsync ( _skillManifest , _serviceClientCredentials , turnContext ) ;
7373 }
7474 }
7575
@@ -91,55 +91,65 @@ public override async Task EndDialogAsync(ITurnContext turnContext, DialogInstan
9191 var accessor = _userState . CreateProperty < SkillContext > ( nameof ( SkillContext ) ) ;
9292 var skillContext = await accessor . GetAsync ( innerDc . Context , ( ) => new SkillContext ( ) ) ;
9393
94- /* In instances where the caller is able to identify/specify the action we process the Action specific slots
95- In other scenarios (aggregated skill dispatch) we evaluate all possible slots against context and pass across
96- enabling the Skill to perform it's own action identification. */
94+ var dialogOptions = options != null ? options as SkillDialogOption : null ;
95+ var actionName = dialogOptions ? . Action ;
9796
98- var actionName = options != null ? options as string : null ;
99- if ( actionName != null )
97+ var activity = innerDc . Context . Activity ;
98+
99+ // only set SemanticAction if it's not populated
100+ if ( activity . SemanticAction == null )
100101 {
101- // Find the specified within the selected Skill for slot filling evaluation
102- var action = _skillManifest . Actions . SingleOrDefault ( a => a . Id == actionName ) ;
103- if ( action != null )
102+ var semanticAction = new SemanticAction
104103 {
105- // If the action doesn't define any Slots or SkillContext is empty then we skip slot evaluation
106- if ( action . Definition . Slots != null && skillContext . Count > 0 )
104+ Id = actionName ,
105+ Entities = new Dictionary < string , Entity > ( ) ,
106+ } ;
107+
108+ if ( ! string . IsNullOrWhiteSpace ( actionName ) )
109+ {
110+ // only set the semantic state if action is not empty
111+ semanticAction . State = SkillConstants . SkillStart ;
112+
113+ // Find the specified action within the selected Skill for slot filling evaluation
114+ var action = _skillManifest . Actions . SingleOrDefault ( a => a . Id == actionName ) ;
115+ if ( action != null )
107116 {
108- // Match Slots to Skill Context
109- slots = await MatchSkillContextToSlots ( innerDc , action . Definition . Slots , skillContext ) ;
117+ // If the action doesn't define any Slots or SkillContext is empty then we skip slot evaluation
118+ if ( action . Definition . Slots != null && skillContext . Count > 0 )
119+ {
120+ // Match Slots to Skill Context
121+ slots = await MatchSkillContextToSlots ( innerDc , action . Definition . Slots , skillContext ) ;
122+ }
123+ }
124+ else
125+ {
126+ throw new ArgumentException ( $ "Passed Action ({ actionName } ) could not be found within the { _skillManifest . Id } skill manifest action definition.") ;
110127 }
111128 }
112129 else
113130 {
114- throw new ArgumentException ( $ "Passed Action ({ actionName } ) could not be found within the { _skillManifest . Id } skill manifest action definition.") ;
131+ // The caller hasn't got the capability of identifying the action as well as the Skill so we enumerate
132+ // actions and slot data to pass what we have
133+
134+ // Retrieve a distinct list of all slots, some actions may use the same slot so we use distinct to ensure we only get 1 instance.
135+ var skillSlots = _skillManifest . Actions . SelectMany ( s => s . Definition . Slots ) . Distinct ( new SlotEqualityComparer ( ) ) ;
136+ if ( skillSlots != null )
137+ {
138+ // Match Slots to Skill Context
139+ slots = await MatchSkillContextToSlots ( innerDc , skillSlots . ToList ( ) , skillContext ) ;
140+ }
115141 }
116- }
117- else
118- {
119- // The caller hasn't got the capability of identifying the action as well as the Skill so we enumerate
120- // actions and slot data to pass what we have
121142
122- // Retrieve a distinct list of all slots, some actions may use the same slot so we use distinct to ensure we only get 1 instance.
123- var skillSlots = _skillManifest . Actions . SelectMany ( s => s . Definition . Slots ) . Distinct ( new SlotEqualityComparer ( ) ) ;
124- if ( skillSlots != null )
143+ foreach ( var slot in slots )
125144 {
126- // Match Slots to Skill Context
127- slots = await MatchSkillContextToSlots ( innerDc , skillSlots . ToList ( ) , skillContext ) ;
145+ semanticAction . Entities . Add ( slot . Key , new Entity { Properties = slot . Value } ) ;
128146 }
147+
148+ activity . SemanticAction = semanticAction ;
129149 }
130150
131151 await innerDc . Context . SendActivityAsync ( new Activity ( type : ActivityTypes . Trace , text : $ "-->Handing off to the { _skillManifest . Name } skill.") ) ;
132152
133- var activity = innerDc . Context . Activity ;
134- var semanticAction = new SemanticAction { Entities = new Dictionary < string , Entity > ( ) } ;
135-
136- foreach ( var slot in slots )
137- {
138- semanticAction . Entities . Add ( slot . Key , new Entity { Properties = slot . Value } ) ;
139- }
140-
141- activity . SemanticAction = semanticAction ;
142-
143153 return await ForwardToSkillAsync ( innerDc , activity ) ;
144154 }
145155
@@ -215,7 +225,7 @@ private async Task<DialogTurnResult> ForwardToSkillAsync(DialogContext innerDc,
215225 {
216226 try
217227 {
218- var endOfConversation = await _skillTransport . ForwardToSkillAsync ( innerDc . Context , activity , GetTokenRequestCallback ( innerDc ) ) ;
228+ var endOfConversation = await _skillTransport . ForwardToSkillAsync ( _skillManifest , _serviceClientCredentials , innerDc . Context , activity , GetTokenRequestCallback ( innerDc ) ) ;
219229
220230 if ( endOfConversation )
221231 {
0 commit comments