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

Duplication membersAdded event #4377

Closed
Serginyo90 opened this issue Nov 24, 2022 · 26 comments
Closed

Duplication membersAdded event #4377

Serginyo90 opened this issue Nov 24, 2022 · 26 comments
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.

Comments

@Serginyo90
Copy link

Serginyo90 commented Nov 24, 2022

Version

JavaScript "botbuilder": "4.14.0",

Describe the bug

Give a clear and concise description of what the bug is.
We receive 2 or 4 events when user installs our application.

Expected behavior

Receive event once

Additional context

    "membersAdded": [
        {
            "id": "29:1Iat8W8y5w9RxIgqFnDUqJlJalpDXC5jlXWG3hYzfczu25fn_gNbbc6WV7V36GbpgvQjpt8_w5nHuW_os7d",
            "aadObjectId": "9272a828-5c43-4a1c-8a15-e315f8a8"
        },
        {
            "id": "28:331df719-bfd2-4fcc-aa91-f08bc21a"
        }
    ],
    "type": "conversationUpdate",
    "timestamp": "2022-11-12T12:57:45.190Z",
    "id": "f:884a2807-d9d0-d4cb-ffd6-eec40244",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
        "id": "29:1Iat8W8y5w9RxIgqFnDUqJlJalpDXC5jlXWG3hYzfczu25fn_gNbbc6WV7V36GbpgvQjpt8_w5nHuW_os7d",
        "aadObjectId": "9272a828-5c43-4a1c-8a15-e315f8a8"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "f8ed7ee1-1d5c-48b5-b6c3-6a31e6fc",
        "id": "a:18hXVgntuPkzeTp8DS4JaeE7ua5b9sk24t8WVVfeGEb-Lt0Idw_ZOEAbWq9sGopVv6FzGM7BqZjyLv985oC4SwVjrjpMKumbK2UOj128CpWCnFvJdKQ-Xxdgz9NsK"
    },
    "recipient": {
        "id": "28:331df719-bfd2-4fcc-aa91-f08bc21a",
        "name": "ProHabits Bot"
    },
    "channelData": {
        "tenant": {
            "id": "f8ed7ee1-1d5c-48b5-b6c3-6a31e6fc"
        }
    },
    "rawTimestamp": "2022-11-12T12:57:45.1909085Z",
    "callerId": "urn:botframework:azure",
    "hashId": "5da0a5f4-0e83-4e9d-a1d5-2026b69"
}

Do you have any ideas how we can receive event only once?

@Serginyo90 Serginyo90 added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Nov 24, 2022
@ramfattah ramfattah self-assigned this Nov 28, 2022
@ramfattah ramfattah added customer-reported Issue is created by anyone that is not a collaborator in the repository. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. and removed needs-triage The issue has just been created and it has not been reviewed by the team. labels Nov 28, 2022
@ramfattah
Copy link
Contributor

Thanks @Serginyo90, we are investigating.

@ramfattah
Copy link
Contributor

Hi @Serginyo90,

Have you tried updating botbuilder sdk to latest version 4.17.1, to see if that might address this issue?
Also, are you experiencing this issue only in Teams channel?

@ramfattah ramfattah added the customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. label Nov 29, 2022
@ramfattah ramfattah transferred this issue from microsoft/botframework-sdk Nov 29, 2022
@ramfattah
Copy link
Contributor

Might be related to #4202
Fix #4203 was included in JavaScript SDK release 4.17.0.

@Serginyo90, could you please try to update the javascript botbuilder sdk to latest version?

@Serginyo90
Copy link
Author

@ramfattah I updated botbuilder and botbuilder-dialogs to 4.18.0 but issue still exists.
The same behavior. Duplicated onMembersAdded event

@Serginyo90
Copy link
Author

Serginyo90 commented Nov 29, 2022

here is example of code

export default class TeamsActivityService extends TeamsActivityHandler {
  constructor() {
    super()

    this.onConversationUpdate(async (context: TurnContext, next) => {
      await this.addConversationReference(context)
      await next()
    })

    this.onMembersAdded(async (context: TurnContext, next) => {
      await this.addConversationReference(context)
      await next()
    })

    this.onMessage(async (context: TurnContext, next) => {
      await this.addConversationReference(context)
      await next()
    })
  }

@ramfattah
Copy link
Contributor

Thanks for providing the code @Serginyo90, looking into this further.

@ramfattah
Copy link
Contributor

Thanks for your patience @Serginyo90,

I was able to repro this issue after installing bot sample bot-conversation in Teams.

sharing the steps to repro:

  1. Clone bot-conversation/nodejs
  2. Follow the readme to set up the bot with Teams
  3. In bots/teamsConversationBot.js, change the onMembersAddedActivity method to the following:
        this.onMembersAdded(async (context, next) => {
            await Promise.all((context.activity.membersAdded || []).map(async (member) => {
                if (member.id !== context.activity.recipient.id) {
                    await context.sendActivity(`Welcome to the team`);
                }
            }));
    
            await next();
        });
  4. Run and add the bot app to Teams client.
  5. Notice the POST request in Ngrok after the bot has been installed and onMembersAdded event is triggered:

@ramfattah
Copy link
Contributor

Hey @JuanAr,

I was able to repro this issue. Assigned this to you for now.

Please let me know if you have any questions.
Thanks.

@erquirogasw
Copy link
Contributor

Hi @ramfattah .
We tried to reproduce the issue but we couldn't see the onMembersAdded event triggered more than once.
Have you been able to see the event triggered two times? In the image you shared, we see it once with the ids of the user and the bot.

@ramfattah
Copy link
Contributor

ramfattah commented Dec 19, 2022

Thanks for checking on this @erquirogasw,

The above screenshot was taken right after the bot app was installed in Teams.
If a member was added to a group (not install), then the result looked like:

    "membersAdded": [
        {
            "id": "xx:xxxxx...........................",
            "aadObjectId": "xxxxxxxx..........."
        }
    ],

While investigating this issue; so far, I've found that the onMembersAdded event gets triggered with the following scenarios:

  1. If user joins a group chat
  2. If user install the bot app in Teams

Scenario #1 was not reproducible, whereas scenario #2 is reproducible.

    "membersAdded": [
        {
            "id": "29:1Iat8W8y5w9RxIgqFnDUqJlJalpDXC5jlXWG3hYzfczu25fn_gNbbc6WV7V36GbpgvQjpt8_w5nHuW_os7d",
            "aadObjectId": "9272a828-5c43-4a1c-8a15-e315f8a8"
        },
        {
            "id": "28:331df719-bfd2-4fcc-aa91-f08bc21a"
        }
    ],

Please let me know if I've done something incorrectly or if you have any questions.
Thanks.

@Serginyo90
Copy link
Author

@ramfattah @erquirogasw main issue for me is I receive current event twice and sometime once. But usually twice. Did you able to reproduce it?
Screenshot 2022-12-20 at 10 50 36

@erquirogasw
Copy link
Contributor

erquirogasw commented Dec 21, 2022

Hi everyone, we couldn't reproduce the issue. If we install the app normally, we only receive the event once (with the two ids, user and bot, but that's expected).
We can see two MembersAdded events when we install the app in two different scopes (team and personal) as shown in the images.
@Serginyo90, can you give us more information? In which scope are you installing your bot (personal, team, meeting)? Do you have a sample bot to test this behavior?

Thanks!

image (178)

@Serginyo90
Copy link
Author

@erquirogasw it is personal scope in both cases.
Screenshot 2022-12-22 at 19 54 18
I see that you received 2 api calls each time when add app on your screenshot. But must be only one. Correct?
Does in 2nd one the same information like in first one?

@erquirogasw
Copy link
Contributor

Hi @Serginyo90, the other two requests we received are of type installationUpdate. They are not the same as MembersAdded.

image (179)

@Serginyo90
Copy link
Author

@erquirogasw Ok. I will prepare the code and share with you on Tuesday

@Serginyo90
Copy link
Author

@erquirogasw You can find the sample bot here https://github.com/Serginyo90/issue-with-ms-bot .
P.S. I tried to reproduce it with Bot Framework Emulator but can't. Can you try reproduce with Azure Bot?

@erquirogasw
Copy link
Contributor

Hi @Serginyo90, we weren't able to reproduce the issue when installing the provided sample in Teams. We got the same outputs as before and the behavior seems to be the expected. The only difference we can think off is the app manifest. Could you share yours so we can compare and test it?

@ramfattah
Copy link
Contributor

Closing due to inactivity. @Serginyo90, please re-open if needed.

@Serginyo90
Copy link
Author

Serginyo90 commented Feb 9, 2023

@ramfattah @erquirogasw
Sorry, I was in vacation guys.
Sure... here is manifest
{ "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.13/MicrosoftTeams.schema.json", "manifestVersion": "1.13", "version": "2.3.13", "id": "e1dc8cc5-....", "packageName": "com.microsoft.teams.extension", "developer": { "name": "Teams App, Inc.", "websiteUrl": "https://prohabits.com", "privacyUrl": "https://assets.stg.prohabits.com/mst/helpers/privacy.html", "termsOfUseUrl": "https://prohabits.com/how-it-works-2" }, "icons": { "color": "resources/color.png", "outline": "resources/outline.png" }, "name": { "short": "ProHabits Stg", "full": "ProHabits Stg Corporation" }, "description": { "short": "ProHabits Stg is created for motivation", "full": "ProHabits Stg makes people better and better each day. We are here 24/7 to help you achieve your goals." }, "accentColor": "#FFFFFF", "bots": [ { "botId": "e1dc8cc5-8...", "scopes": ["personal", "team", "groupchat"], "supportsFiles": false, "isNotificationOnly": true } ], "composeExtensions": [], "configurableTabs": [ { "configurationUrl": "https://assets.stg....", "canUpdateConfiguration": true, "scopes": ["team", "groupchat"] } ], "staticTabs": [ { "entityId": "conversations", "scopes": ["personal"] }, { "entityId": "dashboard", "name": "Community", "contentUrl": "https://assets.stg.prohabits.com/...#/dashboard", "websiteUrl": "https://assets.stg.prohabits.com/...#/dashboard", "scopes": ["personal"] }, { "entityId": "myActivities", "name": "Progress", "contentUrl": "https://assets.stg.prohabits.com/...#/myActivities", "websiteUrl": "https://assets.stg.prohabits.com/...#/myActivities", "scopes": ["personal"] }, { "entityId": "settings", "name": "Settings", "contentUrl": "https://assets.stg.prohabits.com/...#/settings", "websiteUrl": "https://assets.stg.prohabits.com/...#/settings", "scopes": ["personal"] }, { "entityId": "leaderboard", "name": "Leaderboard", "contentUrl": "https://assets.stg.prohabits.com/...#/leaderboard", "websiteUrl": "https://assets.stg.prohabits.com/...#/leaderboard", "scopes": ["personal"] } ], "permissions": ["identity", "messageTeamMembers"], "validDomains": [ "mabbly.wistia.com", "youtube.com", "youtu.be", "prohabits.com", "typeform.com", "assets.prohabits.com", "assets.dev.prohabits.com", "assets.stg.prohabits.com" ], "webApplicationInfo": { "id": "e1dc8cc5-....", "resource": "https://localhost:3000" }, "activities": { "activityTypes": [ { "type": "Daily MicroActivity", "description": "Morning Notification", "templateText": "{activityName}" } ] } }

@erquirogasw
Copy link
Contributor

erquirogasw commented Feb 16, 2023

Hi @Serginyo90. We tested your manifest with the sample you provided both locally and in Azure, and the membersAdded event was received only once.
Also, we connected the sample to Azure Application Insights to discard a problem with it, and we got only one event.
Do you have any other feature implemented that might be causing that behavior?

image

@Serginyo90
Copy link
Author

Serginyo90 commented Feb 17, 2023

@erquirogasw Ok. Looks like I found the issue. Just want to confirm that it triggers onMembersAdded and onConversationUpdate events when user installs the App.

@Serginyo90
Copy link
Author

@erquirogasw so could you confirm that it triggers onMembersAdded and onConversationUpdate events when user installs the App, please?

@erquirogasw
Copy link
Contributor

Hi @Serginyo90. When installed, it triggers the installationUpdate and conversationUpdate (containing membersAdded info) events.

image (209)
image (210)

@Serginyo90
Copy link
Author

@erquirogasw thank you. I will rewrite logic using installationUpdate type.

@Serginyo90
Copy link
Author

@erquirogasw I can confirm that installationUpdate also triggered twice. The same like conversationUpdate. So issue still exists

@erquirogasw
Copy link
Contributor

Hi @ramfattah @Serginyo90 .
We weren't able to reproduce this issue in any of the following scenarios:

  • Using the bot-conversation sample. Locally and deployed to Azure.
  • Using the provided sample. Locally, deployed in Azure and with Application Insights.

In both scenarios, we could see 2 requests. One with activityType installationUpdate and another with activityType conversationUpdate.
The conversationUpdate contains the membersAdded array with the data of the bot and the user.
Also, we tried installing the application as personal chat, meeting, and group.
@ramfattah should we re-open this issue to investigate further?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository.
Projects
None yet
Development

No branches or pull requests

4 participants