Skip to content

Commit

Permalink
Merge pull request #1042 from watson-developer-cloud/update-schemas
Browse files Browse the repository at this point in the history
fix(assistant): adjust agent availability schema
  • Loading branch information
jeff-arn authored Dec 22, 2020
2 parents f58b90e + 69e7da4 commit 5595caa
Show file tree
Hide file tree
Showing 13 changed files with 369 additions and 218 deletions.
170 changes: 85 additions & 85 deletions Sources/AssistantV1/Assistant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
**/

/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-36b26b63-20201028-122900
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-be3b4618-20201221-123327
**/

// swiftlint:disable file_length
Expand Down Expand Up @@ -263,6 +263,90 @@ public class Assistant {
// swiftlint:enable identifier_name
}

/**
Identify intents and entities in multiple user utterances.
Send multiple user inputs to a workspace in a single request and receive information about the intents and entities
recognized in each input. This method is useful for testing and comparing the performance of different workspaces.
This method is available only with Premium plans.
- parameter workspaceID: Unique identifier of the workspace.
- parameter input: An array of input utterances to classify.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func bulkClassify(
workspaceID: String,
input: [BulkClassifyUtterance]? = nil,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<BulkClassifyResponse>?, WatsonError?) -> Void)
{
// construct body
let bulkClassifyRequest = BulkClassifyRequest(
input: input)
let body: Data?
do {
body = try JSON.encoder.encodeIfPresent(bulkClassifyRequest)
} catch {
completionHandler(nil, RestError.serialization(values: "request body"))
return
}

// construct header parameters
var headerParameters = defaultHeaders
let sdkHeaders = Shared.getSDKHeaders(serviceName: serviceName, serviceVersion: serviceVersion, methodName: "bulkClassify")
headerParameters.merge(sdkHeaders) { (_, new) in new }
headerParameters["Accept"] = "application/json"
headerParameters["Content-Type"] = "application/json"
if let headers = headers {
headerParameters.merge(headers) { (_, new) in new }
}

// construct query parameters
var queryParameters = [URLQueryItem]()
queryParameters.append(URLQueryItem(name: "version", value: version))

// construct REST request
let path = "/v1/workspaces/\(workspaceID)/bulk_classify"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
completionHandler(nil, RestError.urlEncoding(path: path))
return
}

// ensure that serviceURL is set
guard let serviceEndpoint = serviceURL else {
completionHandler(nil, RestError.noEndpoint)
return
}

let request = RestRequest(
session: session,
authenticator: authenticator,
errorResponseDecoder: errorResponseDecoder,
method: "POST",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters,
messageBody: body
)

// execute REST request
request.responseObject(completionHandler: completionHandler)
}

// Private struct for the bulkClassify request body
private struct BulkClassifyRequest: Encodable {
// swiftlint:disable identifier_name
let input: [BulkClassifyUtterance]?
init? (input: [BulkClassifyUtterance]? = nil) {
if input == nil {
return nil
}
self.input = input
}
// swiftlint:enable identifier_name
}

/**
List workspaces.
Expand Down Expand Up @@ -4076,88 +4160,4 @@ public class Assistant {
request.response(completionHandler: completionHandler)
}

/**
Identify intents and entities in multiple user utterances.
Send multiple user inputs to a workspace in a single request and receive information about the intents and entities
recognized in each input. This method is useful for testing and comparing the performance of different workspaces.
This method is available only with Premium plans.
- parameter workspaceID: Unique identifier of the workspace.
- parameter input: An array of input utterances to classify.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
public func bulkClassify(
workspaceID: String,
input: [BulkClassifyUtterance]? = nil,
headers: [String: String]? = nil,
completionHandler: @escaping (WatsonResponse<BulkClassifyResponse>?, WatsonError?) -> Void)
{
// construct body
let bulkClassifyRequest = BulkClassifyRequest(
input: input)
let body: Data?
do {
body = try JSON.encoder.encodeIfPresent(bulkClassifyRequest)
} catch {
completionHandler(nil, RestError.serialization(values: "request body"))
return
}

// construct header parameters
var headerParameters = defaultHeaders
let sdkHeaders = Shared.getSDKHeaders(serviceName: serviceName, serviceVersion: serviceVersion, methodName: "bulkClassify")
headerParameters.merge(sdkHeaders) { (_, new) in new }
headerParameters["Accept"] = "application/json"
headerParameters["Content-Type"] = "application/json"
if let headers = headers {
headerParameters.merge(headers) { (_, new) in new }
}

// construct query parameters
var queryParameters = [URLQueryItem]()
queryParameters.append(URLQueryItem(name: "version", value: version))

// construct REST request
let path = "/v1/workspaces/\(workspaceID)/bulk_classify"
guard let encodedPath = path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
completionHandler(nil, RestError.urlEncoding(path: path))
return
}

// ensure that serviceURL is set
guard let serviceEndpoint = serviceURL else {
completionHandler(nil, RestError.noEndpoint)
return
}

let request = RestRequest(
session: session,
authenticator: authenticator,
errorResponseDecoder: errorResponseDecoder,
method: "POST",
url: serviceEndpoint + encodedPath,
headerParameters: headerParameters,
queryItems: queryParameters,
messageBody: body
)

// execute REST request
request.responseObject(completionHandler: completionHandler)
}

// Private struct for the bulkClassify request body
private struct BulkClassifyRequest: Encodable {
// swiftlint:disable identifier_name
let input: [BulkClassifyUtterance]?
init? (input: [BulkClassifyUtterance]? = nil) {
if input == nil {
return nil
}
self.input = input
}
// swiftlint:enable identifier_name
}

}
48 changes: 48 additions & 0 deletions Sources/AssistantV1/Models/AgentAvailabilityMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* (C) Copyright IBM Corp. 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import Foundation

/**
AgentAvailabilityMessage.
*/
public struct AgentAvailabilityMessage: Codable, Equatable {

/**
The text of the message.
*/
public var message: String?

// Map each property name to the key that shall be used for encoding/decoding.
private enum CodingKeys: String, CodingKey {
case message = "message"
}

/**
Initialize a `AgentAvailabilityMessage` with member variables.
- parameter message: The text of the message.
- returns: An initialized `AgentAvailabilityMessage`.
*/
public init(
message: String? = nil
)
{
self.message = message
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public struct DialogNodeOutputGenericDialogNodeOutputResponseTypeConnectToAgent:
An optional message to be displayed to the user to indicate that the conversation will be transferred to the next
available agent.
*/
public var agentAvailable: String?
public var agentAvailable: AgentAvailabilityMessage?

/**
An optional message to be displayed to the user to indicate that no online agent is available to take over the
conversation.
*/
public var agentUnavailable: String?
public var agentUnavailable: AgentAvailabilityMessage?

/**
Routing or other contextual information to be used by target service desk systems.
Expand Down Expand Up @@ -87,8 +87,8 @@ public struct DialogNodeOutputGenericDialogNodeOutputResponseTypeConnectToAgent:
public init(
responseType: String,
messageToHumanAgent: String? = nil,
agentAvailable: String? = nil,
agentUnavailable: String? = nil,
agentAvailable: AgentAvailabilityMessage? = nil,
agentUnavailable: AgentAvailabilityMessage? = nil,
transferInfo: DialogNodeOutputConnectToAgentTransferInfo? = nil
)
{
Expand Down
13 changes: 6 additions & 7 deletions Sources/AssistantV1/Models/RuntimeEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public struct RuntimeEntity: Codable, Equatable {
public var groups: [CaptureGroup]?

/**
An object containing detailed information about the entity recognized in the user input. This property is included
only if the new system entities are enabled for the workspace.
For more information about how the new system entities are interpreted, see the
[documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-beta-system-entities).
An object containing detailed information about the entity recognized in the user input.
For more information about how system entities are interpreted, see the
[documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-system-entities).
*/
public var interpretation: RuntimeEntityInterpretation?

Expand Down Expand Up @@ -100,9 +99,9 @@ public struct RuntimeEntity: Codable, Equatable {
- parameter metadata: Any metadata for the entity.
- parameter groups: The recognized capture groups for the entity, as defined by the entity pattern.
- parameter interpretation: An object containing detailed information about the entity recognized in the user
input. This property is included only if the new system entities are enabled for the workspace.
For more information about how the new system entities are interpreted, see the
[documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-beta-system-entities).
input.
For more information about how system entities are interpreted, see the
[documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-system-entities).
- parameter alternatives: An array of possible alternative values that the user might have intended instead of
the value returned in the **value** property. This property is returned only for `@sys-time` and `@sys-date`
entities when the user's input is ambiguous.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public struct RuntimeResponseGenericRuntimeResponseTypeConnectToAgent: Codable,
An optional message to be displayed to the user to indicate that the conversation will be transferred to the next
available agent.
*/
public var agentAvailable: String?
public var agentAvailable: AgentAvailabilityMessage?

/**
An optional message to be displayed to the user to indicate that no online agent is available to take over the
conversation.
*/
public var agentUnavailable: String?
public var agentUnavailable: AgentAvailabilityMessage?

/**
Routing or other contextual information to be used by target service desk systems.
Expand Down Expand Up @@ -105,8 +105,8 @@ public struct RuntimeResponseGenericRuntimeResponseTypeConnectToAgent: Codable,
public init(
responseType: String,
messageToHumanAgent: String? = nil,
agentAvailable: String? = nil,
agentUnavailable: String? = nil,
agentAvailable: AgentAvailabilityMessage? = nil,
agentUnavailable: AgentAvailabilityMessage? = nil,
transferInfo: DialogNodeOutputConnectToAgentTransferInfo? = nil,
topic: String? = nil,
dialogNode: String? = nil
Expand Down
Loading

0 comments on commit 5595caa

Please sign in to comment.