Check Agent Availability
Before starting a session, you can check the availability
of your chat agents and then provide your users with more accurate
expectations.
To check whether agents are available, call the determineAvailabilityWithConfiguration method on the chatCore property, similar to how you start a chat session.
In Swift:
1let config = SCSChatConfiguration(liveAgentPod: "YOUR-POD-NAME",
2 orgId: "YOUR-ORG-ID",
3 deploymentId: "YOUR-DEPLOYMENT-ID",
4 buttonId: "YOUR-BUTTON-ID")
5
6ServiceCloud.shared().chatCore.determineAvailability(with: config,
7 completion: { (error: Error?,
8 available: Bool,
9 estimatedWaitTime: TimeInterval) in
10
11 if (error != nil) {
12 // TO DO: Handle error
13 }
14 else if (available) {
15 // TO DO: Enable chat button...
16
17 // Optionally, use the estimatedWaitTime to
18 // show an estimated wait time until an agent
19 // is available. This value is only valid if
20 // SCSChatConfiguration.queueStyle is set to
21 // EstimatedWaitTime. Estimate is returned
22 // in seconds.
23 }
24 else {
25 // TO DO: Disable button or warn user that no agents are available
26 }
27
28})In Objective-C:
1SCSChatConfiguration *config =
2 [[SCSChatConfiguration alloc] initWithLiveAgentPod:@"YOUR-POD-NAME"
3 orgId:@"YOUR-ORG-ID"
4 deploymentId:@"YOUR-DEPLOYMENT-ID"
5 buttonId:@"YOUR-BUTTON-ID"];
6
7[[SCServiceCloud sharedInstance].chatCore
8 determineAvailabilityWithConfiguration:config
9 completion:^(NSError *error, BOOL available,
10 NSTimeInterval estimatedWaitTime) {
11
12 if (error != nil) {
13 // TO DO: Handle error
14 }
15 else if (available) {
16 // TO DO: Enable chat button...
17
18 // Optionally, use the estimatedWaitTime to
19 // show an estimated wait time until an agent
20 // is available. This value is only valid if
21 // SCSChatConfiguration.queueStyle is set to
22 // EstimatedWaitTime. Estimate is returned
23 // in seconds.
24 }
25 else {
26 // TO DO: Disable button or warn user that no agents are available
27 }
28
29});To understand the algorithm used for the estimated wait time, see the estimated wait time documentation in the Chat REST API Developer Guide.