Overview
Class/Protocol | API | Description |
ARTCAIChatEngineInterface Interface for managing the messaging engine | Gets the connection state of the engine. | |
Gets the information about the user who participates in the current session. | ||
Gets the unique identifier of the current session. | ||
Gets the information about the AI agent that participates in the current session. | ||
Gets the current response status of the agent. | ||
Retrieves the available voices. | ||
Configures and queries callback events. | ||
Configures and obtains TemplateConfig. | ||
The custom user information. The information is passed to the AI agent. | ||
Starts a chat session. | ||
Ends a chat session. | ||
Sends a message. The agent reply will be interrupted before sending the message (when the agent is thinking or replying). | ||
Deletes a message. | ||
Requests historical messages. | ||
Interrupts the current reply. | ||
Deletes a message. | ||
Starts to read out a message. | ||
Stops reading out a message. | ||
Checks whether a message is being read out. | ||
Creates an attachment uploader object to send messages with images, videos, or other files. | ||
Starts push-to-talk voice recording. When the button is tapped, recording starts and the voice input is sent in real time. Make sure that the recording permission is granted. | ||
Ends push-to-talk voice recording. This method is called when the button is released, indicating that the voice message has been sent. | ||
Cancels push-to-talk voice recording. This method is called when the button is released, indicating that the sending of the voice message is canceled. | ||
Releases resources. | ||
Parses the information about a shared agent. | ||
Starts a conversation with a shared agent. | ||
IARTCAIChatEngineCallback Callback events for the messaging engine | Called when an error occurred. | |
Requests an authentication token. This callback is triggered when ChatEngine needs to log on to interactive messaging or when the authentication token for logon expires. | ||
Called when the connection state of the engine changes. | ||
A response is received from the AI agent. This callback is triggered when the agent sends a new reply or when the status of a message changes during the current reply process. | ||
Called when a custom message is received. | ||
Called when the user-sent message is updated. | ||
Called when the response status of the agent changes. | ||
Called when the readout status of a message from the AI agent changes. | ||
ARTCAICallEngineFactory An engine creation factory | Creates a default agent engine. |
API details
ARTCAIChatEngineInterface
state
Gets the connection state of the engine. For detailed states, see ARTCAIChatEngineState.
var state: ARTCAIChatEngineState { get }userInfo
Gets the information about the user who participates in the current session. For details, see ARTCAIChatUserInfo.
var userInfo: ARTCAIChatUserInfo? { get }sessionId
Gets the unique identifier of the current session.
var sessionId: String? { get }agentInfo
Gets the information about the AI agent that participates in the current session. For details, see ARTCAIChatAgentInfo.
var agentInfo: ARTCAIChatAgentInfo? { get }agentResponeState
Gets the current response status of the agent. For details, see ARTCAIChatAgentResponseState.
var agentResponeState: ARTCAIChatAgentResponseState { get }voiceIdList
Retrieves the available voices.
var voiceIdList: [String] { get }delegate
Configures and queries callback events. For details, see ARTCAIChatEngineDelegate.
weak var delegate: ARTCAIChatEngineDelegate? { get set }templateConfig
Configures and obtains TemplateConfig. For details, see ARTCAIChatTemplateConfig.
var templateConfig: ARTCAIChatTemplateConfig? { get set }userData
The custom user information. The information is passed to the AI agent.
var userData: [String: Any]? { get set }startChat
Starts a chat session.
func startChat(userInfo: ARTCAIChatUserInfo, agentInfo: ARTCAIChatAgentInfo, sessionId: String?)Parameter | Type | Description |
userInfo | ARTCAIChatUserInfo | The information about the user that joins the session. |
agentInfo | ARTCAIChatAgentInfo | The information about the AI agent that joins the session. |
sessionId | String? | The unique identifier of the current session. If empty, the session ID defaults to a concatenation of userId and agentId. |
endChat
Ends a chat session.
func endChat(needLogout: Bool)Parameter | Type | Description |
needLogout | Bool | Specifies whether the user needs to log out. If it is set to false, the connection time is reduced when startChat is called next time. Set it to true if conversation is no longer needed. |
sendMessage
Sends a message. The agent reply will be interrupted before sending the message (when the agent is thinking or replying).
func sendMessage(request: ARTCAIChatSendMessageRequest, completed:((_ msg: ARTCAIChatMessage?, _ error: NSError?) -> Void)?)Parameter | Type | Description |
request | ARTCAIChatSendMessageRequest | The content of the message to send. |
completed | (_ msg: ARTCAIChatMessage?, _ error: NSError?) -> Void | The callback for message sending result. |
deleteMessage
Deletes a message.
func deleteMessage(message: ARTCAIChatMessage, completed:((_ error: NSError?) -> Void)?)Parameter | Type | Description |
message | ARTCAIChatMessage | The message object. |
completed | ((_ error: NSError?) -> Void)? | The callback for the operation result. |
queryMessageList
Requests historical messages.
func queryMessageList(request: ARTCAIChatMessageListRequest, completed:((_ msgList: [ARTCAIChatMessage]?, _ error: NSError?) -> Void)?) Parameter | Type | Description |
request | ARTCAIChatMessageListRequest | The request model. |
completed | (_ msgList: [ARTCAIChatMessage]?, _ error: NSError?) -> Void)? | The result callback. |
interruptAgentResponse
Interrupts the current reply.
func interruptAgentResponse()deleteMessage
Deletes a message.
func deleteMessage(dialogueId: String, completed:((_ error: NSError?) -> Void)?)Parameter | Type | Description |
dialogueId | String | The message ID. |
completed | (_ error: NSError?) -> Void)? | The result callback. |
startPlayMessage
Starts to read out a message.
func startPlayMessage(message: ARTCAIChatMessage, voiceId: String?, completed: ((NSError?) -> Void)?)Parameter | Type | Description |
message | ARTCAIChatMessage | The message to read out. |
voiceId | voiceId | The voice ID. |
completed | (_ error: NSError?) -> Void)? | The result callback. |
stopPlayMessage
Stops reading out a message.
func stopPlayMessage()isPlayingMessage
Checks whether a message is being read out.
func isPlayingMessage(dialogueId: String) -> BoolcreateAttachmentUploader
Creates an attachment uploader object to send messages with images, videos, or other files.
func createAttachmentUploader() -> ARTCAIChatAttachmentUploader?startPushVoiceMessage
Starts push-to-talk voice recording. When the button is tapped, recording starts and the voice input is sent in real time. Make sure that the recording permission is granted.
A return value of true indicates that the operation is successful. A return value of false indicates that the operation failed. The failure may be caused by an incorrect status or disabled recording permission.
func startPushVoiceMessage(request: ARTCAIChatSendMessageRequest) -> BoolParameter | Type | Description |
request | ARTCAIChatSendMessageRequest | The content of the message to send. |
finishPushVoiceMessage
Ends push-to-talk voice recording. This method is called when the button is released, indicating that the voice message has been sent.
func finishPushVoiceMessage(completed:((_ msg: ARTCAIChatMessage) -> Void)?)Parameter | Type | Description |
completed | (_ msg: ARTCAIChatMessage) -> Void)? | The result callback. |
cancelPushVoiceMessage
Cancels push-to-talk voice recording. This method is called when the button is released, indicating that the sending of the voice message is canceled.
func cancelPushVoiceMessage()destroy
Releases resources.
func destroy()parseShareAgentChat
Parses the information about a shared agent.
func parseShareAgentChat(shareInfo: String) -> ARTCAIChatAgentShareConfig?Parameter | Type | Description |
shareInfo | String | The shared information. |
generateShareAgentChat
Starts a conversation with a shared agent.
func generateShareAgentChat(shareConfig: ARTCAIChatAgentShareConfig, userId: String, completed: ((_ agentInfo: ARTCAIChatAgentInfo?, _ authToken: ARTCAIChatAuthToken?, _ error: NSError?, _ reqId: String) -> Void)?) Parameter | Type | Description |
shareConfig | ARTCAIChatAgentShareConfig | The shared information. |
userId | String | The user ID. |
completed | (_ agentInfo: ARTCAIChatAgentInfo?, _ authToken: ARTCAIChatAuthToken?, _ error: NSError?, _ reqId: String) -> Void)? | The result callback. |
ARTCAIChatEngineDelegate
onErrorOccurs
Called when an error occurred.
@objc optional func onErrorOccurs(error: NSError, requestId: String?)Parameter | Type | Description |
error | NSError | The error message. |
requestId | String? | The message request ID. If this parameter is not empty, an error occurred during message processing. |
onRequestAuthToken
Requests an authentication token. This callback is triggered when ChatEngine needs to log on to interactive messaging or when the authentication token for logon expires.
@objc optional func onRequestAuthToken(userId: String, responseBlock: @escaping (_ authToken: ARTCAIChatAuthToken?, _ error: NSError?)->Void)Parameter | Type | Description |
userId | String | The user ID. |
responseBlock | (_ authToken: ARTCAIChatAuthToken?, _ error: NSError?)->Void | The token callback. |
onEngineStateChange
Called when the connection state of the engine changes.
@objc optional func onEngineStateChange(state: ARTCAIChatEngineState)Parameter | Type | Description |
state | ARTCAIChatEngineState | The current connection state of the agent. |
onReceivedMessage
A response is received from the AI agent. This callback is triggered when the agent sends a new reply or when the status of a message changes during the current reply process.
@objc optional func onReceivedMessage(message: ARTCAIChatMessage)Parameter | Type | Description |
message | ARTCAIChatMessage | The message object. |
onReceivedCustomMessage
Called when a custom message is received.
@objc optional func onReceivedCustomMessage(text: String)Parameter | Type | Description |
text | String | The message content. |
onUserMessageUpdated
Called when the user-sent message is updated.
@objc optional func onUserMessageUpdated(message: ARTCAIChatMessage)Parameter | Type | Description |
message | ARTCAIChatMessage | The message object. |
onAgentResponeStateChange
Called when the response status of the agent changes.
@objc optional func onAgentResponeStateChange(state: ARTCAIChatAgentResponseState, requestId: String?)Parameter | Type | Description |
state | ARTCAIChatAgentResponseState | The response status. |
requestId | String? | The current message session. |
onMessagePlayStateChange
Called when the readout status of a message from the AI agent changes.
@objc optional func onMessagePlayStateChange(message: ARTCAIChatMessage, state: ARTCAIChatMessagePlayState)Parameter | Type | Description |
message | ARTCAIChatMessage | The message object. |
state | ARTCAIChatMessagePlayState | The readout status. |
ARTCAICallEngineFactory
CreateChatEngine
Creates a default agent engine.
public static func createChatEngine() -> ARTCAIChatEngineInterface