From be3fb0c2f7ccc012314eba83b832b360c3a72348 Mon Sep 17 00:00:00 2001
From: tracyboehrer
Date: Tue, 9 Feb 2021 12:34:07 -0600
Subject: [PATCH] Refactored samples to use @Bean method for Bot instead of
@Component.
---
.../bot/sample/echo/Application.java | 35 ++++++++---
.../microsoft/bot/sample/echo/EchoBot.java | 2 -
.../bot/sample/welcomeuser/Application.java | 37 ++++++++----
.../sample/welcomeuser/WelcomeUserBot.java | 2 -
.../sample/multiturnprompt/Application.java | 58 +++++++++++++++----
.../bot/sample/multiturnprompt/DialogBot.java | 2 -
.../multiturnprompt/UserProfileDialog.java | 2 -
.../bot/sample/usingcards/Application.java | 58 +++++++++++++++----
.../bot/sample/usingcards/MainDialog.java | 2 -
.../bot/sample/usingcards/RichCardsBot.java | 7 +--
.../sample/suggestedactions/Application.java | 36 ++++++++----
.../suggestedactions/SuggestedActionsBot.java | 2 -
.../bot/sample/proactive/Application.java | 49 +++++++++++-----
.../bot/sample/proactive/ProactiveBot.java | 7 ++-
.../bot/sample/multilingual/Application.java | 35 +++++++----
.../sample/multilingual/MultiLingualBot.java | 1 -
.../promptusersforinput/Application.java | 41 +++++++++----
.../promptusersforinput/CustomPromptBot.java | 1 -
.../sample/statemanagement/Application.java | 41 +++++++++----
.../statemanagement/StateManagementBot.java | 1 -
.../bot/sample/inspection/Application.java | 49 ++++++++++------
.../bot/sample/inspection/EchoBot.java | 1 -
.../pom.xml | 2 +-
.../bot/sample/teamssearch/Application.java | 42 ++++++++++----
.../TeamsMessagingExtensionsSearchBot.java | 2 -
.../bot/sample/teamsaction/Application.java | 42 ++++++++++----
.../TeamsMessagingExtensionsActionBot.java | 2 -
.../pom.xml | 4 +-
.../sample/teamssearchauth/Application.java | 47 +++++++++++----
...essagingExtensionsSearchAuthConfigBot.java | 2 -
.../teamsactionpreview/Application.java | 42 ++++++++++----
...msMessagingExtensionsActionPreviewBot.java | 2 -
.../sample/teamstaskmodule/Application.java | 42 ++++++++++----
.../teamstaskmodule/TeamsTaskModuleBot.java | 6 +-
.../bot/sample/teamsunfurl/Application.java | 42 ++++++++++----
.../sample/teamsunfurl/LinkUnfurlingBot.java | 2 -
.../sample/teamsfileupload/Application.java | 42 ++++++++++----
.../teamsfileupload/TeamsFileUploadBot.java | 3 -
.../sample/teamsconversation/Application.java | 36 ++++++++----
.../TeamsConversationBot.java | 2 -
.../teamsstartnewthread/Application.java | 42 ++++++++++----
.../TeamsStartNewThreadBot.java | 2 -
42 files changed, 611 insertions(+), 264 deletions(-)
diff --git a/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/Application.java b/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/Application.java
index dfdcb0731..cc7014c76 100644
--- a/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/Application.java
+++ b/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/Application.java
@@ -3,6 +3,7 @@
package com.microsoft.bot.sample.echo;
+import com.microsoft.bot.builder.Bot;
import com.microsoft.bot.integration.AdapterWithErrorHandler;
import com.microsoft.bot.integration.BotFrameworkHttpAdapter;
import com.microsoft.bot.integration.Configuration;
@@ -10,31 +11,47 @@
import com.microsoft.bot.integration.spring.BotDependencyConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
-/**
- * This is the starting point of the Sprint Boot Bot application.
- *
- * This class also provides overrides for dependency injections. A class that extends the {@link
- * com.microsoft.bot.builder.Bot} interface should be annotated with @Component.
- *
- * @see EchoBot
- */
+//
+// This is the starting point of the Sprint Boot Bot application.
+//
@SpringBootApplication
// Use the default BotController to receive incoming Channel messages. A custom
// controller could be used by eliminating this import and creating a new
-// RestController.
+// org.springframework.web.bind.annotation.RestController.
// The default controller is created by the Spring Boot container using
// dependency injection. The default route is /api/messages.
@Import({BotController.class})
+/**
+ * This class extends the BotDependencyConfiguration which provides the default
+ * implementations for a Bot application. The Application class should
+ * override methods in order to provide custom implementations.
+ */
public class Application extends BotDependencyConfiguration {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+ /**
+ * Returns the Bot for this application.
+ *
+ *
+ * The @Component annotation could be used on the Bot class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Bot implementation for this application.
+ */
+ @Bean
+ public Bot getBot() {
+ return new EchoBot();
+ }
+
/**
* Returns a custom Adapter that provides error handling.
*
diff --git a/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/EchoBot.java b/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/EchoBot.java
index d6c5c2e0f..e34b01416 100644
--- a/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/EchoBot.java
+++ b/samples/02.echo-bot/src/main/java/com/microsoft/bot/sample/echo/EchoBot.java
@@ -9,7 +9,6 @@
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.schema.ChannelAccount;
import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -23,7 +22,6 @@
* #onMembersAdded(List, TurnContext)} will send a greeting to new conversation participants.
*
*/
-@Component
public class EchoBot extends ActivityHandler {
@Override
diff --git a/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/Application.java b/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/Application.java
index 6931438e5..78f74fe9d 100644
--- a/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/Application.java
+++ b/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/Application.java
@@ -3,6 +3,8 @@
package com.microsoft.bot.sample.welcomeuser;
+import com.microsoft.bot.builder.Bot;
+import com.microsoft.bot.builder.UserState;
import com.microsoft.bot.integration.AdapterWithErrorHandler;
import com.microsoft.bot.integration.BotFrameworkHttpAdapter;
import com.microsoft.bot.integration.Configuration;
@@ -10,31 +12,46 @@
import com.microsoft.bot.integration.spring.BotDependencyConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
-/**
- * This is the starting point of the Sprint Boot Bot application.
- *
- * This class also provides overrides for dependency injections. A class that
- * extends the {@link com.microsoft.bot.builder.Bot} interface should be
- * annotated with @Component.
- *
- * @see WelcomeUserBot
- */
+//
+// This is the starting point of the Sprint Boot Bot application.
+//
@SpringBootApplication
// Use the default BotController to receive incoming Channel messages. A custom
// controller could be used by eliminating this import and creating a new
-// RestController.
+// org.springframework.web.bind.annotation.RestController.
// The default controller is created by the Spring Boot container using
// dependency injection. The default route is /api/messages.
@Import({BotController.class})
+/**
+ * This class extends the BotDependencyConfiguration which provides the default
+ * implementations for a Bot application. The Application class should
+ * override methods in order to provide custom implementations.
+ */
public class Application extends BotDependencyConfiguration {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+ /**
+ * Returns the Bot for this application.
+ *
+ *
+ * The @Component annotation could be used on the Bot class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Bot implementation for this application.
+ */
+ @Bean
+ public Bot getBot(UserState userState) {
+ return new WelcomeUserBot(userState);
+ }
+
/**
* Returns a custom Adapter that provides error handling.
*
diff --git a/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/WelcomeUserBot.java b/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/WelcomeUserBot.java
index ab9a14b4d..c0a1e94a6 100644
--- a/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/WelcomeUserBot.java
+++ b/samples/03.welcome-user/src/main/java/com/microsoft/bot/sample/welcomeuser/WelcomeUserBot.java
@@ -18,7 +18,6 @@
import com.microsoft.bot.schema.ResourceResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Collections;
@@ -36,7 +35,6 @@
*
* @see WelcomeUserState
*/
-@Component
public class WelcomeUserBot extends ActivityHandler {
// Messages sent to the user.
private static final String WELCOMEMESSAGE =
diff --git a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/Application.java b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/Application.java
index 1324a2348..32ac57561 100644
--- a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/Application.java
+++ b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/Application.java
@@ -3,6 +3,10 @@
package com.microsoft.bot.sample.multiturnprompt;
+import com.microsoft.bot.builder.Bot;
+import com.microsoft.bot.builder.ConversationState;
+import com.microsoft.bot.builder.UserState;
+import com.microsoft.bot.dialogs.Dialog;
import com.microsoft.bot.integration.AdapterWithErrorHandler;
import com.microsoft.bot.integration.BotFrameworkHttpAdapter;
import com.microsoft.bot.integration.Configuration;
@@ -10,31 +14,65 @@
import com.microsoft.bot.integration.spring.BotDependencyConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
-/**
- * This is the starting point of the Sprint Boot Bot application.
- *
- * This class also provides overrides for dependency injections. A class that
- * extends the {@link com.microsoft.bot.builder.Bot} interface should be
- * annotated with @Component.
- *
- * @see DialogBot
- */
+//
+// This is the starting point of the Sprint Boot Bot application.
+//
@SpringBootApplication
// Use the default BotController to receive incoming Channel messages. A custom
// controller could be used by eliminating this import and creating a new
-// RestController.
+// org.springframework.web.bind.annotation.RestController.
// The default controller is created by the Spring Boot container using
// dependency injection. The default route is /api/messages.
@Import({BotController.class})
+/**
+ * This class extends the BotDependencyConfiguration which provides the default
+ * implementations for a Bot application. The Application class should
+ * override methods in order to provide custom implementations.
+ */
public class Application extends BotDependencyConfiguration {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+ /**
+ * Returns the Bot for this application.
+ *
+ *
+ * The @Component annotation could be used on the Bot class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Bot implementation for this application.
+ */
+ @Bean
+ public Bot getBot(
+ ConversationState conversationState,
+ UserState userState,
+ Dialog dialog
+ ) {
+ return new DialogBot(conversationState, userState, dialog);
+ }
+
+ /**
+ * Returns the starting Dialog for this application.
+ *
+ *
+ * The @Component annotation could be used on the Dialog class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Dialog implementation for this application.
+ */
+ @Bean
+ public Dialog getRootDialog(UserState userState) {
+ return new UserProfileDialog(userState);
+ }
+
/**
* Returns a custom Adapter that provides error handling.
*
diff --git a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/DialogBot.java b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/DialogBot.java
index d71d53ed6..ddcafee17 100644
--- a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/DialogBot.java
+++ b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/DialogBot.java
@@ -10,7 +10,6 @@
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.builder.UserState;
import java.util.concurrent.CompletableFuture;
-import org.springframework.stereotype.Component;
/**
* This IBot implementation can run any type of Dialog. The use of type parameterization is to
@@ -21,7 +20,6 @@
* been used in a Dialog implementation, and the requirement is that all BotState objects are
* saved at the end of a turn.
*/
-@Component
public class DialogBot extends ActivityHandler {
protected Dialog dialog;
protected BotState conversationState;
diff --git a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/UserProfileDialog.java b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/UserProfileDialog.java
index 302fe5d3a..ade706bd8 100644
--- a/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/UserProfileDialog.java
+++ b/samples/05.multi-turn-prompt/src/main/java/com/microsoft/bot/sample/multiturnprompt/UserProfileDialog.java
@@ -27,9 +27,7 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
-@Component
public class UserProfileDialog extends ComponentDialog {
private StatePropertyAccessor userProfileAccessor;
diff --git a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/Application.java b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/Application.java
index 5c08c5a98..9db23c06f 100644
--- a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/Application.java
+++ b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/Application.java
@@ -3,6 +3,10 @@
package com.microsoft.bot.sample.usingcards;
+import com.microsoft.bot.builder.Bot;
+import com.microsoft.bot.builder.ConversationState;
+import com.microsoft.bot.builder.UserState;
+import com.microsoft.bot.dialogs.Dialog;
import com.microsoft.bot.integration.AdapterWithErrorHandler;
import com.microsoft.bot.integration.BotFrameworkHttpAdapter;
import com.microsoft.bot.integration.Configuration;
@@ -10,31 +14,65 @@
import com.microsoft.bot.integration.spring.BotDependencyConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
-/**
- * This is the starting point of the Sprint Boot Bot application.
- *
- * This class also provides overrides for dependency injections. A class that
- * extends the {@link com.microsoft.bot.builder.Bot} interface should be
- * annotated with @Component.
- *
- * @see RichCardsBot
- */
+//
+// This is the starting point of the Sprint Boot Bot application.
+//
@SpringBootApplication
// Use the default BotController to receive incoming Channel messages. A custom
// controller could be used by eliminating this import and creating a new
-// RestController.
+// org.springframework.web.bind.annotation.RestController.
// The default controller is created by the Spring Boot container using
// dependency injection. The default route is /api/messages.
@Import({BotController.class})
+/**
+ * This class extends the BotDependencyConfiguration which provides the default
+ * implementations for a Bot application. The Application class should
+ * override methods in order to provide custom implementations.
+ */
public class Application extends BotDependencyConfiguration {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
+ /**
+ * Returns the Bot for this application.
+ *
+ *
+ * The @Component annotation could be used on the Bot class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Bot implementation for this application.
+ */
+ @Bean
+ public Bot getBot(
+ ConversationState conversationState,
+ UserState userState,
+ Dialog rootDialog
+ ) {
+ return new RichCardsBot(conversationState, userState, rootDialog);
+ }
+
+ /**
+ * Returns the starting Dialog for this application.
+ *
+ *
+ * The @Component annotation could be used on the Dialog class instead of this method
+ * with the @Bean annotation.
+ *
+ *
+ * @return The Dialog implementation for this application.
+ */
+ @Bean
+ public Dialog getRootDialog() {
+ return new MainDialog();
+ }
+
/**
* Returns a custom Adapter that provides error handling.
*
diff --git a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/MainDialog.java b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/MainDialog.java
index 7507bc568..c6510175f 100644
--- a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/MainDialog.java
+++ b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/MainDialog.java
@@ -20,9 +20,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import org.springframework.stereotype.Component;
-@Component
public class MainDialog extends ComponentDialog {
public MainDialog() {
super("MainDialog");
diff --git a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/RichCardsBot.java b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/RichCardsBot.java
index aede87551..70235e3d1 100644
--- a/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/RichCardsBot.java
+++ b/samples/06.using-cards/src/main/java/com/microsoft/bot/sample/usingcards/RichCardsBot.java
@@ -8,22 +8,21 @@
import com.microsoft.bot.builder.MessageFactory;
import com.microsoft.bot.builder.TurnContext;
import com.microsoft.bot.builder.UserState;
+import com.microsoft.bot.dialogs.Dialog;
import com.microsoft.bot.schema.Activity;
import com.microsoft.bot.schema.ChannelAccount;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
// RichCardsBot prompts a user to select a Rich Card and then returns the card
// that matches the user's selection.
-@Component
-public class RichCardsBot extends DialogBot {
+public class RichCardsBot extends DialogBot