Refactored 18.bot-authentication to match other samples by tracyboehrer · Pull Request #968 · microsoft/botbuilder-java · GitHub
Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
import com.microsoft.bot.dialogs.Dialog;
import com.microsoft.bot.schema.ChannelAccount;

import org.springframework.stereotype.Component;
import com.codepoetics.protonpack.collectors.CompletableFutures;
import com.microsoft.bot.schema.Activity;
import org.apache.commons.lang3.StringUtils;


// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

@Component
public class AuthBot extends DialogBot<MainDialog> {

public AuthBot(ConversationState conversationState, UserState userState, MainDialog dialog) {
Expand All @@ -49,7 +43,7 @@ protected CompletableFuture<Void> onMembersAdded(
@Override
protected CompletableFuture<Void> onTokenResponseEvent(TurnContext turnContext) {
// Run the Dialog with the new Token Response Event Activity.
return Dialog.run(dialog, turnContext, conversationState.createProperty("DialogState"));
return Dialog.run(dialog, turnContext, conversationState.createProperty("DialogState"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
import java.util.concurrent.CompletableFuture;

/**
* This Bot implementation can run any type of Dialog. The use of type parameterization is to
* allows multiple different bots to be run at different endpoints within the same project. This
* can be achieved by defining distinct Controller types each with dependency on distinct IBot
* types, this way ASP Dependency Injection can glue everything together without ambiguity. The
* ConversationState is used by the Dialog system. The UserState isn't, however, it might have
* been used in a Dialog implementation, and the requirement is that all BotState objects are
* saved at the end of a turn.
* This Bot implementation can run any type of Dialog. The use of type parameterization is to allows
* multiple different bots to be run at different endpoints within the same project. This can be
* achieved by defining distinct Controller types each with dependency on distinct IBot types, this
* way ASP Dependency Injection can glue everything together without ambiguity. The
* ConversationState is used by the Dialog system. The UserState isn't, however, it might have been
* used in a Dialog implementation, and the requirement is that all BotState objects are saved at
* the end of a turn.
*/
public class DialogBot<T extends Dialog> extends ActivityHandler {

protected Dialog dialog;
protected BotState conversationState;
protected BotState userState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public LogoutDialog(String id, String connectionName) {


@Override
protected CompletableFuture<DialogTurnResult> onBeginDialog(DialogContext innerDc, Object options) {
DialogTurnResult result = interrupt(innerDc).join();
protected CompletableFuture<DialogTurnResult> onBeginDialog(
DialogContext innerDc, Object options
) {
DialogTurnResult result = interrupt(innerDc).join();
if (result != null) {
return CompletableFuture.completedFuture(result);
}
Expand All @@ -34,7 +36,7 @@ protected CompletableFuture<DialogTurnResult> onBeginDialog(DialogContext innerD

@Override
protected CompletableFuture<DialogTurnResult> onContinueDialog(DialogContext innerDc) {
DialogTurnResult result = interrupt(innerDc).join();
DialogTurnResult result = interrupt(innerDc).join();
if (result != null) {
return CompletableFuture.completedFuture(result);
}
Expand All @@ -48,10 +50,12 @@ private CompletableFuture<DialogTurnResult> interrupt(DialogContext innerDc) {

if (text.equals("logout")) {
// The bot adapter encapsulates the authentication processes.
BotFrameworkAdapter botAdapter = (BotFrameworkAdapter) innerDc.getContext().getAdapter();
BotFrameworkAdapter botAdapter = (BotFrameworkAdapter) innerDc.getContext()
.getAdapter();
botAdapter.signOutUser(innerDc.getContext(), getConnectionName(), null).join();
innerDc.getContext().sendActivity(MessageFactory.text("You have been signed out.")).join();
return innerDc.cancelAllDialogs();
innerDc.getContext().sendActivity(MessageFactory.text("You have been signed out."))
.join();
return innerDc.cancelAllDialogs();
}
}

Expand Down