microsoftgraph / microsoft-graph-comms-samples

Microsoft Graph Communications Samples
MIT License
212 stars 237 forks source link

Stateless samples with latest package does not work. #508

Open Janath opened 3 years ago

Janath commented 3 years ago

Stateless samples generate json with reference data after upgrade to the latest package. Anyone know how to sort this out?

var answerRequest = this.RequestBuilder.Communications.Calls[callId].Answer( callbackUri: "https://xxxxxxxxxxxx/api/callback", mediaConfig: new ServiceHostedMediaConfig { PreFetchMedia = preFetchMediaList}, acceptedModalities: new List { Modality.Audio }).Request(); await GraphApiClient.SendAsync(answerRequest, RequestType.Create, tenantId, scenarioId).ConfigureAwait(false);

Expected Request

{ "@odata.type": "#microsoft.graph.callAnswerRequestBody", "callbackUri": "https://xxxxxxxxxxxx/api/callback", "mediaConfig": { "@odata.type": "#microsoft.graph.serviceHostedMediaConfig", "preFetchMedia": [] }, "acceptedModalities": [ "audio" ] }

Actual Request

{ "$id": "1", "callbackUri": "https://xxxxxxxxxxxxxx/api/callback", "mediaConfig": { "preFetchMedia": { "$id": "1", "$values": [] }, "@odata.type": "microsoft.graph.serviceHostedMediaConfig" }, "acceptedModalities": { "$id": "2", "$values": [ "Audio" ] }, "participantCapacity": null }

Janath commented 3 years ago

I think happens due to GraphAuthClient default system text json settings. Old version works properly with newtonsoft settings

bogdandynamic commented 2 years ago

Update nugets to the latest version and use below snippet to correct serialization problem (Bot.cs constructor):

// graph client
var productInfo = new ProductInfoHeaderValue(
    typeof(Bot).Assembly.GetName().Name,
    typeof(Bot).Assembly.GetName().Version.ToString());

JsonSerializerOptions jsonSerializerOptions = new();
jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, false));

GraphApiClient = new GraphAuthClient(
    GraphLogger,
    jsonSerializerOptions, // replaced Serializer.JsonSerializerSettings,
    new HttpClient(),
    AuthenticationProvider,
    productInfo,
    defaultProperties);

The serialized result will be:

{
    "@odata.type": "#microsoft.graph.callAnswerRequestBody",
    "callbackUri": "https://xxxxxxxxxxxx/api/callback",
    "mediaConfig": {
      "@odata.type": "#microsoft.graph.serviceHostedMediaConfig",
      "preFetchMedia": []
    },
    "acceptedModalities": [
      "Audio"
    ]
}

Any call with the above payload will return a 202 (Accepted) code.

Janath commented 2 years ago

@bogdandynamic Thanks

Amogh24 commented 2 years ago

I'm also facing the same issue, can you please suggest how to update to the latest version of the nugets, since the target framework is .netcore2.1 and that doesn't allow the nugets to be updated to the latest version @bogdandynamic @Janath

bogdandynamic commented 2 years ago

@Amogh24, just edit the .csproj file of the project you want to update and change

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

with

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

After that, run Nuget Package Manager and update all packages.

Amogh24 commented 2 years ago

Thanks for your help @bogdandynamic