简体   繁体   English

从node.js中的webhook发送不同的响应(Dialogflow)

[英]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: 有两种添加平台特定响应的方法:

  1. At your intent, scroll all the way down to responses. 根据您的意图,一直向下滚动到响应。 Next to the default, there's a plus button where you can select for which platform you want to add rich messages. 在默认值旁边,有一个加号按钮,您可以在其中选择要向其添加丰富消息的平台。 If you then go to the 'Add responses' you can select from the drop down menu what your rich response should have (madia, suggestion chips etc) and then add there all the information required. 如果您随后转到“添加回复”,则可以从下拉菜单中选择您的丰富回复应具有的内容(母题,建议筹码等),然后在其中添加所有所需信息。
  2. From your fulfillment, by adding a custom payload. 根据您的需要,添加自定义有效负载。 I've attached the snippet below, but for more information you can visit this link https://dialogflow.com/docs/fulfillment . 我已附上以下代码段,但有关更多信息,您可以访问此链接https://dialogflow.com/docs/fulfillment And of course, don't forget to enable the fulfillment for that intent :) 当然,不要忘了为此目的实现:)

 { "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.

相关问题 从 nodejs webhook 发送响应表单对话流的正确方法是什么? - What is the proper way to send a response form dialogflow from nodejs webhook? 我在 Dialogflow 上的 webhook 没有响应 - No response from my webhook on Dialogflow 如何通过dialogflow将其他参数从nodejs客户端传递到webhook? - How to pass additional parameters from the nodejs client to webhook via dialogflow? 格式错误的响应:从 dialogflow Web 挂钩获取响应时出现 Webhook 错误 - Malformed Ressponse: Webhook error on getting response from dialogflow web hook Dialogflow:从 webhook 调用第三方 api 并等待响应 - Dialogflow: Call third party api from webhook and wait for response 可以在不从Dialogflow而是从服务器本身调用webhook的情况下,将上下文数据发送到dialogflow - Possibility to send context data to dialogflow without webhook being called from Dialogflow, but from server itself 在 Dialogflow Nodejs 中发送图像 - Send Image in Dialogflow Nodejs 如何使用 nodejs 在 Dialogflow 中处理 webhook 实现 - How to handle webhook fulfillment in Dialogflow using nodejs 无法将响应发送到dialogflow - Unable to send response to dialogflow 将参数发送到 dialogflow sdk v2 上的 webhook - Send parameters to webhook on dialogflow sdk v2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM