-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ActivityHandler class #757
Conversation
first few test cases
Pull Request Test Coverage Report for Build #1953
💛 - Coveralls |
case ActivityTypes.MessageReaction: | ||
await this.handle(context, 'MessageReaction', async() => { | ||
if (context.activity.reactionsAdded && context.activity.reactionsAdded.length) { | ||
await this.handle(context, 'MessageReactionAdded', runDialogs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: shouldn't this be "MessageReactionsAdded" and "MessageReactionsRemoved"
(for consistency with the property name and the membersAdded etc.)
await this.handle(context, 'EndOfConversation', runDialogs); | ||
break; | ||
case ActivityTypes.Event: | ||
await this.handle(context, 'Event', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also handle event name "tokens/response"
Note: Partity with microsoft/botbuilder-dotnet#1358
Description
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.Specific Changes
Testing
Run unit tests using
npm run test