[英]Send different response from webhook in nodejs (Dialogflow)
I'm new using Dialogflow. 我是使用Dialogflow的新手。 I have a webhook in nodejs which send a response to users when they ask for information, I would like to send a different response if the users are using telegram, facebook, line... by now I always send the same. 我在nodejs中有一个网络挂钩,当用户要求提供信息时,它会向用户发送响应,如果用户使用电报,facebook,线路...,我想发送不同的响应。到目前为止,我总是发送相同的信息。 This is my 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");
});
There are 2 ways to add a platform specific response: 有两种添加平台特定响应的方法:
{ "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" } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.