Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit aa307c5

Browse files
Added typing activity to activityhandler (#837)
1 parent 794af6f commit aa307c5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/ActivityHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public CompletableFuture<Void> onTurn(TurnContext turnContext) {
8080
case ActivityTypes.INSTALLATION_UPDATE:
8181
return onInstallationUpdate(turnContext);
8282

83+
case ActivityTypes.TYPING:
84+
return onTypingActivity(turnContext);
85+
8386
case ActivityTypes.INVOKE:
8487
return onInvokeActivity(turnContext).thenCompose(invokeResponse -> {
8588
// If OnInvokeActivityAsync has already sent an InvokeResponse, do not send
@@ -501,6 +504,17 @@ protected CompletableFuture<Void> onInstallationUpdate(TurnContext turnContext)
501504
return CompletableFuture.completedFuture(null);
502505
}
503506

507+
/**
508+
* Override this in a derived class to provide logic specific to
509+
* ActivityTypes.Typing activities.
510+
*
511+
* @param turnContext The context object for this turn.
512+
* @return A task that represents the work queued to execute.
513+
*/
514+
protected CompletableFuture<Void> onTypingActivity(TurnContext turnContext) {
515+
return CompletableFuture.completedFuture(null);
516+
}
517+
504518
/**
505519
* Invoked when an activity other than a message, conversation update, or event
506520
* is received when the base behavior of {@link #onTurn(TurnContext)} is used.

libraries/bot-builder/src/test/java/com/microsoft/bot/builder/ActivityHandlerTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ public void TestOnInstallationUpdate() {
3333
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
3434
}
3535

36+
@Test
37+
public void TestOnTypingActivity() {
38+
Activity activity = new Activity(ActivityTypes.TYPING);
39+
TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity);
40+
41+
TestActivityHandler bot = new TestActivityHandler();
42+
bot.onTurn(turnContext).join();
43+
44+
Assert.assertEquals(1, bot.getRecord().size());
45+
Assert.assertEquals("onTypingActivity", bot.getRecord().get(0));
46+
}
47+
3648
@Test
3749
public void TestMemberAdded1() {
3850
Activity activity = new Activity() {
@@ -449,6 +461,12 @@ protected CompletableFuture onInstallationUpdate(TurnContext turnContext) {
449461
return super.onInstallationUpdate(turnContext);
450462
}
451463

464+
@Override
465+
protected CompletableFuture onTypingActivity(TurnContext turnContext) {
466+
record.add("onTypingActivity");
467+
return super.onTypingActivity(turnContext);
468+
}
469+
452470
@Override
453471
protected CompletableFuture onUnrecognizedActivityType(TurnContext turnContext) {
454472
record.add("onUnrecognizedActivityType");

0 commit comments

Comments
 (0)