This topic describes how to integrate message conversation agents into your iOS application by using the AICallKit SDK.
API overview
Class or protocol | API | Description |
ARTCAIChatEngineInterface Message conversation engine interface definition | Obtains the engine connection status | |
Obtains the information about the user who participates in the current session | ||
Obtains the unique identifier of the current session | ||
Obtains the information about the agent that participates in the current session | ||
Obtains the current agent response status | ||
Obtains the current voice list | ||
Configures and queries callback events | ||
Sets and obtains TemplateConfig | ||
Custom user information that is passed to the agent | ||
Starts a chat session | ||
Ends a chat session | ||
Sends a message and interrupts the current reply (if the agent is thinking or replying) | ||
Deletes a message | ||
Requests the historical message list | ||
Interrupts the current message reply | ||
Deletes a message | ||
Starts playing the message content | ||
Stops playing the message | ||
Checks whether a message is being played | ||
Creates an attachment uploader object to send messages with images, videos, or files | ||
Starts push-to-talk voice messaging. When you press the button, recording starts and the voice is sent in real time. Make sure that the recording permission is enabled | ||
Ends push-to-talk voice messaging. This operation is called when you release the button, indicating that the current voice message is sent and the system is waiting for the agent to respond | ||
Cancels push-to-talk voice messaging. This operation is called when you release the button, indicating that the current voice message is canceled | ||
Releases resources | ||
Parses the information about a shared intelligent agent | ||
Starts a call with a shared intelligent agent | ||
IARTCAIChatEngineCallback Message conversation engine callback events | An error occurred | |
Requests an AuthToken. This callback is triggered when the ChatEngine needs to log on to IM or when the AuthToken for IM logon expires | ||
The agent connection status changes | ||
A reply message is received from the 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 | ||
A custom message is received | ||
A message sent by the user needs to be updated | ||
The agent response status changes | ||
The message playback status of the Chat agent changes | ||
ARTCAICallEngineFactory An engine factory | Creates a default Chat agent engine |
API details
ARTCAIChatEngineInterface details
state
Obtains the engine connection status. For more information about ARTCAIChatEngineState, see ARTCAIChatEngineState.
var state: ARTCAIChatEngineState { get }userInfo
Obtains the information about the user who participates in the current session. For more information about ARTCAIChatUserInfo, see ARTCAIChatUserInfo.
var userInfo: ARTCAIChatUserInfo? { get }sessionId
Obtains the unique identifier of the current session.
var sessionId: String? { get }agentInfo
Obtains the information about the agent that participates in the current session. For more information about ARTCAIChatAgentInfo, see ARTCAIChatAgentInfo.
var agentInfo: ARTCAIChatAgentInfo? { get }agentResponeState
Obtains the current agent response status. For more information about ARTCAIChatAgentResponseState, see ARTCAIChatAgentResponseState.
var agentResponeState: ARTCAIChatAgentResponseState { get }voiceIdList
Obtains the current voice list.
var voiceIdList: [String] { get }delegate
Configures and queries callback events. For more information about ARTCAIChatEngineDelegate, see ARTCAIChatEngineDelegate.
weak var delegate: ARTCAIChatEngineDelegate? { get set }templateConfig
Sets and obtains TemplateConfig. For more information about ARTCAIChatTemplateConfig, see ARTCAIChatTemplateConfig.
var templateConfig: ARTCAIChatTemplateConfig? { get set }userData
Custom user information that is passed to the agent.
var userData: [String: Any]? { get set }startChat
Starts a chat session.
func startChat(userInfo: ARTCAIChatUserInfo, agentInfo: ARTCAIChatAgentInfo, sessionId: String?)Parameters:
Parameter | Type | Description |
userInfo | ARTCAIChatUserInfo | The information about the user who starts the session |
agentInfo | ARTCAIChatAgentInfo | The information about the agent that starts the session |
sessionId | String? | The unique identifier of the current session. If this parameter is empty, userId+agentId is used as the unique identifier |
endChat
Ends a chat session.
func endChat(needLogout: Bool)Parameters:
Parameter | Type | Description |
needLogout | Bool | Specifies whether the current user needs to log out of the connection. If this parameter is set to false, the connection time is reduced when you call startChat next time. If you no longer need to chat, set this parameter to true |
sendMessage
Sends a message and interrupts the current reply (if the agent is thinking or replying).
func sendMessage(request: ARTCAIChatSendMessageRequest, completed:((_ msg: ARTCAIChatMessage?, _ error: NSError?) -> Void)?)Parameters:
Parameter | Type | Description |
request | ARTCAIChatSendMessageRequest | The content of the message to send |
completed | (_ msg: ARTCAIChatMessage?, _ error: NSError?) -> Void | Result callback |
deleteMessage
Deletes a message.
func deleteMessage(message: ARTCAIChatMessage, completed:((_ error: NSError?) -> Void)?)Parameters:
Parameter | Type | Description |
message | ARTCAIChatMessage | The message object |
completed | ((_ error: NSError?) -> Void)? | Result callback |
queryMessageList
Requests the historical message list.
func queryMessageList(request: ARTCAIChatMessageListRequest, completed:((_ msgList: [ARTCAIChatMessage]?, _ error: NSError?) -> Void)?) Parameters:
Parameter | Type | Description |
request | ARTCAIChatMessageListRequest | The request model |
completed | (_ msgList: [ARTCAIChatMessage]?, _ error: NSError?) -> Void)? | Result callback |
interruptAgentResponse
Interrupts the current message reply.
func interruptAgentResponse()deleteMessage
Deletes a message.
func deleteMessage(dialogueId: String, completed:((_ error: NSError?) -> Void)?)Parameters:
Parameter | Type | Description |
dialogueId | String | The message ID |
completed | (_ error: NSError?) -> Void)? | Result callback |
startPlayMessage
Starts playing the message content.
func startPlayMessage(message: ARTCAIChatMessage, voiceId: String?, completed: ((NSError?) -> Void)?)Parameters:
Parameter | Type | Description |
message | ARTCAIChatMessage | The message to play |
voiceId | voiceId | The voice to use for playback |
completed | (_ error: NSError?) -> Void)? | Result callback |
stopPlayMessage
Stops playing the message.
func stopPlayMessage()isPlayingMessage
Checks whether a message is being played.
func isPlayingMessage(dialogueId: String) -> BoolcreateAttachmentUploader
Creates an attachment uploader object to send messages with images, videos, or files.
func createAttachmentUploader() -> ARTCAIChatAttachmentUploader?startPushVoiceMessage
Starts push-to-talk voice messaging. When you press the button, recording starts and the voice is sent in real time. Make sure that the recording permission is enabled.
A return value of true indicates that the operation is successful. A return value of false indicates that the operation failed. Common causes include incorrect status and disabled recording permission.
func startPushVoiceMessage(request: ARTCAIChatSendMessageRequest) -> BoolParameters:
Parameter | Type | Description |
request | ARTCAIChatSendMessageRequest | The content of the message to send |
finishPushVoiceMessage
Ends push-to-talk voice messaging. This operation is called when you release the button, indicating that the current voice message is sent and the system is waiting for the agent to respond.
func finishPushVoiceMessage(completed:((_ msg: ARTCAIChatMessage) -> Void)?)Parameters:
Parameter | Type | Description |
completed | (_ msg: ARTCAIChatMessage) -> Void)? | Result callback |
cancelPushVoiceMessage
Cancels push-to-talk voice messaging. This operation is called when you release the button, indicating that the current voice message is canceled.
func cancelPushVoiceMessage()destroy
Releases resources.
func destroy()parseShareAgentChat
Parses the information about a shared intelligent agent.
func parseShareAgentChat(shareInfo: String) -> ARTCAIChatAgentShareConfig?Parameters:
Parameter | Type | Description |
shareInfo | String | The shared information |
generateShareAgentChat
Starts a call with a shared intelligent agent.
func generateShareAgentChat(shareConfig: ARTCAIChatAgentShareConfig, userId: String, completed: ((_ agentInfo: ARTCAIChatAgentInfo?, _ authToken: ARTCAIChatAuthToken?, _ error: NSError?, _ reqId: String) -> Void)?) Parameters:
Parameter | Type | Description |
shareConfig | ARTCAIChatAgentShareConfig | The shared information |
userId | String | The user ID |
completed | (_ agentInfo: ARTCAIChatAgentInfo?, _ authToken: ARTCAIChatAuthToken?, _ error: NSError?, _ reqId: String) -> Void)? | Result callback |
ARTCAIChatEngineDelegate details
onErrorOccurs
An error occurred.
@objc optional func onErrorOccurs(error: NSError, requestId: String?)Parameters:
Parameter | Type | Description |
error | NSError | The error message |
requestId | String? | The message request ID. If this parameter is not nil, the error is a message error |
onRequestAuthToken
Requests an AuthToken. This callback is triggered when the ChatEngine needs to log on to IM or when the AuthToken for IM logon expires.
@objc optional func onRequestAuthToken(userId: String, responseBlock: @escaping (_ authToken: ARTCAIChatAuthToken?, _ error: NSError?)->Void)Parameters:
Parameter | Type | Description |
userId | String | The user ID |
responseBlock | (_ authToken: ARTCAIChatAuthToken?, _ error: NSError?)->Void | The token callback |
onEngineStateChange
The agent connection status changes.
@objc optional func onEngineStateChange(state: ARTCAIChatEngineState)Parameters:
Parameter | Type | Description |
state | ARTCAIChatEngineState | The current agent connection status |
onReceivedMessage
A reply message is received from the 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)Parameters:
Parameter | Type | Description |
message | ARTCAIChatMessage | The message object |
onReceivedCustomMessage
A custom message is received.
@objc optional func onReceivedCustomMessage(text: String)Parameters:
Parameter | Type | Description |
text | String | The message content |
onUserMessageUpdated
A message sent by the user needs to be updated.
@objc optional func onUserMessageUpdated(message: ARTCAIChatMessage)Parameters:
Parameter | Type | Description |
message | ARTCAIChatMessage | The message object |
onAgentResponeStateChange
The agent response status changes.
@objc optional func onAgentResponeStateChange(state: ARTCAIChatAgentResponseState, requestId: String?)Parameters:
Parameter | Type | Description |
state | ARTCAIChatAgentResponseState | The response status |
requestId | String? | The current message session |
onMessagePlayStateChange
The message playback status of the Chat agent changes.
@objc optional func onMessagePlayStateChange(message: ARTCAIChatMessage, state: ARTCAIChatMessagePlayState)Parameters:
Parameter | Type | Description |
message | ARTCAIChatMessage | The message object |
state | ARTCAIChatMessagePlayState | The playback status |
ARTCAICallEngineFactory details
createChatEngine
Creates a default Chat agent engine.
public static func createChatEngine() -> ARTCAIChatEngineInterface