How to Join logged in user to the groupchat in teams using graph api

Seelam, Bharathi (Cognizant) 1 Reputation point
2022-04-20T09:16:44.86+00:00

I have created a personal BOT and created a tabin the tab when the user click on the button that user automatically added to the groupchat
GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var conversationMember = new AadUserConversationMember
{
VisibleHistoryStartDateTime = DateTimeOffset.Parse("2019-04-18T23:51:43.255Z"),
Roles = new List<String>()
{
"owner"
},
AdditionalData = new Dictionary<string, object>()
{
{"user@odata.bind", "https://graph.microsoft.com/v1.0/users/8b081ef6-4792-4def-b2c9-c363a1bf41d5"}
}
};

await graphClient.Chats["{chat-id}"].Members
.Request()
.AddAsync(conversationMember);
Its throwing an error The initiator 8:orgid:e11885e0-aef7-41e7-be4b-a32c55b5b8e4 is not a member of the roster afbe6dc0-ab9b-49b7-8cfc-c9794834a6f8 in the generic thread 19:19496b7b2d12406694dabcf0edb24cee@thread.v2.isSelfJoining: True isSelfJoiningEnabled: False

when i tried with application token(bot)getting error requested api is not supported in application-only context

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,383 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 40,141 Reputation points
    2022-04-21T09:22:20.49+00:00

    Hi @Seelam, Bharathi (Cognizant)

    The API supports both user context and application context, if you are using user context then you have to log in with the owner of the group chat and get token, then use that token to add new members, in user context only the group chat owner can add new members. If you are using application context then you can add new members directly.

    195065-image.png

    Note that if your user is a guest, you must set roles to "guest" when adding him to the group chat.

    Roles = new List<String>()  
    {  
    	"guest"  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our [documentation][4] to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.