Skip to content
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

Create ActivityHandlerBase, rewrite ActivityHandler for increased extensibility points #1223

Merged
merged 9 commits into from
Oct 1, 2019

Conversation

stevengum
Copy link
Member

@stevengum stevengum commented Sep 27, 2019

Description

This PR adds the ActivityHandlerBase with new on*Activity() methods. These methods mirror the corresponding C# activities.

It also refactors the core logic in ActivityHandler and ActivityHandler.run() out into separate overrideable methods. This increases extensibility as developers can change the processing logic and reuse the base logic.

The original eventing logic is still included in ActivityHandler.

None of the already public APIs in ActivityHandler have been modified, and ActivityHandler.run() is still the only point of ingesting activities.

Specific Changes

  • New ActivityHandlerBase class used for subclassing. (Closely follows the C# impl of ActivityHandler)
    • New tests for ActivityHandlerBase
  • ActivityHandler extends ActivityHandlerBase and overrides the inherited on*Activity() methods from ActivityHandlerBase.
    • The overrides still emit the appropriate events.
  • ActivityHandler now has protected methods that dispatch specific activity types by additional properties on the incoming Activity.
    • dispatchConversationUpdateActivity (called by overridden onConversationUpdateActivity)
    • dispatchMessageReactionActivity (called by overridden onMessageReactionActivity)
    • dispatchEventActivity (called by overridden onEventActivity)

Testing

Current ActivityHandler unit tests still work, will add new unit tests (and maybe a TypeScript test collection 🚀)

Todo:

  • Unit tests for refactored logic
  • Unit tests for subclassing ActivtityHandler (Possibly also include TypeScript tests)
  • Complete doc strings for new methods.

@Kaiqb as FYI

@coveralls
Copy link

coveralls commented Sep 27, 2019

Pull Request Test Coverage Report for Build 81234

  • 58 of 65 (89.23%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 86.54%

Changes Missing Coverage Covered Lines Changed/Added Lines %
libraries/botbuilder-core/src/activityHandler.ts 26 27 96.3%
libraries/botbuilder-core/src/activityHandlerBase.ts 31 37 83.78%
Totals Coverage Status
Change from base Build 81220: 0.07%
Covered Lines: 4490
Relevant Lines: 5010

💛 - Coveralls

* @param context TurnContext A TurnContext representing an incoming Activity from an Adapter
* @param next () => Promise<void>
*/
protected async handleMessageActivity(context: TurnContext, next: () => Promise<void>): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is now very close to the C# onMessageActivity ... perhaps in the next iteration we could unify further
(FWIW the introduction of functions here is massively better factoring - much clear to read)

@stevengum
Copy link
Member Author

FYI @daveta @tsuwandy

@stevengum stevengum changed the title Rewrite ActivityHandler for increased extensibility points Create ActivityHandlerBase, rewrite ActivityHandler for increased extensibility points Sep 30, 2019
@stevengum stevengum merged commit d676e51 into master Oct 1, 2019
@stevengum stevengum deleted the stgum/rewrite branch October 24, 2019 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.6 4.6 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants