using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Teams; using Microsoft.Bot.Schema; using Microsoft.Bot.Builder.Dialogs; namespace {Your_NameSpace}.SSO; public class TeamsSsoBot : TeamsActivityHandler where T : Dialog { private readonly ILogger> _logger; private readonly BotState _conversationState; private readonly Dialog _dialog; private readonly IStatePropertyAccessor _dialogState; public TeamsSsoBot(ConversationState conversationState, T dialog, ILogger> logger) { _conversationState = conversationState; _dialog = dialog; _logger = logger; _dialogState = _conversationState.CreateProperty("DialogState"); ((SsoDialog)_dialog).addCommand("showUserInfo", "show", SsoOperations.ShowUserInfo); } protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) { _logger.LogInformation("Receive message activity"); await ((SsoDialog)_dialog).RunAsync(turnContext, _dialogState); } protected override async Task OnTeamsSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken) { _logger.LogInformation("Receive invoke activity of teams sign in verify state"); await _dialog.RunAsync(turnContext, _conversationState.CreateProperty(nameof(DialogState)), cancellationToken); } protected override async Task OnSignInInvokeAsync(ITurnContext turnContext, CancellationToken cancellationToken) { _logger.LogInformation("Receive invoke activity of sign in"); await _dialog.RunAsync(turnContext, _conversationState.CreateProperty(nameof(DialogState)), cancellationToken); } public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { await base.OnTurnAsync(turnContext, cancellationToken); await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken).ConfigureAwait(false); } }