How to return only the User's info in Bot Builder SDK?

Syafie Asyraf Sarifudin 20 Reputation points
2024-08-13T09:16:13.3133333+00:00

I am developing a chatbot using Microsoft Teams Bot Builder SDK, I managed to get my user profile details however, it comes together with the Bot's which is not required.

The ouput:

"Welcome Syafie!"
"Welcome! We couldn't retrieve your detailed information."

The code:

async def on_members_added_activity(
        self, members_added: List[ChannelAccount], turn_context: TurnContext
    ):
        for member in members_added:
                
            # Attempt to get the Teams member information
            teams_member = await self.get_member(turn_context, member.id)
                
            if teams_member:
                self.full_name = f"{teams_member.given_name} {teams_member.surname}"
                self.name = teams_member.given_name
                self.email = teams_member.email
                self.organization = self.email.split("@")[1].split(".")[0]
                self.selected_option = self.organization
                        
                await turn_context.send_activity(greeting(self.name))

            else:
                self.selected_option = None
                await turn_context.send_activity("Welcome! We couldn't retrieve your detailed information.")


    async def get_member(self, turn_context: TurnContext, member_id: str) -> TeamsChannelAccount:
        try:
            if turn_context.activity.channel_data:
                member = await TeamsInfo.get_member(turn_context, member_id)
                return TeamsChannelAccount().deserialize(member.serialize())
            else:
                raise ValueError("No channel_data available in TurnContext activity.")
        except Exception as e:
            print(f"Error retrieving member: {e}")
            return None
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,980 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,209 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.