GOOGLE ADS

Samstag, 16. April 2022

Bot Framework Custom Action und benutzerdefinierte ArrayExpression-Eigenschaft

Ich baue einen Bot mit dem Bot Framework Composer von Microsoft. Um die Standardfunktionen des Composers zu erweitern, habe ich auch einige benutzerdefinierte Aktionen erstellt, darunter eine, die Eingaben in Form eines Arrays eines bestimmten Typs benötigt. Hier ist das Schema:

{
"$schema": "https://schemas.botframework.com/schemas/component/v1.0/component.schema",
"$role": "implements(Microsoft.IDialog)",
"title": "AdvancePropertyTest",
"description": "Test advanced properties in for custom actions.",
"type": "object",
"additionalProperties": false,
"properties": {
"skillSelectors": {
"$ref": "schema:#/definitions/arrayExpression",
"title": "SkillSelector Items",
"description": "SkillSelector Items.",
"items": {
"title": "SkillSelector Item",
"description": "SkillSelector Item.",
"type": "object",
"properties": {
"key": {
"title": "Key",
"description": "The skill key to query against.",
"type": "string"
},
"operator": {
"title": "Operator",
"description": "Describes how the value of the label is compared to the value defined on the label selector.",
"type": "string",
"enum": [
"Equal",
"NotEqual",
"LessThan",
"LessThanEqual",
"GreaterThan",
"GreaterThanEqual"
],
"default": "Equal"
},
"value": {
"title": "Value",
"description": "The value to compare against the actual label value with the given operator.",
"type": "integer"
}
}
}
}
}
}

was im Composer zu Folgendem führt:
Composer-Aktion mit benutzerdefinierten Eigenschaften

So weit, ist es gut. Nun, im Code des Dialogs, um die Eingabedaten abzurufen, habe ich Folgendes getan:

[Serializable]
public class SkillSelector
{
[JsonProperty(PropertyName = "key")]
public string Key { get; set; }
[JsonProperty(PropertyName = "operator")]
public string Operator { get; set; }
[JsonProperty(PropertyName = "value")]
public int Value { get; set; }
}
public class AdvancedPropertyTest: Dialog
{
[JsonProperty("skillSelectors")]
public ArrayExpression<SkillSelector> SkillSelectors { get; set; }
//public ArrayExpression<Metadata> SkillSelectors { get; set; }
public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default)
{
var skillSelectors = SkillSelectors?.GetValue(dc.State);
// some code
return await dc.EndDialogAsync(cancellationToken: cancellationToken);
}
}

Leider führt dies zu folgender Fehlermeldung, wenn ich es ausführe:

AdvancedProperties.dialog error: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'AdaptiveExpressions.Properties.ArrayExpression`1[SkillSelector]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path 'skillSelectors', line 49, position 37.

Interessante Tatsache, die Verwendung der Klasse Microsoft.Bot.Builder.AI.QnA.MetaData als generischer Typ in ArrayExpression macht den Trick, ist aber natürlich nicht das, was ich will.

Jemand eine Idee wie man das macht? Jede Hilfe wäre sehr willkommen Cheers.


Lösung des Problems

Ihre Eigenschaften sollten von stammen AdaptiveExpressions.Properties. Verwenden Sie also anstelle von Zeichenfolgen StringExpression, BoolExpression, usw.:

 [JsonProperty("businessUnitName")]
public StringExpression BusinessUnitName { get; set; }
[JsonProperty("reloadData")]
public BoolExpression ReloadData { get; set; }

Um den Wert zu erhalten:

BusinessUnitName.GetValue(dc.State)

Keine Kommentare:

Kommentar veröffentlichen

Warum werden SCHED_FIFO-Threads derselben physischen CPU zugewiesen, obwohl CPUs im Leerlauf verfügbar sind?

Lösung des Problems Wenn ich das richtig verstehe, versuchen Sie, SCHED_FIFO mit aktiviertem Hyperthreading ("HT") zu verwenden, ...