![Available on Suite Enterprise plans and above](https://zen-marketing-documentation.s3.amazonaws.com/docs/en/plan_available_suite_ee.png)
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.
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.
Task 1: Checking your setup
- A Zendesk account with a published AI agent for messaging. If you want, 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. For information about using messaging in a sandbox environment, see Using messaging in your sandbox.
- 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.
- 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
Channels in the sidebar, then select AI agents and automation > AI agents.
- Click Manage AI agents for messaging.
- 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.
- 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.
3 comments
Chris Hillam
This was extremely helpful, thank you!
I am configuring Messaging for multiple brands in our environment, and not every agent is assigned to every brand. It seems this is checking whether agents are available on the account level, but not checking whether agents are available in a particular group.
Example: Agents are available in Brand A, but Brand B agents are Invisible for a training session. During that time I'd like to deflect Messages from Brand B using this method.
Assuming I've set everything up correctly, agents being Available in Brand A seem to make it so if the API call sees online agents at all, it routes incoming Brand B messages as if agents are available.
Are there additional variables I can add which would check for available agents at the brand-level?
0
Alex Mashinski
This is a great step in the right direction. Is there by chance any API ability to surface an endpoint around chat wait time. We are looking to utilize this to show an offering of the quickest route to contact in support.
0
Chris Batt
Is this still supported? In the Live Chat API Reference it says:
Important: The Zopim Chat REST API at www.zopim.com/api/v2 is being phased out in favor of {subdomain}.zendesk.com/api/v2/chat. Both APIs will be available concurrently until February 28, 2025, allowing customers time to transition at their own pace.
But it doesn't seem the Real Time Chat REST API, which supports the endpoints for getting chat metics (eg: `/stream/chats/{metric_key}` or specifically `/stream/chats/agents_online`), is set up to use the `{subdomain}.zendesk.com/api/v2/chat` domain.
We would love to enable this, but only if it's still gonna work next month :-)
0