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:
let config = SCSChatConfiguration(liveAgentPod: "YOUR-POD-NAME",
orgId: "YOUR-ORG-ID",
deploymentId: "YOUR-DEPLOYMENT-ID",
buttonId: "YOUR-BUTTON-ID")
ServiceCloud.shared().chatCore.determineAvailability(with: config,
completion: { (error: Error?,
available: Bool,
estimatedWaitTime: TimeInterval) in
if (error != nil) {
// TO DO: Handle error
}
else if (available) {
// TO DO: Enable chat button...
// Optionally, use the estimatedWaitTime to
// show an estimated wait time until an agent
// is available. This value is only valid if
// SCSChatConfiguration.queueStyle is set to
// EstimatedWaitTime. Estimate is returned
// in seconds.
}
else {
// TO DO: Disable button or warn user that no agents are available
}
})
In Objective-C:
SCSChatConfiguration *config =
[[SCSChatConfiguration alloc] initWithLiveAgentPod:@"YOUR-POD-NAME"
orgId:@"YOUR-ORG-ID"
deploymentId:@"YOUR-DEPLOYMENT-ID"
buttonId:@"YOUR-BUTTON-ID"];
[[SCServiceCloud sharedInstance].chatCore
determineAvailabilityWithConfiguration:config
completion:^(NSError *error, BOOL available,
NSTimeInterval estimatedWaitTime) {
if (error != nil) {
// TO DO: Handle error
}
else if (available) {
// TO DO: Enable chat button...
// Optionally, use the estimatedWaitTime to
// show an estimated wait time until an agent
// is available. This value is only valid if
// SCSChatConfiguration.queueStyle is set to
// EstimatedWaitTime. Estimate is returned
// in seconds.
}
else {
// TO DO: Disable button or warn user that no agents are available
}
});
To understand the algorithm used for the estimated wait time, see the estimated wait time documentation in the Chat REST API Developer Guide.