Assistant
public class Assistant
The IBM Watson™ Assistant service combines machine learning, natural language understanding, and an integrated dialog editor to create conversation flows between your apps and your users. The Assistant v2 API provides runtime methods your client application can use to send user input to an assistant and receive a response.
-
The base URL to use when contacting the service.
Declaration
Swift
public var serviceURL: String?
-
Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is
2021-06-14
.Declaration
Swift
public var version: String
-
Service identifiers
Declaration
Swift
public static let defaultServiceName: String
-
The default HTTP headers for all requests to the service.
Declaration
Swift
public var defaultHeaders: [String : String]
-
Undocumented
Declaration
Swift
public let authenticator: Authenticator
-
Create a
Assistant
object.If an authenticator is not supplied, the initializer will retrieve credentials from the environment or a local credentials file and construct an appropriate authenticator using these credentials. The credentials file can be downloaded from your service instance on IBM Cloud as ibm-credentials.env. Make sure to add the credentials file to your project so that it can be loaded at runtime.
If an authenticator is not supplied and credentials are not available in the environment or a local credentials file, initialization will fail by throwing an exception. In that case, try another initializer that directly passes in the credentials.
- serviceName: String = defaultServiceName
-
Create a
Assistant
object.Declaration
Swift
public init(version: String, authenticator: Authenticator)
Parameters
version
Release date of the API version you want to use. Specify dates in YYYY-MM-DD format. The current version is
2021-06-14
.authenticator
The Authenticator object used to authenticate requests to the service
-
Allow network requests to a server without verification of the server certificate. IMPORTANT: This should ONLY be used if truly intended, as it is unsafe otherwise.
Declaration
Swift
public func disableSSLVerification()
-
Create a session.
Create a new session. A session is used to send user input to a skill and receive responses. It also maintains the state of the conversation. A session persists until it is deleted, or until it times out because of inactivity. (For more information, see the documentation.
Declaration
Swift
public func createSession( assistantID: String, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<SessionResponse>?, WatsonError?) -> Void)
Parameters
assistantID
Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open the assistant settings and click API Details. For information about creating assistants, see the documentation. Note: Currently, the v2 API does not support creating assistants.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
Delete session.
Deletes a session explicitly before it times out. (For more information about the session inactivity timeout, see the documentation).
Declaration
Swift
public func deleteSession( assistantID: String, sessionID: String, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<Void>?, WatsonError?) -> Void)
Parameters
assistantID
Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open the assistant settings and click API Details. For information about creating assistants, see the documentation. Note: Currently, the v2 API does not support creating assistants.
sessionID
Unique identifier of the session.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
Send user input to assistant (stateful).
Send user input to an assistant and receive a response, with conversation state (including context data) stored by Watson Assistant for the duration of the session.
Declaration
Swift
public func message( assistantID: String, sessionID: String, input: MessageInput? = nil, context: MessageContext? = nil, userID: String? = nil, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<MessageResponse>?, WatsonError?) -> Void)
Parameters
assistantID
Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open the assistant settings and click API Details. For information about creating assistants, see the documentation. Note: Currently, the v2 API does not support creating assistants.
sessionID
Unique identifier of the session.
input
An input object that includes the input text.
context
Context data for the conversation. You can use this property to set or modify context variables, which can also be accessed by dialog nodes. The context is stored by the assistant on a per-session basis. Note: The total size of the context data stored for a stateful session cannot exceed 100KB.
userID
A string value that identifies the user who is interacting with the assistant. The client must provide a unique identifier for each individual end user who accesses the application. For user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain carriage return, newline, or tab characters. If no value is specified in the input, user_id is automatically set to the value of context.global.session_id. Note: This property is the same as the user_id property in the global system context. If user_id is specified in both locations, the value specified at the root is used.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
Send user input to assistant (stateless).
Send user input to an assistant and receive a response, with conversation state (including context data) managed by your application.
Declaration
Swift
public func messageStateless( assistantID: String, input: MessageInputStateless? = nil, context: MessageContextStateless? = nil, userID: String? = nil, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<MessageResponseStateless>?, WatsonError?) -> Void)
Parameters
assistantID
Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open the assistant settings and click API Details. For information about creating assistants, see the documentation. Note: Currently, the v2 API does not support creating assistants.
input
An input object that includes the input text.
context
Context data for the conversation. You can use this property to set or modify context variables, which can also be accessed by dialog nodes. The context is not stored by the assistant. To maintain session state, include the context from the previous response. Note: The total size of the context data for a stateless session cannot exceed 250KB.
userID
A string value that identifies the user who is interacting with the assistant. The client must provide a unique identifier for each individual end user who accesses the application. For user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain carriage return, newline, or tab characters. If no value is specified in the input, user_id is automatically set to the value of context.global.session_id. Note: This property is the same as the user_id property in the global system context. If user_id is specified in both locations in a message request, the value specified at the root is used.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
Identify intents and entities in multiple user utterances.
Send multiple user inputs to a dialog skill 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 skills or skill versions. This method is available only with Enterprise with Data Isolation plans.
Declaration
Swift
public func bulkClassify( skillID: String, input: [BulkClassifyUtterance]? = nil, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<BulkClassifyResponse>?, WatsonError?) -> Void)
Parameters
skillID
Unique identifier of the skill. To find the skill ID in the Watson Assistant user interface, open the skill settings and click API Details.
input
An array of input utterances to classify.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
List log events for an assistant.
List the events from the log of an assistant. This method requires Manager access, and is available only with Enterprise plans.
Declaration
Swift
public func listLogs( assistantID: String, sort: String? = nil, filter: String? = nil, pageLimit: Int? = nil, cursor: String? = nil, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<LogCollection>?, WatsonError?) -> Void)
Parameters
assistantID
Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open the assistant settings and click API Details. For information about creating assistants, see the documentation. Note: Currently, the v2 API does not support creating assistants.
sort
How to sort the returned log events. You can sort by request_timestamp. To reverse the sort order, prefix the parameter value with a minus sign (
-
).filter
A cacheable parameter that limits the results to those matching the specified filter. For more information, see the documentation.
pageLimit
The number of records to return in each page of results.
cursor
A token identifying the page of results to retrieve.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error
-
Delete labeled data.
Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with the customer ID. You associate a customer ID with data by passing the
X-Watson-Metadata
header with a request that passes data. For more information about personal data and customer IDs, see Information security. Note: This operation is intended only for deleting data associated with a single specific customer, not for deleting data associated with multiple customers or for any other purpose. For more information, see Labeling and deleting data in Watson Assistant.Declaration
Swift
public func deleteUserData( customerID: String, headers: [String: String]? = nil, completionHandler: @escaping (WatsonResponse<Void>?, WatsonError?) -> Void)
Parameters
customerID
The customer ID for which all data is to be deleted.
headers
A dictionary of request headers to be sent with this request.
completionHandler
A function executed when the request completes with a successful result or error