CAIConversation
public final class CAIConversation : MessagingPublisher
                  This class is the standard implementation of MessagingPublisher for connecting
to a bot of the CAI platform via the Channel Connector.
- 
                    
                    
Declaration
Swift
public typealias Output = Result<ResponseMessageData, Error> - 
                    
                    
Declaration
Swift
public typealias Failure = Never - 
                    
                    
CAI Conversation ID. Read-only getter to get the current conversation ID set with this object. It’s created for you in
load()or you can pass it in constructorDeclaration
Swift
public private(set) var conversationID: String? { get } 
- 
                    
                    
Creates a new CAI conversation object.
Declaration
Swift
public convenience init(config: CAIServiceConfig, channelId: String, channelToken: String?, withExistingConvID conversationID: String? = nil)Parameters
configThe configuration object holding central config properties
channelIdThe channel ID (from channel connector)
channelTokenThe channel connector token
conversationIDAn existing conversation ID (stored somewhere externally). If this is supplied, no new conversation will be created in the backend. Optional. Default is nil hence a request to the backend will be triggered to create one.
 - 
                    
                    
Creates a new CAI conversation object. Convenience init using CAIChannel struct
Declaration
Swift
public convenience init(config: CAIServiceConfig, channel: CAIChannel, withExistingConvID conversationID: String? = nil)Parameters
configCAIServiceConfig
channelCAIChannel. Channel you want to create a conversation to
conversationIDAn existing conversation ID (stored somewhere externally). If this is supplied, no new conversation will be created in the backend. Optional. Default is nil hence a request to the backend will be triggered to create one.
 - 
                    
                    
Creates a new CAI conversation object. Convenience init using CAIChannel struct
Declaration
Swift
public convenience init(config: CAIServiceConfig, channel: CAIChannel, messageDelivery: MessageDelivering, withExistingConvID conversationID: String? = nil)Parameters
configCAIServiceConfig
channelCAIChannel. Channel you want to create a conversation to
messageDeliveryMethod / UI Protocol on how to retrieve messages from backend. Polling & WebSocket are supported.
conversationIDAn existing conversation ID (stored somewhere externally). If this is supplied, no new conversation will be created in the backend. Optional. Default is nil hence a request to the backend will be triggered to create one.
 
- 
                    
                    
Declaration
Swift
public func load() - 
                    
                    
Reset an existing conversation. Next time a message is sent, this will trigger a creation of a new conversation.
Declaration
Swift
public func resetConversation() - 
                    
                    
Reset an existing conversation and create a new conversation.
Declaration
Swift
public func resetAndCreateConversation() - 
                    
                    
Post a text message to CAI platform
Declaration
Swift
public func postMessage(text: String, memoryOptions: MemoryOptions? = nil)Parameters
textString
 - 
                    
                    
Post a postback action to CAI platform. Used by buttons and quickReplies
Declaration
Swift
public func postMessage(type: PostbackType, postbackData: PostbackData, memoryOptions: MemoryOptions? = nil)Parameters
typeUIModelPostbackRequestDataType
postbackDataButtonData
 - 
                    
                    
Creates a conversation in the backend and returns the newly created conversation ID
Declaration
Swift
public func createConversation(_ completionHandler: @escaping ((Result<String, CAIError>) -> Void))Parameters
completionHandlerHandler function
 - 
                    
                    
Returns a publisher that emits the current conversationId. If no conversationId is available, it will trigger a backend call to create a new one.
Declaration
Swift
public func getConversationId() -> AnyPublisher<String, CAIError> - 
                    
                    
Loads content for an existing conversation ID
Declaration
Swift
public func loadConversation(_ conversationId: String, _ completionHandler: @escaping (Result<CAIResponseData, CAIError>) -> Void)Parameters
conversationIdString
completionHandlerHandler function called once finished
 
- 
                    
                    
Loads a conversation and returns a Publisher. Always emits on
Mainthread.Declaration
Swift
func loadConversation(_ conversationId: String) -> AnyPublisher<CAIResponseData, CAIError>Parameters
conversationIdString