ChatProvider
@objc(ZDKChatProvider)
public final class ChatProvider : NSObject, Loggable
The ZDKChatProvider provides APIs to interact and observe the current Chat session.
It provides APIs to:
- proactively request a chat
- send messages
- handle failed messages (retry/delete)
- set the visitors’ typing indicator
- end the chat
-
Current chat state. Defaults to
ChatState.initial.In order to observe updates of
ChatState, please use theobserveChatStatefunction.Declaration
Swift
@objc public var chatState: ChatState { get } -
Proactively lets an agent know that the user wants to chat.
Declaration
Swift
@available(*, deprecated, message: "This API is no longer supported") @objc public func requestChat() -
Get information about the state of the current chat.
The
Chatis ongoing if the givenChatInfomodel’sisChattingflag, is set totrue.Declaration
Swift
public func getChatInfo(_ completion: @escaping (Result<ChatInfo, Error>) -> Void)Parameters
completionblock that is invoked once the
getChatInforequest finishes. -
Set the department for the next chat session.
Note
The department can’t be changed during a session. This method should be called before calling any otherChatProvidermethods to ensure the department was set successfully.The
Chatis ongoing if the givenChatInfomodel’sisChattingflag, is set totrue. Retrieve the list of department names from via theAccountProvider.Declaration
Swift
public func setDepartment(_ name: String?, completion: ((Result<String?, DeliveryStatusError>) -> Void)? = nil)Parameters
nameThe name of the department to set.
completionblock that is invoked once the
getChatInforequest finishes. -
Let’s the agent know when the visitor is typing.
If
true, the visitor typing indicator will appear in agent dashboard, else it will be hidden.Declaration
Swift
@objc public func sendTyping(isTyping: Bool)Parameters
isTypingisTyping
-
Sends an offline form from the current visitor.
Warning
Make sure the email field is filled in the
VisitorInfo, or the form will fail to sendDeclaration
Swift
public func sendOfflineForm(_ offlineForm: OfflineForm, completion: ((Result<OfflineForm, DeliveryStatusError>) -> Void)? = nil)Parameters
offlineFormOfflineFormmodelcompletionblock that executes everytime there is an update to the
ChatState -
Send a chat message
Declaration
Swift
public func sendMessage(_ message: String, completion: ((Result<String, DeliveryStatusError>) -> Void)? = nil)Parameters
messagevisitor message
completionResult<String, DeliveryStatusError>closure to handle delivery status of message. Default isnil -
Resend failed message identified by given message id
Note
If the message id does not exist or the message associated with the id didn’t fail, then
FailedMessageErrorwill be propagated through completion block.Declaration
Swift
public func resendFailedMessage(withId id: String, completion: ((Result<String, Error>) -> Void)? = nil)Parameters
idid of the failed message.
completionResult<String, DeliveryStatusError>closure to handle resend status of message. Success is message id. -
Delete failed message identified by given message id.
Note
If the message id does not exist or the message associated with the id didn’t fail, then
FailedMessageErrorwill be propagated through completion block. This can be used to delete failed file uploads.Declaration
Swift
public func deleteFailedMessage(withId id: String, completion: ((Result<String, Error>) -> Void)? = nil)Parameters
idid of the failed message.
completionResult<String, Error>closure to handle deletion status of message. Default isnil
-
Send an attachment message.
Declaration
Swift
public func sendFile(url: URL, onProgress: ((Double) -> Void)? = nil, completion: ((Result<ChatAttachmentMessage, DeliveryStatusError>) -> Void)? = nil)Parameters
urlThe file
URLof the attachment to sendonProgressHandle file upload progress
completionResult<ChatAttachment, DeliveryStatusError>closure to handle whether the file sent successfully, -
Resend attachment identified by given message id
Declaration
Swift
public func resendFailedFile(withId id: String, onProgress: ((Double) -> Void)? = nil, completion: ((Result<String, Error>) -> Void)? = nil)Parameters
idid of the attachment message.
onProgressclosure to handle upload progress
completionResult<ChatAttachmentMessage, Error>closure to handle resend status of message. Default isnil
-
Send a chat
Ratingfor the active sessionDeclaration
Swift
public func sendChatRating(_ rating: Rating, completion: ((Result<Rating, DeliveryStatusError>) -> Void)? = nil)Parameters
ratingThe rating of the session
.good/.badcompletionResult<Rating, DeliveryStatusError>closure to handle delivery status of message. Default isnil -
Send a comment about the current chat session
Declaration
Swift
public func sendChatComment(_ comment: String, completion: ((Result<String, DeliveryStatusError>) -> Void)? = nil)Parameters
commentThe comment about the chat
completionResult<String, DeliveryStatusError>closure to handle delivery status of message. Default isnil -
Schedules an email containing the chat transcript to be sent to email when the chat has ended.
Declaration
Swift
public func sendEmailTranscript(_ email: String, completion: ((Result<String, DeliveryStatusError>) -> Void)? = nil)Parameters
emailthe email to send the transcript
completionResult<String, DeliveryStatusError>closure to handle delivery status of message. Default isnil
-
Ends the chat and closes the socket connection
Declaration
Swift
public func endChat(_ completion: ((Result<Bool, DeliveryStatusError>) -> Void)? = nil)Parameters
completionblock to handle the status of the
endChatrequest.trueon success.
-
Observe changes of the current chat’s state
The conversation thread can be accessed through the
logsDeclaration
Swift
public func observeChatState(identifier: ObservableIdentifier = .uuid(), _ completion: @escaping (ChatState) -> Void) -> ObservationTokenParameters
identifierObservableIdentifier to be exclusive, or unique
completionblock that executes everytime there is an update to the
ChatStateReturn Value
An
ObservationTokenthat can cancel the subscription to theChatState.
Install in Dash
ChatProvider Class Reference