DO NOT MERGE: Demo of Typescript ActivityHandler class #1202
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an initial Javascript port of #1176
Introducing ActivityHandler
This introduces a new class called ActivityHandler. ActivityHandlers have a
.run()
method that accepts the incoming turnContext created byadapter.processActivity
. The ActivityHandler then emits events based on the activity type and other characteristics. These events can be handled by developer-defined functions.The intention is to provide a flexible base class for bots. This should make it easier for developers to handle specific types of activities, and easier to understand the scope of activities a bot might receive. All activity types that might arrive via the Azure Bot Service are exposed as events, along with a few specialized events to - for example - distinguish whether a conversationUpdates represents member added versus members removed.
Here's a simple example, showing an "Echo bot" that replies to any incoming message with an echo.
Events
For all incoming activities, a
Turn
event will fire.Then, the type-specific event will fire. For example, ConversationUpdate:
Then, any sub-events will fire. For example, MembersAdded, which is a specialized version of ConversationUpdate:
Finally, a special
Dialog
event will fire that can be used to process Dialog activities. (see below)Prevent Propagation of event
At any point in the processing chain, a handler may omit a call to
await next()
to prevent the event from continuing to be processed by other handlers.This pattern can be used to capture interruptions or handle special events before they reach other handlers.
Using with Dialogs
In order to use an ActivityHandler along with the Dialogs system, use the
onDialog()
method, which fires at the very end of the processing chain.