Tutorial 6 - Fallback with search engine results

In this tutorial every time a fallback occurs te chatbot will propose a set of results from a knowledge base (i.e. Wikipedia)

Fork the tutorial code

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

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

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

Introduction

It's not easy to train a chatbot to address all questions the end-user can ask. But many times you or your Company already have some questions answered elsewhere in some Knowledge Base (i.e. your website, a FAQ database, an ECM/WCM etc.). What you can do to increase the user satisfaction

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") {
TiledeskClient.anonymousAuthentication(project_id, function(err, res, resbody) {
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 [email protected]

Enjoy Tiledesk!