The conversation bot builder's Add business hours condition step lets you branch a conversation bot'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 bot 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 bot 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 messaging bot. If you want, you can use a
sandbox testing environment to
test the bot before using it in production.
To set up a conversation bot on a web and mobile messaging channel, see Working with conversation bots 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 conversation bot 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.
- 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 conversation bot. 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 Bots and automations > Bots. Then click Manage bots.
- Click the bot you want to update. Then click the answer you want to update.
- In the 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_onlineas 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 bot
When you're done editing the answer, you can publish the updated bot.
- Click Done in the upper right corner of the bot builder.
- On the bot page, click Publish bot.
- 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 bot. For more information about testing conversation bots, see Testing the end user's messaging experience.