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 3eb858ebe..6a451e17d 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 @@ -80,6 +80,9 @@ public CompletableFuture onTurn(TurnContext turnContext) { case ActivityTypes.INSTALLATION_UPDATE: return onInstallationUpdate(turnContext); + case ActivityTypes.TYPING: + return onTypingActivity(turnContext); + case ActivityTypes.INVOKE: return onInvokeActivity(turnContext).thenCompose(invokeResponse -> { // If OnInvokeActivityAsync has already sent an InvokeResponse, do not send @@ -501,6 +504,17 @@ protected CompletableFuture onInstallationUpdate(TurnContext turnContext) return CompletableFuture.completedFuture(null); } + /** + * Override this in a derived class to provide logic specific to + * ActivityTypes.Typing activities. + * + * @param turnContext The context object for this turn. + * @return A task that represents the work queued to execute. + */ + protected CompletableFuture onTypingActivity(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 06aef2590..6cf214870 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 @@ -33,6 +33,18 @@ public void TestOnInstallationUpdate() { Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0)); } + @Test + public void TestOnTypingActivity() { + Activity activity = new Activity(ActivityTypes.TYPING); + TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity); + + TestActivityHandler bot = new TestActivityHandler(); + bot.onTurn(turnContext).join(); + + Assert.assertEquals(1, bot.getRecord().size()); + Assert.assertEquals("onTypingActivity", bot.getRecord().get(0)); + } + @Test public void TestMemberAdded1() { Activity activity = new Activity() { @@ -449,6 +461,12 @@ protected CompletableFuture onInstallationUpdate(TurnContext turnContext) { return super.onInstallationUpdate(turnContext); } + @Override + protected CompletableFuture onTypingActivity(TurnContext turnContext) { + record.add("onTypingActivity"); + return super.onTypingActivity(turnContext); + } + @Override protected CompletableFuture onUnrecognizedActivityType(TurnContext turnContext) { record.add("onUnrecognizedActivityType");