我是使用Dialogflow的新手。我在nodejs中有一个webhook,当他们要求提供信息时会向用户发送响应。如果用户使用电报,脸谱,线路,我想发送不同的响应...现在我总是发送相同的信息。 这是我的webhook:
"use strict";
const express = require("express");
const bodyParser = require("body-parser");
const restService = express();
restService.use(
bodyParser.urlencoded({
extended: true
})
);
restService.use(bodyParser.json());
restService.post("/webhook", function(req, res) {
var speech =
req.body.result &&
req.body.result.parameters &&
req.body.result.parameters.tipo
? response(req.body.result.parameters.tipo.toLowerCase())
: "Ups... ha habido algún problema con nuestra comunicación, sorry!";
return res.json({
speech: speech,
displayText: speech,
source: "webhook-echo-sample"
});
});
let response = function(tipo){
let response;
switch(tipo){
case 'daw': response = 'http://moodle.iesgrancapitan.org/course/index.php?categoryid=7'; break;
case 'asir': response = 'http://moodle.iesgrancapitan.org/course/index.php?categoryid=4'; break;
default: response = 'Vaya... Creo que algo fue mal'; break;
}
return response;
}
restService.listen(process.env.PORT || 8000, function() {
console.log("Server up and listening");
});
答案 0 :(得分:2)
有两种方法可以添加特定于平台的响应:
{
"fulfillmentText": "This is a text response",
"fulfillmentMessages": [
{
"card": {
"title": "card title",
"subtitle": "card text",
"imageUri": "https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png",
"buttons": [
{
"text": "button text",
"postback": "https://assistant.google.com/"
}
]
}
}
],
"source": "example.com",
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "this is a simple response"
}
}
]
}
},
"facebook": {
"text": "Hello, Facebook!"
},
"slack": {
"text": "This is a text response for Slack."
}
},
"outputContexts": [
{
"name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/context name",
"lifespanCount": 5,
"parameters": {
"param": "param value"
}
}
],
"followupEventInput": {
"name": "event name",
"languageCode": "en-US",
"parameters": {
"param": "param value"
}
}