0

My Flow 1- Created Azure bot in python.(focusing on member added activity and send message activity only) 2- Deployed Bot on azure and changed messaging endpoint of bot with my api url where i want these activities responses

3- Added teams in bot channels.

4- Share the bot URL to teams client.

Problem -> If i run this bot in 'Test in Web Chat' its working fine. I mean It is providing me OnMembersAdded activity response automatically.

But if client add this bot to Teams then I am not getting OnMembersAdded activity response automatically. Client has to send his first message. If he sends message then after i get this activity.

On Client Added To Teams-> No response. Client sends his first message -> Getting OnMembersAdded activity response + OnMessage activity response

This OnMembersAdded Activity should be trigger when member is added not after sending first message.

Also tried with 'on_teams_members_added' activity but its not sending welcome message to Teams at all.

 async def on_teams_members_added(  # pylint: disable=unused-argument
    self,
    teams_members_added: [TeamsChannelAccount],
    team_info: TeamInfo,
    turn_context: TurnContext,
):
    for member in teams_members_added:
        if member.id != turn_context.activity.recipient.id:
            await turn_context.send_activity(
                f"Welcome!!"
            )

1 Answers1

1

This OnMembersAdded Activity should be trigger when member is added not after sending first message.

The team has a specific activity handler called "OnTeamsMembersAddedAsync" and this will support your requirement in MS Teams. I think onMembersAddedAsync works in WebChat, emulator, etc but not in Teams.

Reference:

  1. Teams Activity Handlers
  2. Python TeamsActivityHandler
Rajeesh Menoth
  • 1,704
  • 3
  • 17
  • 33
  • Yes i also tried 'OnTeamsMembersAddedAsync' but that is not working.I mean its not sending welcome message at all on Teams. Should i change something in it to make it work for Teams? – Nitin Sharma Jul 21 '21 at 07:25
  • Also added a code for it. Can you please verify that – Nitin Sharma Jul 21 '21 at 07:33
  • @NitinSharma use TeamsActivityHandler, Check this reference https://stackoverflow.com/questions/65701014/how-to-proactively-send-a-message-to-a-teams-channel – Rajeesh Menoth Jul 21 '21 at 08:02
  • @NitinSharma if the above answer is helpful you can mark it as an acceptable answer and it will helpful for others in the future. – Rajeesh Menoth Jul 21 '21 at 08:09
  • @NitinSharma you can also refer to the existing issue reported in Microsoft bot builder https://github.com/microsoft/botbuilder-python/issues/1469 – Rajeesh Menoth Jul 21 '21 at 08:29
  • Yes i looked those links but issue still exists. i also deployed a copy of this bot https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/57.teams-conversation-bot but this is also not working. Note that i only want to send welcome message on personal scope when a new user opens my bot first time. – Nitin Sharma Jul 21 '21 at 11:40
  • I am sharing the bot to new user by bot url(got from teams channels in azure portal).User adds this bot in his space first time and nothing happens. – Nitin Sharma Jul 21 '21 at 11:43
  • Share the url is not enough you should add those bot in AppStudio and install as an app. – Rajeesh Menoth Jul 21 '21 at 11:49
  • But How can a user of different organization will get my bot if i add it to my AppStudio? – Nitin Sharma Jul 21 '21 at 12:07
  • Valid point, probably you need to add other tenant in your AD because these are security concern. – Rajeesh Menoth Jul 21 '21 at 12:33
  • Basically that's what i need . Anybody can access my bot by using URL.If any user adds bot then first step is to let me know that user is added(member_added_activity).So i can send him welcome message or "invalid user" message.Problem is that this first activity is not triggering(on_team_members_added activity) at all.If i change this to 'on_member_added_activity' then it runs but after when user sends his first message. – Nitin Sharma Jul 21 '21 at 12:43
  • I think your python code or package have some issue because teammember added functionality should work in teams. I have already shared you GitHub reference if those are not working means it related to your code / package issue because those reference is similar to your issue. You can create a support ticket to microsoft or create a new chatbot and re-verify. – Rajeesh Menoth Jul 21 '21 at 13:01
  • Well i did dpeloy a copy of https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/python/57.teams-conversation-bot. But on_team_member_added activity is not working for this bot too. – Nitin Sharma Jul 22 '21 at 05:12