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
  • Fork the tutorial code
  • Introduction
  • Enable Agent fulfillment
  • Re-train the 'talk to agent' intent to use fulfillment

Was this helpful?

  1. External Chatbot
  2. Advanced Tutorials

Tutorial 5 - Gracefully handling operating hours during handoff

Gracefully handling operating hours in bot-to-humans handoff

PreviousTutorial 4 - Explicit Human handoff with user intentNextGenerate Dialogflow Google Credentials file

Last updated 1 year ago

Was this helpful?

NOTE: this tutorial uses Dialogflow just as an example for a programmatic external chatbot integration. If you instead need to easily embed your Dialogflow Agent in your conversations, please use the Tiledesk , the out-of-the-box Dialogflow integration that doesn't require programming skills.

Fork the tutorial code

We'll start from , just adding a small library to our original endpoint.

You must use the code in Tutorial 1. The code is available on Github .

Fork the tutorial code using the Fork button. Now you have a copy of the tutorial on your own repo.

Introduction

What happens if, while you switch to the human operator, your support team is outside of operating hours? The request will be placed in the unserved queue and will became served as soon as your team became available again. Meanwhile you should notice to the user that the request will be taken in some hours, or probably the day after. So, telling "I'm putting you in touch with an operator" is not enough.

How can you write an handoff message that depends by operating hours? You can mix Dialogflow messages fulfillment and Tiledesk APIs to reach your goal.

Enable Agent fulfillment

Open Dialogflow dashboard on your agent, the in the menu fulfillment option enable "Webhook" option. In the URL field insert your heroku app url where you pubblished your app followed by /dfwebhook and your project_id:

This "webhook" endpoint is already provided in the script.

// Tutorial 4.1 - Webhook for Bot-to-Agent handoff message based on opening hours
app.post('/dfwebhook/:project_id', (req, res) => {
  const fulfillmentText = req.body.queryResult.fulfillmentText
  console.log("fulfillmentText:", fulfillmentText)
  const languageCode = req.body.queryResult.languageCode
  console.log("languageCode:", languageCode)
  // replace the following with your prject id
  const project_id = req.params.project_id
  const intent = req.body.queryResult.intent.displayName.toUpperCase()
  if (intent === "TALK TO AGENT") {
    if (resbody && resbody.token) {
      const tdclient = new TiledeskClient()
      tdclient.openNow(function(isopen) {
        var df_res = {}
        if (isopen) {
          df_res['fulfillmentText'] = "We are open! Switching to agent\\agent"
        }
        else {
          df_res['fulfillmentText'] = "I'm sorry but we are closed right now."
        }
        res.status(200).send(JSON.stringify(df_res));
      })
    }
  }
});

This endpoint uses a projeect_id in the webhook URL that you must have care to replace with your own.

Re-train the 'talk to agent' intent to use fulfillment

Fulfillment is not automatically actvive on the intents. You must activate it for each intent that you want to reply dynamically. We will re-train the 'talk to agent' intent to use our webhook to reply, instead of the static response.

Switch to the intent UI from Dialogflow dashboard, the go on the form bottom and switch to "on" the fulfillment button, as in the following picture:

Now go on your project in Tiledesk dashboard and activate operating hours, taking care to put offline the interval when you ask the bot to switch to human agents. If you will try to switch to human operators during offline hours you will get the following message:

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

Enjoy Tiledesk!

Dialogflow Connector
Dialogflow Tutorial 1
here