Tiledesk Developer Hub
WebsiteCommunityTutorialsGet started
  • Introduction
  • Community
  • Ask for Support
  • Public Roadmap and Changelog
  • Tutorials
  • Widget
    • Widget SDK
    • Javascript API: Methods
    • Javascript API: Attributes
    • Javascript API: Listeners/Events
    • Widget Authentication
    • Widget Angular integration
    • Widget React integration
    • Widget for Android with WebView
    • Widget for iOS with WKWebView
    • Widget for Flutter with WebView
    • Widget for React with WebView
    • Widget for Wix Website platform
    • Tutorials
      • Hide widget
      • Show/Hide widget programmatically
      • Force widget loading without user interaction
      • Mobile positioning
      • Custom size (width/height)
      • Installing widget on selected pages
    • Conversation Embedded Apps
      • Payment App Tutorial
      • Prechat form App Tutorial
    • Advanced
      • Preset the Widget on a specific Department
      • Authentication Flow
      • Widget protocol specs
      • Prechat Form JSON specs
      • Prevent multiple conversations
      • Old versions
        • Web SDK v4
  • External Chatbot
    • Introduction
    • Hello World tutorial
    • Chatbot to Human handoff
    • Send Text Buttons
    • Advanced Tutorials
      • Introduction
      • Tutorial 1 - Dialogflow as external chatbot
      • Tutorial 2 - Buttons and images
      • Tutorial 3 - Automatic human handoff with fallback intent
      • Tutorial 4 - Explicit Human handoff with user intent
      • Tutorial 5 - Gracefully handling operating hours during handoff
      • Generate Dialogflow Google Credentials file
    • Rasa tutorials
      • Rasa Tutorial 1 - Rasa as external chatbot
  • Resolution bot
    • Introduction
    • Quickstart
    • Webhook service
    • Rich messages
    • Tutorials
      • Chatbot chooser (multilanguage)
      • Department chooser
      • Order info (webhook)
  • APIs
    • REST APIs
      • Introduction
      • Authentication
      • Requests
      • Leads
      • Messages
      • Activities
      • Projects
      • Team
      • User
      • Analytics
      • Canned responses
      • Tags
      • Events
      • Jwt
      • Labels
      • Images
      • Files
      • Segments
      • Chatbots
      • Knowledge Bases
        • Knowledge Base
        • Contents
        • Question & Answer
      • Management Api
        • Departments
        • Groups
    • NodeJS SDK
    • Webhooks
      • Subscriptions
    • Conversation Messages APIs tips
    • Realtime API
    • JWT Authentication
      • JWT Custom authentication Tutorial
    • Tutorials
      • REST API
        • Sending and receiving messages with Tiledesk APIs
        • PHP Tiledesk REST API example
        • Import multiple messages into Tiledesk using REST APIs from third party app
      • Webhooks
        • Custom Request assignment
        • Request transcript on close
  • Apps
    • Build Custom App - Quick start
    • External Channels integration flow diagram
    • Telegram integration tutorial
  • Dashboard & AgentChat SDK
    • Dashboard SDK
    • Agent Chat SDK
  • Architecture
    • Architecture overview
    • Components list
    • Bot Design diagram
    • Multi Channel Message Flow
  • Installation
    • Installation
    • Running Tiledesk using Docker Compose
    • Running Tiledesk with Kubernetes using Helm
    • Choosing Hardware
  • Configuration
    • Chat21 channel configuration
    • Email parameters and templates configuration
    • Configure the logging system
Powered by GitBook
On this page

Was this helpful?

  1. External Chatbot

Chatbot to Human handoff

Move a conversation to a human

PreviousHello World tutorialNextSend Text Buttons

Last updated 1 year ago

Was this helpful?

This article is about transfering a conversation from the initial chatbot to a human using Tiledesk external-chatbot technology. This feature is named chatbot to human handoff.

In this example, after the initial greeting message the chatbot proposes you to move to an agent. If you reply "yes" the handoff will occur.

image

You can handoff to human agents from any Tiledesk chatbot (native or external) simply sending the \agent text as the last line of any message. This message tells Tiledesk to remove the chatbot from the current conversation and invite a human in its place. As soon as Tiledesk sees this command in the text it will remove the current chatbot from the current conversation and will try to invite a human, following the current department rules. If no agents are available the conversation will wait in the “unassigned” queue from where it can be pulled by an agent as soon as one becomes available again.

Here follows the source code of index.js file in the example:

const express = require('express');
const bodyParser = require('body-parser');
const { TiledeskChatbotClient } = require('@tiledesk/tiledesk-chatbot-client');

const app = express();
app.use(bodyParser.json());

app.get('/', (req, res) => {
  res.send("Tiledesk External-Chatbot to Human handoff Tutorial");
});

app.post('/bot', (req, res) => {
  res.status(200).send({"success":true});
  const tdclient = 
    new TiledeskChatbotClient(
      {
        request: req,
        APIKEY: '__APIKEY__'
      });
  if (tdclient.text === "\\start") {
    tdclient.sendMessage({
      text: 'Cheers! Need operator?'
    });
  }
  else if (tdclient.text === "yes") {
    tdclient.sendMessage({text: 'Moving you to an operator...'}, (err) => {
      tdclient.sendMessage(
        {
          text: '\\agent',
          attributes: {
            subtype: 'info' // widget-hidden message
          }
        });
    });
  }
  else {
    tdclient.sendMessage({text: 'Not trained for this'});
  }
});

app.listen(3000, () => {
  console.log('server started');
});

Just note that if you send the '\agent' command it will be visible to the end-user in the Widget. If you want to hide this command-message you must send it as an "info" message. Info messages are always hidden from the end-user conversation.

In the example you see the code sending a first message to indicate the start of the "Agent switching" operation ('Moving you to an operator...'). As soon as this message is sent we send the handoff command ('\agent') as hidden (attributes.subtype = 'info'). This message will start the handoff operation.

Do you have suggestions on this article? Please send us your feedback writing an email to info@tiledesk.com

We wrote a full Node.js that you can fork or copy.

image
repl.it example