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

Adaptive HttpRequest body does not interpret property for body field #3219

Closed
scheyal opened this issue Jan 6, 2020 · 1 comment
Closed
Assignees
Labels
R8 Release 8 - March 16th, 2020
Milestone

Comments

@scheyal
Copy link
Contributor

scheyal commented Jan 6, 2020

‘Body’ is taking the property string literally "@{dialog.httpbody}". It seems that Body requires a JObject. In turn, Json is throwing an exception

Example:

new Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.HttpRequest()
                                    {
                                        // Set response from the http request to turn.httpResponse property in memory.
                                        ResultProperty = "dialog.httpResponse",
                                        Url = apiUrl,
                                        Method = HttpRequest.HttpMethod.POST,
                                        Body = "@{dialog.httpbody}",
                                        ResponseType = HttpRequest.ResponseTypes.None
                                    },

$exception {System.InvalidOperationException: The parent is missing.
at Newtonsoft.Json.Linq.JToken.Replace(JToken value)
at Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.HttpRequest.ReplaceJTokenRecursively(DialogContext dc, JToken token)
at Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.HttpRequest.BeginDialogAsync(DialogContext dc, Object options, CancellationToken cancellationToken)

@vishwacsena vishwacsena added adaptive R8 Release 8 - March 16th, 2020 labels Jan 6, 2020
@vishwacsena
Copy link
Contributor

vishwacsena commented Jan 14, 2020

I debugged this and the core issue seems to be twofold.

Issue #1: we should consider adding headers without validation TryAddWithoutValidation so things like adding content-type does not blow up (it does with a .Add())

// Set headers
if (instanceHeaders != null)
{
    foreach (var unit in instanceHeaders)
    {
        client.DefaultRequestHeaders.TryAddWithoutValidation(
            await new TextTemplate(unit.Key).BindToData(dc.Context, dc.GetState()).ConfigureAwait(false),
            await new TextTemplate(unit.Value).BindToData(dc.Context, dc.GetState()).ConfigureAwait(false));
    }
}

Issue #2: Data binding within JArray blows up in ReplaceJTokenRecursively

new HttpRequest()
{
    Body = new JObject(
            new JProperty(
                "list",
                new JArray(
                    new JValue("@{dialog.appId1}"),
                    new JValue("@{dialog.appId2}")))),
    Url = ""
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R8 Release 8 - March 16th, 2020
Projects
None yet
Development

No branches or pull requests

4 participants