# Using Smartsupp

This page will describe methods which are available to you.

# Opening Chat Box

Opens the Chat box.

# UIKit

Smartsupp.openChatBox(from: self) {
    switch $0 {
    case .success:
        print("Chatbox was opened")
    case .error(let error):
        print("Failed to open the Chatbox - \(error.localizedDescription)")
    }
}

# SwiftUI

Smartsupp.openChatBox {
    switch $0 {
    case .success:
        print("Chatbox was opened")
    case .error(let error):
        print("Failed to open the Chatbox - \(error.localizedDescription)")
    }
}

The method to open the Chat Box has a callback with an enum. success indicates that the validation was successful and the Chat Box will open. If you recieve an error, check your Smartsupp key and API key.

WARNING

User has to be connected to the internet in order to open the Chat Box.

# User Identification

Set additonal properties of your user.

Smartsupp.identifyUser(
    name: "John Appleseed",
    email: "john.appleseed@apple.com",
    phone: "+420123456789",
    variables: [
        "custom_id": "2343233",
        "age": "29"
    ]
)

Each value is optional, so you can use only the ones you need.

TIP

For more information visit this (opens new window).

# State

You can get information such as account status and number of unread messages from Smartsupp.shared.state.

class SmartsuppState {
    var unreadMessages: Int
    var status: Smartsupp.AccountStatus
    var userIsBlocked: Bool
}

If you want to observe changes of these values, just add a delegate Smartsupp.shared.state.delegate.add(self).

protocol SmartsuppStateDelegate: AnyObject {
    func smartsuppState(unreadMessages: Int)
    func smartsuppState(status: Smartsupp.AccountStatus)
    func smartsuppState(userIsBlocked: Bool)
}