Skip to content

Commit 369e7fd

Browse files
committed
feat(AssistantV2): add support for ListLogs and DeleteUserData
1 parent f6c0ed0 commit 369e7fd

14 files changed

+464
-24
lines changed

Scripts/Services/Assistant/V2/AssistantService.cs

+179-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace IBM.Watson.Assistant.V2
3232
public partial class AssistantService : BaseService
3333
{
3434
private const string serviceId = "assistant";
35-
private const string defaultServiceUrl = "https://gateway.watsonplatform.net/assistant/api";
35+
private const string defaultServiceUrl = "https://api.us-south.assistant.watson.cloud.ibm.com";
3636

3737
#region VersionDate
3838
private string versionDate;
@@ -246,8 +246,6 @@ private void OnDeleteSessionResponse(RESTConnector.Request req, RESTConnector.Re
246246
///
247247
/// Send user input to an assistant and receive a response, with conversation state (including context data)
248248
/// stored by Watson Assistant for the duration of the session.
249-
///
250-
/// There is no rate limit for this operation.
251249
/// </summary>
252250
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
253251
/// <param name="assistantId">Unique identifier of the assistant. To find the assistant ID in the Watson
@@ -341,8 +339,6 @@ private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response
341339
///
342340
/// Send user input to an assistant and receive a response, with conversation state (including context data)
343341
/// managed by your application.
344-
///
345-
/// There is no rate limit for this operation.
346342
/// </summary>
347343
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
348344
/// <param name="assistantId">Unique identifier of the assistant. To find the assistant ID in the Watson
@@ -427,5 +423,183 @@ private void OnMessageStatelessResponse(RESTConnector.Request req, RESTConnector
427423
if (((RequestObject<MessageResponseStateless>)req).Callback != null)
428424
((RequestObject<MessageResponseStateless>)req).Callback(response, resp.Error);
429425
}
426+
/// <summary>
427+
/// List log events for an assistant.
428+
///
429+
/// List the events from the log of an assistant.
430+
///
431+
/// This method is available only with Premium plans.
432+
/// </summary>
433+
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
434+
/// <param name="assistantId">Unique identifier of the assistant. To find the assistant ID in the Watson
435+
/// Assistant user interface, open the assistant settings and click **API Details**. For information about
436+
/// creating assistants, see the
437+
/// [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-add#assistant-add-task).
438+
///
439+
/// **Note:** Currently, the v2 API does not support creating assistants.</param>
440+
/// <param name="sort">How to sort the returned log events. You can sort by **request_timestamp**. To reverse
441+
/// the sort order, prefix the parameter value with a minus sign (`-`). (optional)</param>
442+
/// <param name="filter">A cacheable parameter that limits the results to those matching the specified filter.
443+
/// For more information, see the
444+
/// [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-filter-reference#filter-reference).
445+
/// (optional)</param>
446+
/// <param name="pageLimit">The number of records to return in each page of results. (optional)</param>
447+
/// <param name="cursor">A token identifying the page of results to retrieve. (optional)</param>
448+
/// <returns><see cref="LogCollection" />LogCollection</returns>
449+
public bool ListLogs(Callback<LogCollection> callback, string assistantId, string sort = null, string filter = null, long? pageLimit = null, string cursor = null)
450+
{
451+
if (callback == null)
452+
throw new ArgumentNullException("`callback` is required for `ListLogs`");
453+
if (string.IsNullOrEmpty(assistantId))
454+
throw new ArgumentNullException("`assistantId` is required for `ListLogs`");
455+
456+
RequestObject<LogCollection> req = new RequestObject<LogCollection>
457+
{
458+
Callback = callback,
459+
HttpMethod = UnityWebRequest.kHttpVerbGET,
460+
DisableSslVerification = DisableSslVerification
461+
};
462+
463+
foreach (KeyValuePair<string, string> kvp in customRequestHeaders)
464+
{
465+
req.Headers.Add(kvp.Key, kvp.Value);
466+
}
467+
468+
ClearCustomRequestHeaders();
469+
470+
foreach (KeyValuePair<string, string> kvp in Common.GetSdkHeaders("conversation", "V2", "ListLogs"))
471+
{
472+
req.Headers.Add(kvp.Key, kvp.Value);
473+
}
474+
475+
req.Parameters["version"] = VersionDate;
476+
if (!string.IsNullOrEmpty(sort))
477+
{
478+
req.Parameters["sort"] = sort;
479+
}
480+
if (!string.IsNullOrEmpty(filter))
481+
{
482+
req.Parameters["filter"] = filter;
483+
}
484+
if (pageLimit != null)
485+
{
486+
req.Parameters["page_limit"] = pageLimit;
487+
}
488+
if (!string.IsNullOrEmpty(cursor))
489+
{
490+
req.Parameters["cursor"] = cursor;
491+
}
492+
493+
req.OnResponse = OnListLogsResponse;
494+
495+
Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/logs", assistantId);
496+
Authenticator.Authenticate(Connector);
497+
498+
return Connector.Send(req);
499+
}
500+
501+
private void OnListLogsResponse(RESTConnector.Request req, RESTConnector.Response resp)
502+
{
503+
DetailedResponse<LogCollection> response = new DetailedResponse<LogCollection>();
504+
foreach (KeyValuePair<string, string> kvp in resp.Headers)
505+
{
506+
response.Headers.Add(kvp.Key, kvp.Value);
507+
}
508+
response.StatusCode = resp.HttpResponseCode;
509+
510+
try
511+
{
512+
string json = Encoding.UTF8.GetString(resp.Data);
513+
response.Result = JsonConvert.DeserializeObject<LogCollection>(json);
514+
response.Response = json;
515+
}
516+
catch (Exception e)
517+
{
518+
Log.Error("AssistantService.OnListLogsResponse()", "Exception: {0}", e.ToString());
519+
resp.Success = false;
520+
}
521+
522+
if (((RequestObject<LogCollection>)req).Callback != null)
523+
((RequestObject<LogCollection>)req).Callback(response, resp.Error);
524+
}
525+
/// <summary>
526+
/// Delete labeled data.
527+
///
528+
/// Deletes all data associated with a specified customer ID. The method has no effect if no data is associated
529+
/// with the customer ID.
530+
///
531+
/// You associate a customer ID with data by passing the `X-Watson-Metadata` header with a request that passes
532+
/// data. For more information about personal data and customer IDs, see [Information
533+
/// security](https://cloud.ibm.com/docs/assistant?topic=assistant-information-security#information-security).
534+
///
535+
/// This operation is limited to 4 requests per minute. For more information, see **Rate limiting**.
536+
/// </summary>
537+
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
538+
/// <param name="customerId">The customer ID for which all data is to be deleted.</param>
539+
/// <returns><see cref="object" />object</returns>
540+
public bool DeleteUserData(Callback<object> callback, string customerId)
541+
{
542+
if (callback == null)
543+
throw new ArgumentNullException("`callback` is required for `DeleteUserData`");
544+
if (string.IsNullOrEmpty(customerId))
545+
throw new ArgumentNullException("`customerId` is required for `DeleteUserData`");
546+
547+
RequestObject<object> req = new RequestObject<object>
548+
{
549+
Callback = callback,
550+
HttpMethod = UnityWebRequest.kHttpVerbDELETE,
551+
DisableSslVerification = DisableSslVerification
552+
};
553+
554+
foreach (KeyValuePair<string, string> kvp in customRequestHeaders)
555+
{
556+
req.Headers.Add(kvp.Key, kvp.Value);
557+
}
558+
559+
ClearCustomRequestHeaders();
560+
561+
foreach (KeyValuePair<string, string> kvp in Common.GetSdkHeaders("conversation", "V2", "DeleteUserData"))
562+
{
563+
req.Headers.Add(kvp.Key, kvp.Value);
564+
}
565+
566+
req.Parameters["version"] = VersionDate;
567+
if (!string.IsNullOrEmpty(customerId))
568+
{
569+
req.Parameters["customer_id"] = customerId;
570+
}
571+
572+
req.OnResponse = OnDeleteUserDataResponse;
573+
574+
Connector.URL = GetServiceUrl() + "/v2/user_data";
575+
Authenticator.Authenticate(Connector);
576+
577+
return Connector.Send(req);
578+
}
579+
580+
private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp)
581+
{
582+
DetailedResponse<object> response = new DetailedResponse<object>();
583+
foreach (KeyValuePair<string, string> kvp in resp.Headers)
584+
{
585+
response.Headers.Add(kvp.Key, kvp.Value);
586+
}
587+
response.StatusCode = resp.HttpResponseCode;
588+
589+
try
590+
{
591+
string json = Encoding.UTF8.GetString(resp.Data);
592+
response.Result = JsonConvert.DeserializeObject<object>(json);
593+
response.Response = json;
594+
}
595+
catch (Exception e)
596+
{
597+
Log.Error("AssistantService.OnDeleteUserDataResponse()", "Exception: {0}", e.ToString());
598+
resp.Success = false;
599+
}
600+
601+
if (((RequestObject<object>)req).Callback != null)
602+
((RequestObject<object>)req).Callback(response, resp.Error);
603+
}
430604
}
431605
}

Scripts/Services/Assistant/V2/Model/DialogSuggestion.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018, 2019 IBM Corp. All Rights Reserved.
2+
* (C) Copyright IBM Corp. 2018, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@ namespace IBM.Watson.Assistant.V2.Model
2626
public class DialogSuggestion
2727
{
2828
/// <summary>
29-
/// The user-facing label for the disambiguation option. This label is taken from the **title** or
30-
/// **user_label** property of the corresponding dialog node, depending on the disambiguation options.
29+
/// The user-facing label for the suggestion. This label is taken from the **title** or **user_label** property
30+
/// of the corresponding dialog node, depending on the disambiguation options.
3131
/// </summary>
3232
[JsonProperty("label", NullValueHandling = NullValueHandling.Ignore)]
3333
public string Label { get; set; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using System.Collections.Generic;
19+
using Newtonsoft.Json;
20+
21+
namespace IBM.Watson.Assistant.V2.Model
22+
{
23+
/// <summary>
24+
/// LogCollection.
25+
/// </summary>
26+
public class LogCollection
27+
{
28+
/// <summary>
29+
/// An array of objects describing log events.
30+
/// </summary>
31+
[JsonProperty("logs", NullValueHandling = NullValueHandling.Ignore)]
32+
public List<ModelLog> Logs { get; set; }
33+
/// <summary>
34+
/// The pagination data for the returned objects.
35+
/// </summary>
36+
[JsonProperty("pagination", NullValueHandling = NullValueHandling.Ignore)]
37+
public LogPagination Pagination { get; set; }
38+
}
39+
}

Scripts/Services/Assistant/V2/Model/LogCollection.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using Newtonsoft.Json;
19+
20+
namespace IBM.Watson.Assistant.V2.Model
21+
{
22+
/// <summary>
23+
/// The pagination data for the returned objects.
24+
/// </summary>
25+
public class LogPagination
26+
{
27+
/// <summary>
28+
/// The URL that will return the next page of results, if any.
29+
/// </summary>
30+
[JsonProperty("next_url", NullValueHandling = NullValueHandling.Ignore)]
31+
public string NextUrl { get; set; }
32+
/// <summary>
33+
/// Reserved for future use.
34+
/// </summary>
35+
[JsonProperty("matched", NullValueHandling = NullValueHandling.Ignore)]
36+
public long? Matched { get; set; }
37+
/// <summary>
38+
/// A token identifying the next page of results.
39+
/// </summary>
40+
[JsonProperty("next_cursor", NullValueHandling = NullValueHandling.Ignore)]
41+
public string NextCursor { get; set; }
42+
}
43+
}

Scripts/Services/Assistant/V2/Model/LogPagination.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
using Newtonsoft.Json;
19+
20+
namespace IBM.Watson.Assistant.V2.Model
21+
{
22+
/// <summary>
23+
/// A stateful message request formatted for the Watson Assistant service.
24+
/// </summary>
25+
public class MessageRequest
26+
{
27+
/// <summary>
28+
/// An input object that includes the input text.
29+
/// </summary>
30+
[JsonProperty("input", NullValueHandling = NullValueHandling.Ignore)]
31+
public MessageInput Input { get; set; }
32+
/// <summary>
33+
/// Context data for the conversation. You can use this property to set or modify context variables, which can
34+
/// also be accessed by dialog nodes. The context is stored by the assistant on a per-session basis.
35+
///
36+
/// **Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
37+
/// </summary>
38+
[JsonProperty("context", NullValueHandling = NullValueHandling.Ignore)]
39+
public MessageContext Context { get; set; }
40+
}
41+
}

Scripts/Services/Assistant/V2/Model/MessageRequest.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)