Skip to content

[botbuilder]TeamsActivityHandler — Events are called twice #4202

Closed
@alexrecuenco

Description

@alexrecuenco
Contributor

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Versions

Current main branch (commit 08b73c4)
What package version of the SDK are you using.

❯ node --version
v14.19.0

OS: MAC OS

Describe the bug

TeamsActivityHandler, when an activity is received, calls each handler added by onEvent(handler) twice

To Reproduce

  1. Self explanatory, add an event, call it

Expected behavior

Event handlers should be called once

Activity

added
bugIndicates an unexpected problem or an unintended behavior.
needs-triageThe issue has just been created and it has not been reviewed by the team.
on Apr 25, 2022
added a commit that references this issue on Apr 25, 2022
1c354dd
added 2 commits that reference this issue on Apr 25, 2022
22557b9
dcf434d
alexrecuenco

alexrecuenco commented on Apr 25, 2022

@alexrecuenco
ContributorAuthor

The best way to test this issue is to use the PR #4203 and remove the code change:

The test included in that PR will fail without the change included in that PR

iKnowRam

iKnowRam commented on Apr 26, 2022

@iKnowRam
Contributor

Hey @alexrecuenco,

I'm able to reproduce. I ran the /teamsActivityHandler.test.js / unit test in current main branch and the onEvent method is being called twice.

it('should not call middleware handler twice', async function () {

Screenshot:
image

iKnowRam

iKnowRam commented on Apr 26, 2022

@iKnowRam
Contributor

I'm not sure if this is by design or a bug within the JS SDK.
I will discuss this with the SDK engineering team today.

removed
needs-triageThe issue has just been created and it has not been reviewed by the team.
on Apr 26, 2022
iKnowRam

iKnowRam commented on Apr 27, 2022

@iKnowRam
Contributor

Update:

I attempted to repro on the .NET SDK, and it looks like the OnEventActivityAsync method for TeamsActivityHandler is called once.

Here are the steps I took:

  1. Cloned and built the botbuilder-dotnet repo on my local machine environment

  2. Navigate to /TeamsActivityHandlerTests.cs / test file

  3. In TestActivityHandler class, I created getter and setter property set to 0 by default, to count the number of calls for OnEventActivityAsyn

       private class TestActivityHandler : TeamsActivityHandler
       {
    +      public int NumberOfOnEventCalls { get; set; } = 0;
    
           public List<string> Record { get; } = new List<string>();
    
  4. Then, in OnEventActivityAsync method, I increment the NumberOfOnEventCalls property by one if it gets called.

           protected override Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
           {
               Record.Add(MethodBase.GetCurrentMethod().Name);
    +          NumberOfOnEventCalls++;
               return base.OnEventActivityAsync(turnContext, cancellationToken);
           }
  5. Ran the TestOnEventActivity() test case, and debugged the NumberOfOnEventCalls property. It seems it was only called once.

    image

Also, I created a temporary branch of my changes here microsoft/botbuilder-dotnet@1d18e1f

alexrecuenco

alexrecuenco commented on Apr 27, 2022

@alexrecuenco
ContributorAuthor

Thank you for your effort verifying the inconsistency. I hope #4203 is a sufficient solution.

self-assigned this
on Apr 27, 2022
added
customer-replied-toIndicates that the team has replied to the issue reported by the customer. Do not delete.
on Apr 28, 2022

8 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Bot ServicesRequired for internal Azure reporting. Do not delete. Do not change color.bugIndicates an unexpected problem or an unintended behavior.customer-replied-toIndicates that the team has replied to the issue reported by the customer. Do not delete.customer-reportedIssue is created by anyone that is not a collaborator in the repository.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @EricDahlvang@alexrecuenco@lauren-mills@iKnowRam@msomanathan

    Issue actions

      [botbuilder]TeamsActivityHandler — Events are called twice · Issue #4202 · microsoft/botbuilder-js