Is chat available?

Returns the current chat availability for an organization.

If your organization has Business Schedules or Holidays enabled, the Boolean passed in the callback for Kustomer.isChatAvailable() callback will return the following: 1) the availability based on those dates and times, and 2) the initialization state of the SDK.

This callback will return false if you have chat completely turned off and the SDK has loaded settings at least once.

This callback tells you if the SDK is ready to present a chat interface. If the SDK hasn’t been initialized (that is, the SDK doesn’t have settings information loaded or cached), Kustomer.isChatAvailable() will return false. If you have chat set to appear available outside of business hours, Kustomer.isChatAvailable() will return true.

let provider = ChatProvider.shared

let available: Bool? = provider.isChatAvailable()

if available == nil {
  print("Unknown")
} else {
  print("Is chat available? \(available)")
}
// This is the deprecated version. Please see the changlog entry for v2.0.7 more information.

let provider = ChatProvider.shared

provider.isChatAvailable({ available in
  print("Is chat available? \(available)")
})

When isChatAvailable is nil

If isChatAvailable() is nil, this means either that 1) the local settings cache is empty or expired, or 2) that an internet connection has never been available when the SDK tried to refresh settings.

Common scenarios for when isChatAvailable is nil

Here are some common scenarios for when isChatAvailable is set to nil:

  1. The user accesses chat during your set business hours
  2. The user opens Kustomer Chat with a working internet connection
  3. The user force quits your app
  4. The user turns on Airplane Mode on their device
  5. The user opens your app
  6. isChatAvailable() is returning true

👍

Automated cache management for chat settings

The Kustomer Chat SDK automatically manages the cache for chat settings.

With this in mind, do not add calls to reloadChatSettings when your app opens, or when internet connectivity changes.

The Chat SDK does reloads chat settings automatically as needed to show the chat interface.

**How to query Kustomer servers for the value of nil
If isChatAvailable() is nil, and you need to know the value, you can use reloadChatSettings to query Kustomer's servers.

let provider = ChatProvider.shared

let available: Bool? = provider.isChatAvailable()

if available == nil {
  tryToFetchSettings()
} else {
  print("Is chat available? \(available)")
}

func tryToFetchSettings() {
  ChatProvider.shared.reloadChatSettings({ error in
    if error == nil {
      print("Chat settings fetched from servers")
    } else {
      print("Could not reload chat settings because \(error)")
    }
  })
}