All Products
Search
Document Center

Intelligent Media Services:API reference

Last Updated:Dec 09, 2025

Overview

Class/Protocol

API

Description

ARTCAIChatEngineInterface

Interface for managing the messaging engine

state

Gets the connection state of the engine.

userInfo

Gets the information about the user who participates in the current session.

sessionId

Gets the unique identifier of the current session.

agentInfo

Gets the information about the AI agent that participates in the current session.

agentResponeState

Gets the current response status of the agent.

voiceIdList

Retrieves the available voices.

delegate

Configures and queries callback events.

templateConfig

Configures and obtains TemplateConfig.

userData

The custom user information. The information is passed to the AI agent.

startChat

Starts a chat session.

endChat

Ends a chat session.

sendMessage

Sends a message. The agent reply will be interrupted before sending the message (when the agent is thinking or replying).

deleteMessage

Deletes a message.

queryMessageList

Requests historical messages.

interruptAgentResponse

Interrupts the current reply.

deleteMessage

Deletes a message.

startPlayMessage

Starts to read out a message.

stopPlayMessage

Stops reading out a message.

isPlayingMessage

Checks whether a message is being read out.

createAttachmentUploader

Creates an attachment uploader object to send messages with images, videos, or other files.

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.

finishPushVoiceMessage

Ends push-to-talk voice recording. This method is called when the button is released, indicating that the voice message has been sent.

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.

destroy

Releases resources.

parseShareAgentChat

Parses the information about a shared agent.

generateShareAgentChat

Starts a conversation with a shared agent.

IARTCAIChatEngineCallback

Callback events for the messaging engine

onErrorOccurs

Called when an error occurred.

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.

onEngineStateChange

Called when the connection state of the engine changes.

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.

onReceivedCustomMessage

Called when a custom message is received.

onUserMessageUpdated

Called when the user-sent message is updated.

onAgentResponeStateChange

Called when the response status of the agent changes.

onMessagePlayStateChange

Called when the readout status of a message from the AI agent changes.

ARTCAICallEngineFactory

An engine creation factory

createChatEngine

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) -> Bool

createAttachmentUploader

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) -> Bool

Parameter

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)

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