如何在 Dialogflow Messenger 上使用建议芯片等丰富的响应消息?

How to use rich response messages like suggestion chips on Dialogflow messenger?

大家好,我使用 webhook 作为后端,使用 Dialogflow 作为前端 我在节点 js 中使用 Dialogflow-fulfillment 库 我知道如何使用丰富的响应消息,例如使用 Dialogflow 前端的按钮,但我该如何使用它从 webhook 代码可能使用一些 JSON?我想使用建议芯片 目前,我知道如何使用卡片,请参阅下面的代码,现在我想使用建议芯片响应,该怎么做?

//agent.add(new Card({
    //title: `RDF Graph Visualization`,
     //buttonText: 'open website',
     //buttonUrl: 'https://xxherokuapp.com/visualize/' + graphId
       //})
    // )    

我已经尝试使用 Fulfillment 作为 Webhook 的以下代码,并在 Dialogflow Messenger 上对其进行了测试。响应包含带链接的建议信息片。

Index.js :

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';
exports.myfunction = 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 welcome(agent) {
   agent.add(`Welcome to my agent!`);
 }
 function fallback(agent) {
   agent.add(`I didn't understand`);
   agent.add(`I'm sorry, can you try again?`);
 }
 
 function pet(agent){
   agent.add(`which one u want`);
   const payload = {
    
     "richContent":[
       [
         {
           "type":"chips",
           "options":[
             {
               "text":"Dog",
               "link" : "https://en.wikipedia.org/wiki/Dog"
             },
             {
               "text":"Cat",
               "link":"https://en.wikipedia.org/wiki/Cat"
             },
             {
             "text":"Rabbit",
             "link" : "https://en.wikipedia.org/wiki/Rabbit"
             }
           ]
         }
       ]
     ]
    
   };
   agent.add(new Payload(agent.UNSPECIFIED, payload, {rawPayload: true, sendAsMessage: true}));
 }
  let intentMap = new Map();
 intentMap.set('Default Welcome Intent', welcome);
 intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('mypet',pet);
  agent.handleRequest(intentMap);
});

Package.json :

 "name": "myfunction",
 "description": "This is the webhook",
 "version": "0.0.1",
 "private": true,
 "license": "Apache Version 2.0",
 "author": "Google Inc.",
 "engines": {
   "node": "10"
 },
  "dependencies": {
   "actions-on-google": "^2.2.0",
   "firebase-admin": "^5.13.1",
   "firebase-functions": "^2.0.2",
   "dialogflow": "^0.6.0",
   "dialogflow-fulfillment": "^0.6.1"
 }
}

输出: document.

中提供了有关将建议卡与 Dialogflow Messenger 结合使用的更多信息