Dialogflow和Google Action MediaObject集成

时间:2018-06-21 05:09:42

标签: node.js actions-on-google dialogflow

我尝试使用googleaction和dialogflow集成mp3音频文件。我使用了来自GitHub clikhere的代码。

由于github代码未运行,我做了一些更改,还添加了“ agent.add(conv);”。在yourFunctionHandler函数中,代码仍未执行。

'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const {
  dialogflow,
  BasicCard,
  BrowseCarousel,
  BrowseCarouselItem,
  Button,
  Carousel,
  LinkOutSuggestion,
  List,
  MediaObject,
  Suggestions,
  SimpleResponse,
 } = require('actions-on-google');

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 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?`);
  }

  // // Uncomment and edit to make your own intent handler
  // // uncomment `intentMap.set('your intent name here', yourFunctionHandler);`
  // // below to get this function to be run when a Dialogflow intent is matched
  function yourFunctionHandler(agent) {
    let conv = agent.conv();
    conv.ask(new SimpleResponse("Here is a funky Jazz tune"));
    conv.ask(new Suggestions(['suggestion 1', 'suggestion 2']));
    conv.close(new MediaObject({
      name: 'Jazz in Paris',
      url: 'https://storage.googleapis.com/automotive-media/Jazz_In_Paris.mp3',
      description: 'A funky Jazz tune',
      icon: new Image({
        url: 'https://storage.googleapis.com/automotive-media/album_art.jpg',
        alt: 'Media icon',
      }),
    }));
    agent.add(conv);

  }

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
   intentMap.set('PlaySongIntents', yourFunctionHandler);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);
});

但是当我使用模拟器执行这项技能时,我遇到了一些错误

{
  "conversationToken": "[]",
  "expectUserResponse": true,
  "expectedInputs": [
    {
      "inputPrompt": {
        "richInitialPrompt": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Your Song is"
              }
            }
          ]
        }
      },
      "possibleIntents": [
        {
          "intent": "assistant.intent.action.TEXT"
        }
      ],
      "speechBiasingHints": [
        "$songname"
      ]
    }
  ],
  "responseMetadata": {
    "status": {
      "code": 14,
      "message": "Webhook error (206)"
    },
    "queryMatchInfo": {
      "queryMatched": true,
      "intent": "b5ae2471-fd76-42d8-8e29-5d1da63a0f38"
    }
  }
}

在查看错误日志中,我看到了以下错误

{
 insertId: "6y7ymjfizlquj"  
 labels: {
  channel: "preview"   
  querystream: "GOOGLE_USER"   
  source: "AOG_REQUEST_RESPONSE"   
 }
 logName: "projects/chuchutest-c2676/logs/actions.googleapis.com%2Factions"  
 receiveTimestamp: "2018-06-21T04:45:04.334924839Z"  
 resource: {
  labels: {
   action_id: "actions.intent.TEXT"    
   project_id: "chuchutest-c2676"    
   version_id: ""    
  }
  type: "assistant_action"   
 }
 severity: "ERROR"  
 textPayload: "Error in fulfillment status received from app endpoint. See ResponseMetadata in the response. Status code: 14. Error message: Webhook error (206)"  
 timestamp: "2018-06-21T04:45:04.294989129Z"  
 trace: "projects/432198826560/traces/1529556292737"  
}

0 个答案:

没有答案