2

I would like to send the user a welcome message when they install my MS Teams Bot app. All the samples and documentation point to using the ActivityHandler onMembersAdded event. Unfortunately I can't get this event to fire. I also noticed that when installing the zip file in Teams and watching the requests in ngrok nothing happens; so I'm not entirely sure the problem is in my bot app. Is there something I need to do in the manifest?

If I chat with my app the onMessage event will fire, but like I said above, I need to send a "Welcome" message when the app is installed before the user starts typing.

Background: I created the manifest for my app using App Studio in Teams and exported it to a zip The node app is built with the using botbuilder 4.9.2

Tyler
  • 1,019
  • 12
  • 27
  • 1
    Has the app been installed for this user previously (like from App Studio directly)? – Hilton Giesenow Jul 18 '20 at 18:00
  • We could not reproduce the issue on our side. Could you please try this [sample](https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/16.proactive-messages/Bots/ProactiveBot.cs#L39)? – Nikitha-MSFT Jul 20 '20 at 11:28
  • @HiltonGiesenow Yes, I have previously installed it using App Studio. Shouldn't generating a new AppID treat it as a new install? – Tyler Jul 20 '20 at 17:14
  • @Tyler if you have already installed the bot. You need to uninstall the previous app before installing the new. Could you please try uninstalling the bot and install it again by using the zip file? – Nikitha-MSFT Jul 23 '20 at 03:19
  • 1
    @Nikitha-MSFT uninstalling doesn't seem to work, it seems like teams keeps everything related to that bot saved and restores it when reinstalling the same bot app. I did manage to get it working by creating an entirely new bot app with all new IDs. But for testing would prefer if uninstall would truly reset everything. – Tyler Jul 24 '20 at 15:53
  • Yep, can confirm. Uninstalling and reinstalling doesn't trigger this event anymore - however it used to up until a few weeks ago. I wonder if this is a bug or if it was a bug that it worked in the first place. :) – Mike R Jul 27 '20 at 06:30
  • Could you please share your app manifest? – Nikitha-MSFT Jul 27 '20 at 06:58
  • Could you please try this [sample](https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/csharp_dotnetcore/16.proactive-messages/Bots/ProactiveBot.cs#L39)? – Nikitha-MSFT Jul 28 '20 at 12:23
  • @Nikitha-MSFT I've got this exact sample implemented however, the problem is that the actual event isn't being sent on reinstall as there are no traces of it in our network logs. Mind you the rest of the bot events work, like receiving a direct message or fetchTask events, or the initial conversationUpdate event for the first time a user installs the app. – Mike R Jul 29 '20 at 11:39
  • Did you try the sample? Are you facing same issue with the sample also? if no could you please compare your code with the sample? – Nikitha-MSFT Aug 03 '20 at 05:10
  • @Nikitha-MSFT I did and the same issue persists. I'm not receiving additional membersAdded events when reinstalling the app for user scope - only for team scope just like before. No difference. – Mike R Aug 03 '20 at 12:23
  • 1
    For a 1:1 conversation between the bot and a user (personal scope) the event is only sent the very first time the bot is installed. Technically, it is sent when the conversation is created between the bot and the user. If the user uninstalls the bot, this conversation is not deleted, so if the user then re-installs the bot the event is not sent. For Group Chats and Channels the event will be sent each time the bot is installed. This is because each time the bot is uninstalled from this context, it is actually completely removed from the conversation, so an uninstall triggers the event. – Nikitha-MSFT Aug 03 '20 at 12:43
  • @Nikitha-MSFT thanks for clearing that up, I came to that conclusion in my own [question](https://stackoverflow.com/questions/63030966/microsoft-teams-cant-start-conversation-receiving-status-code-forbidden) Now I only need to figure out why I'm getting that forbidden error "Invalid user identity in provided tenant" – Mike R Aug 03 '20 at 12:54

1 Answers1

1

onMembersAddedAsync works everywhere, but not in Teams :) For Teams, there is a set of separate methods that work only in Teams. You need to use OnTeamsMembersAddedAsync. You can read more about that here: https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/create-a-bot-for-teams

  • I originally was using OnTeamsMembersAddedAsync and switched to try and see if another event would fire. But you are correct OnTeamsMembersAddedAsync is the right one to use. – Tyler Jul 24 '20 at 15:50