Skip to content

Instantly share code, notes, and snippets.

@tbass134 tbass134/getInfo.js
Last active May 25, 2019

Embed
What would you like to do?
Dialogflow webhook to transfer user to live agent
function getInfo(contexts) {
var product = contexts[contexts.length - 1]['parameters']['Product']
var state = contexts[contexts.length - 1]['parameters']['geo-state-us']
for (var i = 0; i < contexts.length; i++) {
var context = contexts[i]['parameters']
if (typeof context['Product'] != "undefined" && typeof context['geo-state-us'] != "undefined") {
return context
}
}
return null
}
app.post('/', function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Content-Type", "application/json");
console.log("req.body", JSON.stringify(req.body, null, 2));
var json = null
if (intent == "transfer - ask name - ask product - ask state") {
var contexts = req.body['queryResult']["outputContexts"]
var data = getInfo(contexts)
var text = "Great. I’m going to hand you over to a Customer Service Representative now."
var parameters = { "text": text }
var json = {
'followup_event_input': { name: 'transfer_event', 'language_code': 'en', "parameters": parameters },
"outputContexts": [
{
"name": req.body.session+"/contexts/setCRMData",
"parameters": data,
"lifespanCount": 5
}
]
}
return res.json(json)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.