Skip to content

Commit 25344f8

Browse files
committed
chore(Assistant V1): Use JObject as dynamic type, write integration tests
1 parent 6c18de2 commit 25344f8

11 files changed

+288
-159
lines changed

Scripts/Services/Assistant/V1/AssistantService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ public AssistantService(string versionDate, Credentials credentials) : base(vers
153153
/// <param name="customData">A Dictionary<string, object> of data that will be passed to the callback. The raw
154154
/// json output from the REST call will be passed in this object as the value of the 'json'
155155
/// key.</string></param>
156-
/// <returns><see cref="Dictionary<string, JObject>" />Dictionary<string, JObject></returns>
157-
public bool Message(Callback<Dictionary<string, JObject>> callback, string workspaceId, Dictionary<string, object> customData = null, Dictionary<string, JObject> input = null, bool? alternateIntents = null, Dictionary<string, JObject> context = null, List<Dictionary<string, JObject>> entities = null, List<Dictionary<string, JObject>> intents = null, Dictionary<string, JObject> output = null, bool? nodesVisitedDetails = null)
156+
/// <returns><see cref="JObject" />JObject</returns>
157+
public bool Message(Callback<JObject> callback, string workspaceId, Dictionary<string, object> customData = null, JObject input = null, bool? alternateIntents = null, JObject context = null, List<JObject> entities = null, List<JObject> intents = null, JObject output = null, bool? nodesVisitedDetails = null)
158158
{
159159
if (callback == null)
160160
throw new ArgumentNullException("`callback` is required for `Message`");
161161
if (string.IsNullOrEmpty(workspaceId))
162162
throw new ArgumentNullException("`workspaceId` is required for `Message`");
163163

164-
RequestObject<Dictionary<string, JObject>> req = new RequestObject<Dictionary<string, JObject>>
164+
RequestObject<JObject> req = new RequestObject<JObject>
165165
{
166166
Callback = callback,
167167
HttpMethod = UnityWebRequest.kHttpVerbPOST,
@@ -218,8 +218,8 @@ public bool Message(Callback<Dictionary<string, JObject>> callback, string works
218218

219219
private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response resp)
220220
{
221-
DetailedResponse<Dictionary<string, JObject>> response = new DetailedResponse<Dictionary<string, JObject>>();
222-
Dictionary<string, object> customData = ((RequestObject<Dictionary<string, JObject>>)req).CustomData;
221+
DetailedResponse<JObject> response = new DetailedResponse<JObject>();
222+
Dictionary<string, object> customData = ((RequestObject<JObject>)req).CustomData;
223223
foreach (KeyValuePair<string, string> kvp in resp.Headers)
224224
{
225225
response.Headers.Add(kvp.Key, kvp.Value);
@@ -229,7 +229,7 @@ private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response
229229
try
230230
{
231231
string json = Encoding.UTF8.GetString(resp.Data);
232-
response.Result = JsonConvert.DeserializeObject<Dictionary<string, JObject>>(json);
232+
response.Result = JsonConvert.DeserializeObject<JObject>(json);
233233
customData.Add("json", json);
234234
}
235235
catch (Exception e)
@@ -238,8 +238,8 @@ private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response
238238
resp.Success = false;
239239
}
240240

241-
if (((RequestObject<Dictionary<string, JObject>>)req).Callback != null)
242-
((RequestObject<Dictionary<string, JObject>>)req).Callback(response, resp.Error, customData);
241+
if (((RequestObject<JObject>)req).Callback != null)
242+
((RequestObject<JObject>)req).Callback(response, resp.Error, customData);
243243
}
244244
/// <summary>
245245
/// Create workspace.
@@ -3895,7 +3895,7 @@ private void OnUpdateSynonymResponse(RESTConnector.Request req, RESTConnector.Re
38953895
/// json output from the REST call will be passed in this object as the value of the 'json'
38963896
/// key.</string></param>
38973897
/// <returns><see cref="DialogNode" />DialogNode</returns>
3898-
public bool CreateDialogNode(Callback<DialogNode> callback, string workspaceId, string dialogNode, Dictionary<string, object> customData = null, string description = null, string conditions = null, string parent = null, string previousSibling = null, Dictionary<string, JObject> output = null, object context = null, object metadata = null, DialogNodeNextStep nextStep = null, List<DialogNodeAction> actions = null, string title = null, string type = null, string eventName = null, string variable = null, string digressIn = null, string digressOut = null, string digressOutSlots = null, string userLabel = null)
3898+
public bool CreateDialogNode(Callback<DialogNode> callback, string workspaceId, string dialogNode, Dictionary<string, object> customData = null, string description = null, string conditions = null, string parent = null, string previousSibling = null, JObject output = null, object context = null, object metadata = null, DialogNodeNextStep nextStep = null, List<DialogNodeAction> actions = null, string title = null, string type = null, string eventName = null, string variable = null, string digressIn = null, string digressOut = null, string digressOutSlots = null, string userLabel = null)
38993899
{
39003900
if (callback == null)
39013901
throw new ArgumentNullException("`callback` is required for `CreateDialogNode`");
@@ -4328,7 +4328,7 @@ private void OnListDialogNodesResponse(RESTConnector.Request req, RESTConnector.
43284328
/// json output from the REST call will be passed in this object as the value of the 'json'
43294329
/// key.</string></param>
43304330
/// <returns><see cref="DialogNode" />DialogNode</returns>
4331-
public bool UpdateDialogNode(Callback<DialogNode> callback, string workspaceId, string dialogNode, Dictionary<string, object> customData = null, string newDialogNode = null, string newDescription = null, string newConditions = null, string newParent = null, string newPreviousSibling = null, Dictionary<string, JObject> newOutput = null, object newContext = null, object newMetadata = null, DialogNodeNextStep newNextStep = null, string newTitle = null, string newType = null, string newEventName = null, string newVariable = null, List<DialogNodeAction> newActions = null, string newDigressIn = null, string newDigressOut = null, string newDigressOutSlots = null, string newUserLabel = null)
4331+
public bool UpdateDialogNode(Callback<DialogNode> callback, string workspaceId, string dialogNode, Dictionary<string, object> customData = null, string newDialogNode = null, string newDescription = null, string newConditions = null, string newParent = null, string newPreviousSibling = null, JObject newOutput = null, object newContext = null, object newMetadata = null, DialogNodeNextStep newNextStep = null, string newTitle = null, string newType = null, string newEventName = null, string newVariable = null, List<DialogNodeAction> newActions = null, string newDigressIn = null, string newDigressOut = null, string newDigressOutSlots = null, string newUserLabel = null)
43324332
{
43334333
if (callback == null)
43344334
throw new ArgumentNullException("`callback` is required for `UpdateDialogNode`");

Scripts/Services/Assistant/V1/Model/Context.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
*/
1717

18-
using System.Collections.Generic;
1918
using Newtonsoft.Json;
2019
using Newtonsoft.Json.Linq;
2120

@@ -35,7 +34,7 @@ public class Context
3534
/// For internal use only.
3635
/// </summary>
3736
[JsonProperty("system", NullValueHandling = NullValueHandling.Ignore)]
38-
public Dictionary<string, JObject> System { get; set; }
37+
public JObject System { get; set; }
3938
/// <summary>
4039
/// Metadata related to the message.
4140
/// </summary>

Scripts/Services/Assistant/V1/Model/CreateDialogNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public class DigressOutSlotsValue
226226
/// [documentation](https://cloud.ibm.com/docs/services/assistant/dialog-overview.html#complex).
227227
/// </summary>
228228
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
229-
public Dictionary<string, JObject> Output { get; set; }
229+
public JObject Output { get; set; }
230230
/// <summary>
231231
/// The context for the dialog node.
232232
/// </summary>

Scripts/Services/Assistant/V1/Model/DialogNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public class DigressOutSlotsValue
227227
/// [documentation](https://cloud.ibm.com/docs/services/assistant/dialog-overview.html#complex).
228228
/// </summary>
229229
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
230-
public Dictionary<string, JObject> Output { get; set; }
230+
public JObject Output { get; set; }
231231
/// <summary>
232232
/// The context for the dialog node.
233233
/// </summary>

Scripts/Services/Assistant/V1/Model/DialogNodeOutputOptionsElementValue.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
*/
1717

18-
using System.Collections.Generic;
1918
using Newtonsoft.Json;
2019
using Newtonsoft.Json.Linq;
2120

@@ -31,6 +30,6 @@ public class DialogNodeOutputOptionsElementValue
3130
/// An input object that includes the input text.
3231
/// </summary>
3332
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
34-
public Dictionary<string, JObject> Input { get; set; }
33+
public JObject Input { get; set; }
3534
}
3635
}

Scripts/Services/Assistant/V1/Model/DialogSuggestionValue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ public class DialogSuggestionValue
3131
/// An input object that includes the input text.
3232
/// </summary>
3333
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
34-
public Dictionary<string, JObject> Input { get; set; }
34+
public JObject Input { get; set; }
3535
/// <summary>
3636
/// An array of intents to be sent along with the user input.
3737
/// </summary>
3838
[JsonProperty("intents", NullValueHandling = NullValueHandling.Ignore)]
39-
public List<Dictionary<string, JObject>> Intents { get; set; }
39+
public List<JObject> Intents { get; set; }
4040
/// <summary>
4141
/// An array of entities to be sent along with the user input.
4242
/// </summary>
4343
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
44-
public List<Dictionary<string, JObject>> Entities { get; set; }
44+
public List<JObject> Entities { get; set; }
4545
}
4646
}

Scripts/Services/Assistant/V1/Model/LogExport.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*
1616
*/
1717

18-
using System.Collections.Generic;
1918
using Newtonsoft.Json;
2019
using Newtonsoft.Json.Linq;
2120

@@ -35,7 +34,7 @@ public class LogExport
3534
/// The response sent by the workspace, including the output text, detected intents and entities, and context.
3635
/// </summary>
3736
[JsonProperty("response", NullValueHandling = NullValueHandling.Ignore)]
38-
public Dictionary<string, JObject> Response { get; set; }
37+
public JObject Response { get; set; }
3938
/// <summary>
4039
/// A unique identifier for the logged event.
4140
/// </summary>

Scripts/Services/Assistant/V1/Model/MessageRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class MessageRequest
3030
/// An input object that includes the input text.
3131
/// </summary>
3232
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
33-
public Dictionary<string, JObject> Input { get; set; }
33+
public JObject Input { get; set; }
3434
/// <summary>
3535
/// Whether to return more than one intent. Set to `true` to return all matching intents.
3636
/// </summary>
@@ -40,24 +40,24 @@ public class MessageRequest
4040
/// State information for the conversation. To maintain state, include the context from the previous response.
4141
/// </summary>
4242
[JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)]
43-
public Dictionary<string, JObject> Context { get; set; }
43+
public JObject Context { get; set; }
4444
/// <summary>
4545
/// Entities to use when evaluating the message. Include entities from the previous response to continue using
4646
/// those entities rather than detecting entities in the new input.
4747
/// </summary>
4848
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
49-
public List<Dictionary<string, JObject>> Entities { get; set; }
49+
public List<JObject> Entities { get; set; }
5050
/// <summary>
5151
/// Intents to use when evaluating the user input. Include intents from the previous response to continue using
5252
/// those intents rather than trying to recognize intents in the new input.
5353
/// </summary>
5454
[JsonProperty("intents", NullValueHandling = NullValueHandling.Ignore)]
55-
public List<Dictionary<string, JObject>> Intents { get; set; }
55+
public List<JObject> Intents { get; set; }
5656
/// <summary>
5757
/// An output object that includes the response to the user, the dialog nodes that were triggered, and messages
5858
/// from the log.
5959
/// </summary>
6060
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
61-
public Dictionary<string, JObject> Output { get; set; }
61+
public JObject Output { get; set; }
6262
}
6363
}

Scripts/Services/Assistant/V1/Model/MessageResponse.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public class MessageResponse
3535
/// An array of intents recognized in the user input, sorted in descending order of confidence.
3636
/// </summary>
3737
[JsonProperty("intents", NullValueHandling = NullValueHandling.Ignore)]
38-
public List<Dictionary<string, JObject>> Intents { get; set; }
38+
public List<JObject> Intents { get; set; }
3939
/// <summary>
4040
/// An array of entities identified in the user input.
4141
/// </summary>
4242
[JsonProperty("entities", NullValueHandling = NullValueHandling.Ignore)]
43-
public List<Dictionary<string, JObject>> Entities { get; set; }
43+
public List<JObject> Entities { get; set; }
4444
/// <summary>
4545
/// Whether to return more than one intent. A value of `true` indicates that all matching intents are returned.
4646
/// </summary>
@@ -50,13 +50,13 @@ public class MessageResponse
5050
/// State information for the conversation. To maintain state, include the context from the previous response.
5151
/// </summary>
5252
[JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)]
53-
public Dictionary<string, JObject> Context { get; set; }
53+
public JObject Context { get; set; }
5454
/// <summary>
5555
/// An output object that includes the response to the user, the dialog nodes that were triggered, and messages
5656
/// from the log.
5757
/// </summary>
5858
[JsonProperty("output", NullValueHandling = NullValueHandling.Ignore)]
59-
public Dictionary<string, JObject> Output { get; set; }
59+
public JObject Output { get; set; }
6060
/// <summary>
6161
/// An array of objects describing any actions requested by the dialog node.
6262
/// </summary>

Scripts/Services/Assistant/V1/Model/OutputData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class OutputData
3131
/// An array of up to 50 messages logged with the request.
3232
/// </summary>
3333
[JsonProperty("log_messages", NullValueHandling = NullValueHandling.Ignore)]
34-
public List<Dictionary<string, JObject>> LogMessages { get; set; }
34+
public List<JObject> LogMessages { get; set; }
3535
/// <summary>
3636
/// An array of responses to the user.
3737
/// </summary>

0 commit comments

Comments
 (0)