How to build a seamless chatbot to human handoff with a customer support AI chatbot
Why is chatbot to human handoff a critical necessity for customer support AI chatbots?
Despite the remarkable humanlike capabilities of AI chatbots and their use cases in healthcare, ecommerce, and fintech, consumers find reassurance when interacting with a human customer support agent. This human touch is a fundamental aspect of all your customer communication.
This is why chatbot to human handoff represents a highly relevant and practical use case for a customer support AI chatbot. The AI chatbot can handle straightforward requests autonomously, and judiciously transfer complex or edge cases to a human customer support agent while equipping them with comprehensive information (or a summary!) of the case.
For example, in an ecommerce use case, users can engage with a customer support AI chatbot for routine queries; for nuanced questions, the chatbot to human handoff is a smooth transition for the user to receive personalized attention, showcasing the dynamic synergy of AI efficiency and human empathy in modern customer service.
From a business perspective, the customer support AI chatbot serves as an ally to a human customer support agent because it can efficiently pre-process requests before requesting human help. This is why chatbot to human handoff offers a strategic and efficient approach to addressing diverse customer needs, streamlining customer communication, and increasing CSAT.
This tutorial walks you through implementing a seamless chatbot to human handoff from a customer support AI chatbot to a Sendbird Desk support agent. Leveraging the power of OpenAI’s LLM, GPT, we’ll explore the key steps and concepts essential to mastering this and optimizing your customer support workflow.
By the end of this tutorial, you will have built a robust customer support AI chatbot that transitions from automated responses to live human agent interactions. This is what the handover looks like:

Your customer support AI chatbot will manage straightforward queries by itself and ensure a seamless chatbot to human handoff for complex cases. You'll also set up webhooks to ensure the smooth operation of this chatbot to human handoff, as well as establish a system for ticket prioritization and agent assignment.
Here’s what the chatbot to human handoff flow looks like:

Let's get started! 💻
Prerequisites for building an efficient chatbot to human handoff for a customer support AI chatbot
To get the most out of this tutorial, we recommend:
Familiarity with Open AI’s function calling
Knowledge of JavaScript
With that out of the way, let’s dive into the implementation details!
How to implement chatbot to human handoff for effective customer communication
Before we build the actual chatbot to human handoff, we need to first build the customer support AI chatbot, then auto-assign the chatbot to a Sendbird Desk ticket using a webhook, and finally update the Desk ticket when talking to an agent.
Part 1: Build the customer support AI chatbot
Let’s first build the AI chatbot for customer support.
Step 1: Create the bot
In the Sendbird Dashboard, go to Chat → AI chatbot → Manage bots → Create bot.

Fill out the following details:
Bot name = “helpful bot”
Bot ID = “helpful_bot”
Forward event message only → On (When turned on, only the messages that mention a bot or start with "/" to a bot will be forwarded to a bot.)
Bot AI engine = OpenAI ChatGPT

Under Default message, set the Welcome message: “Hi there. I’m Bob, your helpful AI bot.”
Suggested replies = N/A
In the Bot settings section, in the Parameter settings box, set the system prompt. This is your bot’s persona. Consider using ChatGPT to generate and modify the bot’s persona. Here’s a suggested persona prompt to ChatGPT: “Write me a persona for a bot that has a document to find answers from. If the bot can't answer from the document, or if the user asks, ensure that the bot is ready to hand over to a human”.

Upload your target example document. Note that you can generate example texts using ChatGPT.

Add the function calls seen in Step 2 of Part 1.
Example AI chatbot persona
Note: The below persona was generated by using ChatGPT-4 via the web interface. The following prompt or similar can be used: “Please generate a bot persona for a bot that is friendly and has the role of answering questions about a document and knowing when to hand over to a human.”
Name: DocBot
Appearance: A friendly-looking digital icon, possibly a robot holding a magnifying glass and a document.
Purpose: To swiftly provide answers from a predefined document. If unable to do so, or upon user request, it facilitates a seamless transition to a human representative for further assistance.
Introduction: "Hello! I'm DocBot. I'm here to help you find answers from our document. If I can't provide an answer or if you'd like to speak to a human, just let me know!"
---
Capabilities:
Scan and fetch answers from the document.
Recognize when a query is outside the scope of the document.
Initiate a handover to a human representative upon user request or when the bot can't find an answer.
---
Key Phrases:
"I've found the answer in our document! Here it is..."
"I'm sorry, I couldn't find an answer to that in our document. Would you like to speak to a human representative?"
"Of course, I'll connect you to a human representative right away!"
---
Behavior & Personality:
Quick and efficient in fetching information.
Polite and always willing to assist.
Understands the importance of a human touch and is never hesitant to recommend a human representative when needed.
---
Limitations:
Cannot provide information outside the pre-defined document.
Does not have capabilities beyond document scanning and connecting to human representatives.
Step 2: Create the function to listen for a possible transfer to a human
In the Sendbird Dashboard, go to Chat → AI chatbot → Function calls → Create function.

Fill out the following details:
Name = “hand_over_to_a_human”
Key = “hand_over_to_a_human”
Prompt (adjust the prompt based on how well the bot is detecting the target scenario)
Listen for when one of these conditions is met:
The user asks to speak with a human.
The conversation is getting beyond the content of the provided document and you judge a human is needed.
- Set the Method as “POST”. Use any endpoint that is going to return 200 right away. In this case, we use Beeceptor. Use the Dashboard Tester to make sure the calls will go through. In production, however, consider a more reliable approach.
💡 Why is only a 200 response needed? Because it is not possible currently to send channel details via Bot functions. We use a webhook to listen for the bot’s response rather than the initial data sent to the POST request.

Set the Request body = {“hand_over”: true}. Note that this data is a required placeholder but is not used by the service running in this project. Instead, in the message webhooks, we will be listening for the function name “hand_over_to_a_human”.
Finally, go back to the bot created above and add the “hand_over_to_a_human” function. (Sendbird Dashboard → Chat → AI chatbot → Manage bots → helpful bot → Edit → Function calls → Select function → Select “hand_over_to_a_human” → Confirm)



Step 3: Create a testing channel
Consider using the built-in bot testing tool to test that the function fires when expected:
Go to the Sendbird Dashboard → Application → Chat → AI chatbot → Manage bots → Your bot

We suggest that you keep track of your prompts in a digital notebook. You could consider keeping track of what you have tried and what prompts need changing to arrive at a desired result. Consider setting up regular testing schedules once in production.
Step 4: Test your customer support AI chatbot and its functionality in the channel
It is also important to test that your function will trigger when expected in the channel. The following video explains this well:

The video advises you to:
Open Beeceptor or any other POST endpoint you created for the function “hand_over_to_a_human”
Go to Dashboard → Chat → Group → helpful_bot_test
Start talking to the bot → Ask a question about your uploaded doc
- Test the hand_over_to_a_human Function
“Please hand me over to a human”
Tune your function prompt to make sure that it consistently triggers as you need
Part 2: Auto-assign the customer support AI chatbot to a Desk ticket using a webhook

In this example, the Desk tickets are created via the Desk SDK’s createTicket method as LOW_PRIORITY. Therefore, we need to listen for the ticket creations and then assign a bot the moment the ticket is created.
Note that perhaps in the future this step won’t be necessary, but Sendbird’s ChatGPT integration is new and its bots are not fully integrated with Desk just yet.
Step 1: Set up Desk webhook
Here’s what the workflow for this looks like:
The end user creates a ticket
Sendbird fires the TICKET.CREATED webhook
Your web server listens for the event and adds the bot to the ticket’s Sendbird channel

Code for handling the webhook:
Code for inviting the bot to the ticket’s Sendbird channel:
How to test this:
Please take a look at this Desk widget sample. Once it is up and running, create a few tickets to see if your webhook server is working. After the ticket is created, you can use the Sendbird Desk interface.
Part 3: Update Desk ticket when it's time to talk to an agent

In this section, we consider what happens when the “hand_over_to_a_human” function is triggered.
A conversation is ongoing with the bot.
The user wants to speak with a human. Alternatively, some other triggering factor or scenario is automatically detected by the bot.
The “Hand_over_to_a_human” function is triggered.
A POST request is made with Beeceptor or your own endpoint.
The bot responds with a message in the channel (seen below).
Your web server webhook listens for a “hand_over_to_a_human” response in the group_channel:message_sent webhook.
Update the ticket to high priority (PATCH ticket), set its status to Pending, and assign it to a group/team (POST transfer_to_group). Setting the group will cause the ticket to enter the Desk round robin assignment service. Please see the docs for details about groups/teams.
Note: Groups in the Docs are the same as Teams in the Desk Dashboard interface.

Webhook code for listening to messages:
Code for updating a ticket:
The incoming message contains the channel URL.
The channel URL can be used to GET the target ticket.
As mentioned above, update the ticket’s priority, then update its status and groupkey.
Below is an example of the bot’s message that will arrive in the message webhook.
Many fields are not shown for simplicity. Notice that the message.data contains function_calls.name = hand_over_to_a_human
Build an efficient, streamlined chatbot to human handoff flow with Sendbird
Congratulations on implementing a chatbot to human handoff using Sendbird's AI chatbot powered by OpenAI's GPT! You now know how to build a robust customer support AI chatbot that answers routine queries by itself and hands off complex cases to a human customer support agent. In this tutorial, we talked about how to create the customer support AI chatbot, assign the bot to a Sendbird Desk ticket using a webhook, and update the Desk ticket when the user needs to talk to a human support agent. This opens the door to a world of possibilities where AI and human agents work in tandem to provide exceptional customer communication experiences. But that's just the beginning!
We recommend that you dive deeper into our tutorials to unlock the full potential of generative AI. Learn how to leverage OpenAI's functions for structured data retrieval, bringing a new level of sophistication to your conversational AI. You can also enhance control with features like suggested replies and pre-scripted answers, bypassing the LLM when ideal responses are readily available (see our tutorials about building ecommerce, healthcare, and fintech AI chatbots!). This not only boosts efficiency, but also ensures a consistent and reliable interaction.
If you use a support platform like Salesforce support cloud, check out our support chat extension. For Zendesk users wanting to enhance their chat interface, check out this tutorial. Freshdesk customers wanting to build a webcall functionality can do so easily thanks to this tutorial.
We encourage you to explore, experiment, and tailor your AI customer support implementation to your unique needs. Sendbird empowers you to shape customer conversations that resonate with your audience, making every interaction meaningful and memorable. Enhance customer satisfaction, streamline customer communication, and foster loyalty with Sendbird's conversational AI capabilities today!
Happy memorable and effective in-app support building with Sendbird! 🧑💻