Dialogflow:无法从嵌入式编辑器发送自定义有效载荷

时间:2020-09-22 06:11:32

标签: node.js dialogflow-es dialogflow-es-fulfillment

我正在尝试从内联编辑器发送自定义有效负载,以在DialogFlow Messenger集成中显示。这是我的代码:

 // See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {Payload} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
 
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

 function test_accordion  (agent) {
    const payload ={"messages": [{"richContent": [
                        [
                          {
                            "text": "Text to be displayed at accordion",
                            "type": "accordion",
                            "title": "Detalles:",
                            "image": {
                              "src": {
                                "rawUrl": "https://img2.freepng.es/20180621/ewt/kisspng-trello-logo-slack-atlassian-trello-5b2bcdc85e4d36.2783338815295973843863.jpg"
                              }
                            }
                          }
                        ]
                      ]
                    }]};

    agent.add(new Payload(agent.UNSPECIFIED , payload, {rawPayload: true, sendAsMessage: true}));
 }
  
  let intentMap = new Map();
  intentMap.set('test_accordion',  test_accordion);
  agent.handleRequest(intentMap);
});

这是我的包裹文件:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^6.0.0",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0",
    "@google-cloud/common":"^0.25.3",
    "@google-cloud/projectify":"^0.3.1",
    "@google-cloud/promisify":"^0.3.1",
    "@google-cloud/translate":"^2.1.2",
    "@google-cloud/firestore": "^0.16.1"
  }
}

我无法完成这项工作。我已经在网上搜索了几个小时,但找不到任何解决方案。 我还尝试了stackoverflow的一些解决方案,但是由于Dialogflow不断改变环境,它们似乎已经过时了。 任何帮助将不胜感激。

谢谢!

0 个答案:

没有答案