Messaging recipe: Checking agent availability during an AI agent conversation (Legacy)

Support with | Live chat and messaging Team, Professional, or Enterprise

This article describes functionality available only to customers who had a drafted or published AI agent as of February 2, 2025. For information about equivalent functionality in the AI agents - Advanced add-on, see Building dialogues for AI agents - Advanced.
The bot builder's Add business hours condition step lets you branch an AI agent's answers based on your business hours. However, it can't branch a conversation based on agent availability.

In this recipe, you’ll use the bot builder's Make API call and Branch by condition steps to branch an existing AI agent answer based on the number of online agents at the time of the conversation. The Make API call step gets a count of the current online agents by calling the Zendesk Real Time Chat REST API's Get Agent Status Count endpoint. The Branch by condition step then uses the count to branch the answer's flow.

Note: If your account was created after November 11, 2021, you can't use the use the Get Agent Status Count endpoint. Instead, use the Agent Availability API's Get agent availabilities endpoint.

You can use this setup to send customized AI agent messages before creating a ticket using the Transfer to agent step. These messages can help set better customer expectations around wait or response times.

The recipe involves the following tasks:

Task 1: Checking your setup

Task 2: Creating an API connection

Task 3: Retrieving agent availability

Task 4: Branching based on agent availability

Task 5: Publishing your updated AI agent

Task 6: Testing your changes

Task 1: Checking your setup

To complete this recipe, you'll need the following:

A Zendesk account with a published AI agent. If you are on a Suite Enterprise or Enterprise Plus plan, you can use a sandbox testing environment to test the AI agent before using it in production.
To set up an AI agent on a web and mobile messaging channel, see Creating an AI agent for your web and mobile channels.

An OAuth access token for the Zendesk Chat API. To create this token, see Chat API tutorial: Generating an OAuth token.

Task 2: Creating an API connection

To start, create an API connection to store your OAuth access token for the Chat API. Your AI agent can use this connection to authenticate calls to the API.

To create the connection

In Admin Center, click Apps and integrations in the sidebar, then select Connections > Connections.

Click Create connection.

Select the Bearer token authentication type.

For Connection name, enter "zendesk_chat_api_oauth_token".

For Token, enter your OAuth access token (see Task 1: Checking your setup).

For Allowed domain, enter "rtm.zopim.com".

Click Save to create the connection.

Task 3: Retrieving agent availability

Next, add a Make API call step to an existing answer in your AI agent. This step gets a current count of online agents from the Real Time Chat API's Get Agent Status Count endpoint.

To add the Make API call step

In Admin Center, click AI in the sidebar, then select AI agents > AI agents.

Click the AI agent you want to update, then click the answer you want to update.

In bot builder, add a step to the desired location in the answer's flow.

Under Choose step, select Make API Call.

Enter Get agent availability as the Name.

Under API details, enter https://rtm.zopim.com/stream/agents/agents_online as the Endpoint URL.

In Authentication, select the zendesk_chat_api_oauth_token connection.

To test the API request, click Make API call.

Under Test Data, enter Melbourne, AU as the Location.

Click Make API call.

Save the following variable using its default name:

content > data > agents_online

(Optional) Add a step under the Get agent availability step’s API call failed branch. This step runs if the Get Agent Status Count request fails.

Task 4: Branching based on agent availability

Next, add a Branch by condition step to branch the answer's flow based on the value of the agents_online variable.

To add the Branch by condition step

In the bot builder, add a step in the Get agent availability step's API call successful branch.

Under Choose step, select Branch by condition.

Enter Check agent availability as the Name.

In the If this branch, enter Agents are online as the Name.

In the If this branch, click Add condition. Configure the condition as follows:

Variable: agents_online

Operator: Is not

Value: 0

Click Add.

Add any desired steps under the Agents are online and Else branches. Steps under the Agents are online branch run when the Get Agent Status Count request indicates one or more agents are online. Steps under the Else branch run when the request indicates no agents are online.

Task 5: Publishing your updated AI agent

When you're done editing the answer, you can publish the updated AI agent.

To publish the AI agent

Click Done in the upper right corner of the bot builder.

On the AI agent page, click Publish AI agent.

Click Publish.

Task 6: Testing your changes

After you publish your changes, you can test the updated answer by using one of its training phrases in a conversation with the updated AI agent. For more information about testing AI agents, see Testing the end user's messaging experience.