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 the observeChatState function.

    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 Chat is ongoing if the given ChatInfo model’s isChatting flag, is set to true.

    Declaration

    Swift

    public func getChatInfo(_ completion: @escaping (Result<ChatInfo, Error>) -> Void)

    Parameters

    completion

    block that is invoked once the getChatInfo request 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 other ChatProvider methods to ensure the department was set successfully.

    The Chat is ongoing if the given ChatInfo model’s isChatting flag, is set to true. Retrieve the list of department names from via the AccountProvider.

    Declaration

    Swift

    public func setDepartment(_ name: String?,
                              completion: ((Result<String?, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    name

    The name of the department to set.

    completion

    block that is invoked once the getChatInfo request 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

    isTyping

    isTyping

  • 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 send

    Declaration

    Swift

    public func sendOfflineForm(_ offlineForm: OfflineForm, completion: ((Result<OfflineForm, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    offlineForm

    OfflineForm model

    completion

    block 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

    message

    visitor message

    completion

    Result<String, DeliveryStatusError> closure to handle delivery status of message. Default is nil

  • 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 FailedMessageError will be propagated through completion block.

    Declaration

    Swift

    public func resendFailedMessage(withId id: String, completion: ((Result<String, Error>) -> Void)? = nil)

    Parameters

    id

    id of the failed message.

    completion

    Result<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 FailedMessageError will 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

    id

    id of the failed message.

    completion

    Result<String, Error> closure to handle deletion status of message. Default is nil

File Uploads

  • Send an attachment message.

    Declaration

    Swift

    public func sendFile(url: URL,
                         onProgress: ((Double) -> Void)? = nil,
                         completion: ((Result<ChatAttachmentMessage, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    url

    The file URL of the attachment to send

    onProgress

    Handle file upload progress

    completion

    Result<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

    id

    id of the attachment message.

    onProgress

    closure to handle upload progress

    completion

    Result<ChatAttachmentMessage, Error> closure to handle resend status of message. Default is nil

Chat Rating

  • Send a chat Rating for the active session

    Declaration

    Swift

    public func sendChatRating(_ rating: Rating, completion: ((Result<Rating, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    rating

    The rating of the session .good/.bad

    completion

    Result<Rating, DeliveryStatusError> closure to handle delivery status of message. Default is nil

  • Send a comment about the current chat session

    Declaration

    Swift

    public func sendChatComment(_ comment: String, completion: ((Result<String, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    comment

    The comment about the chat

    completion

    Result<String, DeliveryStatusError> closure to handle delivery status of message. Default is nil

  • 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

    email

    the email to send the transcript

    completion

    Result<String, DeliveryStatusError> closure to handle delivery status of message. Default is nil

End Chat

  • Ends the chat and closes the socket connection

    Declaration

    Swift

    public func endChat(_ completion: ((Result<Bool, DeliveryStatusError>) -> Void)? = nil)

    Parameters

    completion

    block to handle the status of the endChat request. true on success.

Observers