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

Creating private channel not working in version 5.13 #1968

Open
TimScholzESC opened this issue Jun 14, 2023 · 6 comments
Open

Creating private channel not working in version 5.13 #1968

TimScholzESC opened this issue Jun 14, 2023 · 6 comments
Labels

Comments

@TimScholzESC
Copy link

Describe the bug
Creating Private Team Channel not working in version 5.13

To Reproduce
Working Code from 5.12

privateChannel.OdataType = "#Microsoft.Graph.channel";
            privateChannel.Members = new();
            foreach (var owner in owners)
            {
                privateChannel.Members.Add(
                    new ConversationMember()
                    {
                        Roles = new List<string>() { "owner" },
                        OdataType = "#microsoft.graph.aadUserConversationMember",
                        AdditionalData = new Dictionary<string, object>
                        {
                            {
                                "user@odata.bind",
                                $"{this.graph.RequestAdapter.BaseUrl}/users('{owner}')"
                            },
                        }
                    }
                );
            }

            await privateChannelPolicy.ExecuteAsync(
                () => this.graph.Teams[group.Id].Channels.PostAsync(privateChannel)
            );

Not working anymore in Version 5.13

Response:
{"code":"BadRequest","message":"CreateChannel_Private: Cannot create private channel, no members specified when calling from an Application."}

Can't see any changes to docu if there was a wanted change to the behavior to this.

@ghost ghost added the Needs: Triage label Jun 14, 2023
@andrueastman
Copy link
Member

Thanks for raising this @TimScholzESC

Any chance you can share the output strings when running the two versions when you run the following code on the privateChannel object to help us investigate the issue better?

                var serializationWriter = graphClient.RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
                serializationWriter.WriteObjectValue(string.Empty, privateChannel);
                using StreamReader reader = new StreamReader(serializationWriter.GetSerializedContent());
                var jsonPayload = await reader.ReadToEndAsync();
                Console.WriteLine(jsonPayload);

@TimScholzESC
Copy link
Author

This is the output for the same code:

5.12:
{"@odata.type":"#Microsoft.Graph.channel","displayName":"Leitung","members":[{"@odata.type":"#microsoft.graph.aadUserConversationMember","user@odata.bind":"https://graph.microsoft.com/v1.0/users(\u0027f4c890e1-3580-4553-8aad-5ca386498a2c\u0027)","roles":["owner"]},{"@odata.type":"#microsoft.graph.aadUserConversationMember","user@odata.bind":"https://graph.microsoft.com/v1.0/users(\u0027678b4b94-7f11-4324-bcbc-7f5a62d9ff20\u0027)","roles":["owner"]}],"membershipType":"private"}

5.13:
{"displayName":"Leitung","membershipType":"private"}

@andrueastman
Copy link
Member

Thanks for the feedback here @TimScholzESC

To confirm, can share how the privateChannel variable is initialized? Is it read from an API call or simply created as new Channel()? Same for the owners collection

At the moment, I still do get the "members" array populated with 5.13.0

{"@odata.type":"#Microsoft.Graph.channel","members":[{"@odata.type":"#microsoft.graph.aadUserConversationMember","user@odata.bind":"https://graph.microsoft.com/v1.0/users(\u0027XXXX\u0027)","roles":["owner"]}]}

@ghost
Copy link

ghost commented Jun 25, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@TimScholzESC
Copy link
Author

Thanks for the respond @andrueastman.
I tried to reproduce it in another project and i couldn't for now,
There is a lot of code between the initialization of the Channel and the PostAsync call.
I will try to create some code I can share with most of the logic where this is reproducable in the next days

@TimScholzESC
Copy link
Author

Hi, @andrueastman
Seems like getting Channels from a Team object and than removing them from the Team object is causing the problem.
This was working in 5.12 and isn't in any version above (Current versions 5.16)
here is code to reproduce the error:

public async Task Main()
    {
        var team = GetTeam();

        var channelsToCreate = team.Channels
            .Where(c => c.MembershipType == ChannelMembershipType.Private)
            .ToList();

        foreach (Channel privateChannel in channelsToCreate)
        {
            team.Channels.Remove(privateChannel);
        }

        var owners = new List<string> { Guid.NewGuid().ToString() };
        await CreateChannelsAtGraph(channelsToCreate, owners);
    }

    private async Task CreateChannelsAtGraph(List<Channel> channels, List<string> owners)
    {
        foreach (var privateChannel in channels)
        {
            privateChannel.OdataType = "#Microsoft.Graph.channel";
            privateChannel.Members = new();
            foreach (var owner in owners)
            {
                privateChannel.Members.Add(
                    new ConversationMember()
                    {
                        Roles = new List<string>() { "owner" },
                        OdataType = "#microsoft.graph.aadUserConversationMember",
                        AdditionalData = new Dictionary<string, object>
                        {
                            {
                                "user@odata.bind",
                                $"{this.graph.RequestAdapter.BaseUrl}/users('{owner}')"
                            },
                        }
                    }
                );
            }

            var serializationWriter =
                graph.RequestAdapter.SerializationWriterFactory.GetSerializationWriter(
                    "application/json"
                );
            serializationWriter.WriteObjectValue(string.Empty, privateChannel);
            using StreamReader reader = new StreamReader(
                serializationWriter.GetSerializedContent()
            );
            var jsonPayload = await reader.ReadToEndAsync();
            Console.WriteLine(jsonPayload);

            //await this._client.Teams[Guid.NewGuid().ToString()].Channels.PostAsync(privateChannel);
        }
    }

    private List<Channel> GetChannels()
    {
        return new List<Channel>()
        {
            new Channel() { DisplayName = "test", MembershipType = ChannelMembershipType.Private },
            new Channel()
            {
                DisplayName = "General",
                OdataType = "microsoft.graph.channel",
                IsFavoriteByDefault = true
            }
        };
    }

    private Team GetTeam()
    {
        var team = new Team() { Channels = GetChannels() };
        team.AdditionalData.Add(
            "template@odata.bind",
            "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"
        );
        team.AdditionalData.Add(
            "group@odata.bind",
            $"{graph.RequestAdapter.BaseUrl}/groups('{Guid.NewGuid().ToString()}')"
        );
        return team;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants