# 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 additional 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).
# Reset User
Method clears the current user's data and initiates a fresh chat session, providing a clean slate for interaction.
Smartsupp.resetUser()
# 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)
}
# Localization
By default, the ChatBox attempts to match the language of your app. To explicitly change the language, you can either use one of the predefined languages in the SmartsuppLanguage
enum or provide a String with the ISO 639-1 code of the desired language. If the specified language isn't supported, the default behavior will apply.
Smartsupp.setChatboxLanguage(_ language: SmartsuppLanguage)
Smartsupp.setChatboxLanguage(_ language: String)
TIP