From 02327c019473d1fca4ab5211fe0fd2632ff7eb2c Mon Sep 17 00:00:00 2001 From: tracyboehrer Date: Thu, 23 Jul 2020 08:59:37 -0500 Subject: [PATCH] Added InstallationUpdate Activity type handling --- .../microsoft/bot/builder/ActivityHandler.java | 14 ++++++++++++++ .../bot/builder/ActivityHandlerTests.java | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java index 2be630d89..3eb858ebe 100644 --- a/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java +++ b/libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java @@ -77,6 +77,9 @@ public CompletableFuture onTurn(TurnContext turnContext) { case ActivityTypes.EVENT: return onEventActivity(turnContext); + case ActivityTypes.INSTALLATION_UPDATE: + return onInstallationUpdate(turnContext); + case ActivityTypes.INVOKE: return onInvokeActivity(turnContext).thenCompose(invokeResponse -> { // If OnInvokeActivityAsync has already sent an InvokeResponse, do not send @@ -487,6 +490,17 @@ protected CompletableFuture onEvent(TurnContext turnContext) { return CompletableFuture.completedFuture(null); } + /** + * Override this in a derived class to provide logic specific to + * ActivityTypes.InstallationUpdate activities. + * + * @param turnContext The context object for this turn. + * @return A task that represents the work queued to execute. + */ + protected CompletableFuture onInstallationUpdate(TurnContext turnContext) { + return CompletableFuture.completedFuture(null); + } + /** * Invoked when an activity other than a message, conversation update, or event * is received when the base behavior of {@link #onTurn(TurnContext)} is used. diff --git a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java index 26fa5fcc8..06aef2590 100644 --- a/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java +++ b/libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java @@ -21,6 +21,18 @@ public void TestMessageActivity() { Assert.assertEquals("onMessageActivity", bot.getRecord().get(0)); } + @Test + public void TestOnInstallationUpdate() { + Activity activity = new Activity(ActivityTypes.INSTALLATION_UPDATE); + TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity); + + TestActivityHandler bot = new TestActivityHandler(); + bot.onTurn(turnContext).join(); + + Assert.assertEquals(1, bot.getRecord().size()); + Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0)); + } + @Test public void TestMemberAdded1() { Activity activity = new Activity() { @@ -431,6 +443,12 @@ protected CompletableFuture onEvent(TurnContext turnContext) { return super.onEvent(turnContext); } + @Override + protected CompletableFuture onInstallationUpdate(TurnContext turnContext) { + record.add("onInstallationUpdate"); + return super.onInstallationUpdate(turnContext); + } + @Override protected CompletableFuture onUnrecognizedActivityType(TurnContext turnContext) { record.add("onUnrecognizedActivityType");