Skip to main content

How to build a seamless chatbot to human handoff with a customer support AI chatbot

Jason Allshorn 1
Jason Allshorn
Solutions Engineer
  • Tutorial Type: Basics
  • Reading Time: 15 min
  • Building Time: 45 min
Mobile engagement scorecard mobile content offer background

Build a chatbot to human handoff

Try Sendbird for free

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:

Tutorial image Customer service AI You Tube video thumbnail

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:

A visual depiction of the chatbot to human handoff flow
A visual depiction of the chatbot to human handoff flow

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:

  1. A free Sendbird account

  2. Familiarity with Open AI’s function calling

  3. 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.

Create an AI chatbot in the Sendbird Dashboard
Create an AI chatbot in the Sendbird Dashboard

Fill out the following details:

  1. Bot name = “helpful bot”

  2. Bot ID = “helpful_bot”

  3. 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.)

  4. Bot AI engine = OpenAI ChatGPT

The bot’s profile details
The bot’s profile details
  1. Under Default message, set the Welcome message: “Hi there. I’m Bob, your helpful AI bot.”

  2. Suggested replies = N/A

  3. 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”.

The bot’s welcome message and system prompt
The bot’s welcome message and system prompt
  1. Upload your target example document. Note that you can generate example texts using ChatGPT.

Uploading the target example document
Uploading the target example document
  1. 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.

The Sendbird dashboard
The Sendbird dashboard

Fill out the following details:

  1. Name = “hand_over_to_a_human”

  2. Key = “hand_over_to_a_human”

  3. 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.

  1. 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.

Details of the function to listen for human handover
Details of the function to listen for human handover
  1. 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”.

  2. 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)

Edit your bot
Edit your bot
Edit the function calls
Edit the function calls
Select the function you just created
Select the function you just created

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

Go to your bot
Go to 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:

Tutorial image Testing Sendbird Chat GPT Function You Tube thumbnail

The video advises you to:

  1. Open Beeceptor or any other POST endpoint you created for the function “hand_over_to_a_human”

  2. Go to Dashboard → Chat → Group → helpful_bot_test

  3. Start talking to the bot → Ask a question about your uploaded doc

  4. Test the hand_over_to_a_human Function
    1. “Please hand me over to a human”

  5. 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

Tutorial image Add bot to ticket channel You Tube thumbnail

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:

  1. The end user creates a ticket

  2. Sendbird fires the TICKET.CREATED webhook

  3. Your web server listens for the event and adds the bot to the ticket’s Sendbird channel

Workflow for the Desk webhook
Workflow for the Desk webhook

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

Tutorial image Hand over to a human You Tube video thumbnail

In this section, we consider what happens when the “hand_over_to_a_human” function is triggered.

  1. A conversation is ongoing with the bot.

  2. The user wants to speak with a human. Alternatively, some other triggering factor or scenario is automatically detected by the bot.

  3. The “Hand_over_to_a_human” function is triggered.

  4. A POST request is made with Beeceptor or your own endpoint.

  5. The bot responds with a message in the channel (seen below).

  6. Your web server webhook listens for a “hand_over_to_a_human” response in the group_channel:message_sent webhook.

  7. 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.

The flow for the “hand_over_to_a_human” function
The flow for the “hand_over_to_a_human” function

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! 🧑‍💻