live_chat_agents_available
Check whether someone in LiveChat is accepting chats before you hand a web chat over to them.
live_chat_agents_available(context: dict) -> dictChecks whether at least one agent in the business's LiveChat handoff group is accepting chats right now.
Use it before handing a web chat off to LiveChat. Agents who are logged in but not accepting chats don't see queued chats, so without this check a customer can wait in a queue nobody is watching. When nobody is available, don't hand off: tell the customer, in their language, that no consultants are available right now and to try again later.
For agents who work in the Octocom help desk, use octocom_agents_available instead.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The execution context. It must contain the conversation. |
Returns
{
"configured": bool, # the business has a LiveChat handoff group
"available": bool, # at least one agent in the group is accepting chats
"acceptingChatsCount": int, # number of agents accepting chats
"channel": str, # the conversation's latest channel, e.g. "web"
}channel is missing when the check could not run (see below).
Behavior
- Not configured: when
configuredisFalse, LiveChat handoff doesn't apply to this business. Proceed with your normal flow. - Which group is checked: the group this conversation would be handed off to. That is the business's default LiveChat handoff group, unless a bot action routed the conversation to another group by setting the
livechat_handoff_group_idconversation metadata to a numeric LiveChat group ID. - Fails open: if LiveChat or Octocom can't answer, the helper returns
available: True, so a transient error never blocks a handoff. - No conversation: without
context["conversation"](for example in an editor test without a conversation), it returns{"configured": False, "available": True, "acceptingChatsCount": 0}.
Examples
Hand off only when someone can take the chat
def execute_action(context):
availability = live_chat_agents_available(context)
if availability["configured"] and not availability["available"]:
return {
"handedOff": False,
"message": "No consultants are available right now. Tell the customer, "
"in their language, to try again later.",
}
hand_off_conversation(context, reason="Customer asked for a consultant")
return {"handedOff": True}Route business customers to their own group, then check it
BUSINESS_GROUP_ID = "7" # your LiveChat group ID
def execute_action(context):
if context["args"].get("isBusinessCustomer"):
set_conversation_metadata(context, "livechat_handoff_group_id", BUSINESS_GROUP_ID)
# Checks the business group when it was set above, otherwise the default group.
availability = live_chat_agents_available(context)
if availability["configured"] and not availability["available"]:
return {"handedOff": False, "reason": "no_consultants_available"}
hand_off_conversation(context, reason="Business customer asked for a consultant")
return {"handedOff": True}Related
hand_off_conversationhands the conversation to a human.- Use Octocom with another help desk explains how web chat handoffs open a live chat in LiveChat.