Business Hours for Android
If you’ve set up business hours in Salesforce, use the retrieveBusinessHours method to check for business hours and handle things accordingly. For instance, you can hide the chat button outside of business hours. When using the UI SDK, customers see a banner in the chat window when it’s outside of business hours.
To configure business hours for your deployment, see Set Business Hours in Enhanced Chat.
This feature requires version 1.3.0 or later of the Enhanced In-App Chat SDK.
This article applies to the following implementations:
Retrieve the business hours from the core client object using the retrieveBusinessHours method, and then determine how to proceed based on that information. This method returns the business hours over the next 24 hours. You can use the helper method isWithinBusinessHours to determine whether a time is within business hours; specifying no argument uses the current time.
This sample requires the configuration object that you created when setting up the UI SDK or the Core SDK. See Build a UI SDK App or Build a Core SDK App for more information.
1private val scope = CoroutineScope(Dispatchers.Main + supervisorJob)
2
3fun handleBusinessHours() {
4
5 // Handle business hours suspend function within a scope
6 scope.launch {
7 // Create a core client from a config
8 val coreClient = CoreClient.Factory.create(myContext, config)
9
10 // Get business hours info
11 val result = coreClient.retrieveBusinessHours()
12 val businessHoursInfo: BusinessHoursInfo? = (result as? Result.Success)?.data
13
14 // Determine whether we're currently within business hours
15 if (businessHoursInfo?.isWithinBusinessHours() != false) {
16 // TO DO: Handle when we're within business hours
17 } else {
18 // TO DO: Handle when we're outside of business hours
19 }
20
21 // Alternatively, you can inspect the business hours info.
22 // For instance, get specific business hours time periods
23 // using the businessHoursInfo.businessHours list.
24 }
25}