Workflow: How to create a condition in the bot builder to check when no agents are available

<p>In this workflow, you'll learn how to create a conditional flow that checks if agents are available. While the <a href="https://support.zendesk.com/hc/en-us/articles/4408838909210" target="_blank" rel="noopener noreferrer">bot builder</a> can verify if a message arrived during business hours, it doesn't automatically detect agent availability. To achieve this, you need to create an Application Programming Interface (API) connection that detects the number of online agents.</p><div class="note attention" id="topic_tjn_hrm_gwb__note_vyj_xg2_f2c">This article describes functionality available only to customers who had a drafted or published Artificial Intelligence (AI) agent as of February 2, 2025. For information about equivalent functionality in the <a class="xref" href="https://support.zendesk.com/hc/en-us/articles/6970583409690" target="_blank" rel="noopener noreferrer">AI agents - Advanced add-on</a>, see <a class="xref" href="https://support.zendesk.com/hc/en-us/sections/8264324615322" target="_blank" rel="noopener noreferrer">Building dialogues for AI agents - Advanced</a>.</div><p>To create this workflow:</p><div style="margin-bottom: 20px; text-align: right;">
<button id="master-toggle" class="btn fw-semibold text-dark" data-action="expand" style="background-color: #DEF991; border: none; outline: none; border-radius: 7px; padding: 10px 20px; font-size: 15px; transition: background-color 0.2s ease;" onmouseover="this.style.backgroundColor='#cbef6d'" onmouseout="this.style.backgroundColor='#DEF991'">
Expand all tabs
</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const toggleBtn = document.getElementById('master-toggle');

toggleBtn.addEventListener('click', function () {
const action = this.getAttribute('data-action');
const headers = document.querySelectorAll('.accordion');

headers.forEach(header => {
const isActive = header.classList.contains('active');
const panel = header.nextElementSibling; // Grabs the corresponding .panel container

if (action === 'expand' && !isActive) {
// Open it by simulating a standard click
header.click();
} else if (action === 'collapse' && isActive) {
// Close it by simulating a standard click
header.click();
}
});

// Flip button text and states
if (action === 'expand') {
this.setAttribute('data-action', 'collapse');
this.textContent = 'Collapse all tabs';
} else {
this.setAttribute('data-action', 'expand');
this.textContent = 'Expand all tabs';
}
});
});
</script><div class="accordion"><h3 id="h_01J5XGC9NS7Q3EQGDK5PQKQWQM">Step 1: Create a bearer token</h3></div><div class="panel"><p>Create a bearer token for the Zendesk Chat API. See <a href="https://support.zendesk.com/hc/en-us/articles/4408828740762-Chat-API-tutorial-Generating-an-OAuth-token-integrated-Chat-accounts" target="_blank" rel="noopener noreferrer">Chat API tutorial: Generating an OAuth token</a>.</p></div><div class="accordion"><h3 id="h_01J5XGCFBRDX8QR8G1XMJ72WAQ">Step 2: Create an API connection</h3></div><div class="panel">
<p>To create an <a href="https://support.zendesk.com/hc/en-us/articles/5040378297626-Creating-API-connections-for-the-bot-builder" target="_blank" rel="noopener noreferrer">API connection</a>:</p>
<ol>
<li data-list-item-id="e1d1496048f14bf4d0c4ee3588abb3567">In <a href="https://support.zendesk.com/hc/en-us/articles/4581766374554-Using-Zendesk-Admin-Center" target="_blank" rel="noopener noreferrer">Admin Center</a>, navigate to <strong>Apps and integrations &gt; Connections</strong> &gt; <strong>Create connection </strong>and click <strong>Custom connection</strong>
</li>
<li data-list-item-id="e3905a97840c951cf3dc1d54d2ab30a48">Select the <strong>Bearer token</strong> authentication type and enter the token created in <a href="#h_01J5XGC9NS7Q3EQGDK5PQKQWQM">Step 1</a>
</li>
<li data-list-item-id="e6a0468d81b759256e16cc8c9e27caa35">Enter the allowed domain value <code>rtm.zopim.com</code>
</li>
</ol>
</div><div class="accordion"><h3 id="h_01J5XGCN100K3QV99K7XN7NT05">Step 3: Create a conditional statement in the bot builder</h3></div><div class="panel">
<ol>
<li data-list-item-id="e1d03645621ab0d3b8034ad510241d0bc">In <a href="https://support.zendesk.com/hc/en-us/articles/4581766374554-Using-Zendesk-Admin-Center" target="_blank" rel="noopener noreferrer">Admin Center</a>, navigate to <strong>AI &gt; AI agents</strong> and select your bot</li>
<li data-list-item-id="ed01f218e23bdd26167ba4ab8e3795a1e">Go to the <a href="https://support.zendesk.com/hc/en-us/articles/4422584657434-Creating-conversation-bot-answers-for-common-customer-questions" target="_blank" rel="noopener noreferrer">Topic</a> tab</li>
<li data-list-item-id="ea6fc7c7fe6ac2d65a44ed0a353694ec7">
<p>In the bot builder, add the <strong>Make API call</strong> step with these API details: select <strong>GET</strong> for the <strong>Request method</strong>, enter <code>https://rtm.zopim.com/stream/agents/agents_online</code> for the <strong>Endpoint URL</strong>, and select the connection created in Step 2 in the <strong>Authentication</strong> field. Click <strong>Make API call</strong> to test the call and return status code 200. Under the <strong>Variables</strong> tab in the <strong>Key</strong> column, expand <strong>Content</strong> then <strong>Data</strong>. Find <strong>agents_online</strong> and click <strong>Save</strong>. The <strong>Add variable</strong> popup appears. Click <strong>Save</strong> to create the <code>agents_online</code> variable.</p>
<p><img class="wysiwyg-image-resized" style="aspect-ratio: 1542/1818; width: 50%;" src="https://support.zendesk.com/hc/article_attachments/10052448411674" alt="Add the agents_online variable in the Make an API call step" width="1542" height="1818"></p>
</li>
<li data-list-item-id="e0a9a4e69fc41f84b8d9b2424702ede38">Under <strong>API call successful</strong>, add a <strong>Branch by condition</strong> step with the <strong>If this</strong> and <strong>Else</strong> options</li>
<li data-list-item-id="e4a36d44e6c5e47036a9ba5c448e8d0b8">Open the <strong>If this</strong> branch and rename it to <strong>Online</strong>, then click <strong>Add condition</strong>
</li>
<li data-list-item-id="e5a9d7280c488dcf130c86cad6f2de8e6">
<p>Add the condition, <strong>Variables &gt; agents_online | Is not | 0</strong></p>
<p><img class="wysiwyg-image-resized" style="aspect-ratio: 1462/1912; width: 42.29%;" src="https://support.zendesk.com/hc/article_attachments/10052418845722" alt="Add the condition that checks if agents_online is not 0" width="1462" height="1912"></p>
</li>
<li data-list-item-id="e218c046a43dcfdce6cb074c42f0477cb">Verify the condition checks for live agents in Chat. Complete the flow with your desired steps and publish the bot.</li>
</ol>
<div class="p"><div class="note">Note: The real-time API used above is available to Enterprise plans.</div></div>
</div>