@@ -60,12 +60,22 @@ CopilotClient GetClient(AgentApplication app, ITurnContext turnContext)
60
60
"mcs" ) ;
61
61
}
62
62
63
+ app . OnMessage ( "signout" , async ( turnContext , turnState , cancellationToken ) =>
64
+ {
65
+ // Force a user signout to reset the user state
66
+ // This is needed to reset the token in Azure Bot Services if needed.
67
+ // Typically this wouldn't be need in a production Agent. Made available to assist it starting from scratch.
68
+ await app . UserAuthorization . SignOutUserAsync ( turnContext , turnState , cancellationToken : cancellationToken ) ;
69
+ await turnContext . SendActivityAsync ( "You have signed out" , cancellationToken : cancellationToken ) ;
70
+ } , rank : RouteRank . First ) ;
71
+
63
72
// Since Auto SignIn is enabled, by the time this is called the token is already available via UserAuthorization.GetTurnTokenAsync or
64
73
// UserAuthorization.ExchangeTurnTokenAsync.
65
74
// NOTE: This is a slightly unusual way to handle incoming Activities (but perfectly) valid. For this sample,
66
75
// we just want to proxy messages to/from a Copilot Studio Agent.
67
76
app . OnActivity ( ( turnContext , cancellationToken ) => Task . FromResult ( true ) , async ( turnContext , turnState , cancellationToken ) =>
68
77
{
78
+
69
79
var mcsConversationId = turnState . Conversation . GetValue < string > ( MCSConversationPropertyName ) ;
70
80
var cpsClient = GetClient ( app , turnContext ) ;
71
81
@@ -94,7 +104,10 @@ CopilotClient GetClient(AgentApplication app, ITurnContext turnContext)
94
104
}
95
105
}
96
106
}
97
- } ) ;
107
+ } , autoSignInHandlers : [ "mcs" ] ) ;
108
+
109
+
110
+
98
111
99
112
app . UserAuthorization . OnUserSignInFailure ( async ( turnContext , turnState , handlerName , response , initiatingActivity , cancellationToken ) =>
100
113
{
0 commit comments