Skip to content

Commit

Permalink
Add new ConnectorSettings "IncludeWebhookFunctions" to allow using mo…
Browse files Browse the repository at this point in the history
…re Teams operation (#2633)

In the Teams connector, the operation "PostCardAndWaitForResponse"
contains extension "x-ms-notification-content" and is excluded from the
parse result of `GetFunctions`.

In MCS, we want to make this operation available to our internal users
to keep parity with Power Automate behavior.

This PR fixes the issue by
1. Creating a new setting "IncludeWebhookFunctions" to conditionally
include those "webhook" functions on demand.
2. Consume that new setting when filtering on the webhook functions, it
set to true, it won't filter away those functions.

As a result, 4 more operations inside Teams connector will be supported
by merging this change.
On MCS side, PFX `GetFunctions` will be invoked with an additional
setting parameter `IncludeWebhookFunctions = true`.
  • Loading branch information
yeze322 authored Sep 10, 2024
1 parent 580cd86 commit cf51f35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/libraries/Microsoft.PowerFx.Connectors/OpenApiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ internal static IEnumerable<ConnectorFunction> GetFunctionsInternal(ConnectorSet
OpenApiPathItem ops = kv.Value;
bool isSupportedForPath = true;
string notSupportedReasonForPath = string.Empty;

// Skip Webhooks
if (ops.Extensions.Any(kvp => kvp.Key == XMsNotificationContent))

// Skip Webhooks
if (!connectorSettings.IncludeWebhookFunctions && ops.Extensions.Any(kvp => kvp.Key == XMsNotificationContent))
{
configurationLogger?.LogInformation($"Skipping Webhook {path} {ops.Description}");
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ public ConnectorSettings(string @namespace)
/// Allow using functions that are identified as unsupported.
/// NotSupportedReason property will still be specified.
/// </summary>
public bool AllowUnsupportedFunctions { get; init; } = false;

public bool AllowUnsupportedFunctions { get; init; } = false;

/// <summary>
/// Include webhook functions that contain "x-ms-notification-content" in definition.
/// By default these functions won't be accessible by end users.
/// </summary>
public bool IncludeWebhookFunctions { get; init; } = false;

/// <summary>
/// By default these functions won't be accessible by end users.
/// Internally, internal functions will be kept (ConnectorFunction.FunctionList) as some of those are used for dynamic intellisense.
/// </summary>
public bool IncludeInternalFunctions { get; init; } = false;
public bool IncludeInternalFunctions { get; init; } = false;

/// <summary>
/// In Power Apps, all record fields which are not declared in the swagger file will not be part of the Power Fx response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,22 @@ public async Task Teams_GetMessageDetails_WithComplexParameterReference()
Assert.Equal(2, connectorTypeWithSuggestions.ConnectorSuggestions.Suggestions.Count);
Assert.Equal("channelName", connectorTypeWithSuggestions.ConnectorSuggestions.Suggestions[0].DisplayName);
Assert.Equal("channelName2", connectorTypeWithSuggestions.ConnectorSuggestions.Suggestions[1].DisplayName);
}

[Fact]
public async Task Teams_PostCardAndWaitForResponse()
{
using var testConnector = new LoggingTestServer(@"Swagger\Teams.json", _output);
using var httpClient = new HttpClient(testConnector);
using PowerPlatformConnectorClient client = new PowerPlatformConnectorClient("https://tip1002-002.azure-apihub.net", "7592282b-e371-e3f6-8e04-e8f23e64227c" /* environment Id */, "shared-cardsforpower-eafc4fa0-c560-4eba-a5b2-3e1ebc63193a" /* connectionId */, () => "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dC...", httpClient) { SessionId = "a41bd03b-6c3c-4509-a844-e8c51b61f878" };

BaseRuntimeConnectorContext runtimeContext = new TestConnectorRuntimeContext("DV", client, console: _output);

ConnectorFunction[] functionsWithWebhooks = OpenApiParser.GetFunctions(new ConnectorSettings("DV") { Compatibility = ConnectorCompatibility.SwaggerCompatibility, IncludeWebhookFunctions = true }, testConnector._apiDocument).ToArray();
ConnectorFunction[] functionsWithoutWebhooks = OpenApiParser.GetFunctions(new ConnectorSettings("DV") { Compatibility = ConnectorCompatibility.SwaggerCompatibility }, testConnector._apiDocument).ToArray();

Assert.NotNull(functionsWithWebhooks.FirstOrDefault(f => f.Name == "PostCardAndWaitForResponse"));
Assert.Null(functionsWithoutWebhooks.FirstOrDefault(f => f.Name == "PostCardAndWaitForResponse"));
}

[Fact]
Expand Down

0 comments on commit cf51f35

Please sign in to comment.