首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google上的操作不起作用,但在对话流中起作用

google上的操作不起作用,但在对话流中起作用
EN

Stack Overflow用户
提问于 2018-11-20 20:09:49
回答 2查看 1.1K关注 0票数 1

我在谷歌和我的手机上测试我的动作技能时遇到了一个问题。它与对话流工作得很好,但当我在google的帮助下或在google网页上的操作中达到questions_ready函数定义的意图来测试它时,我有一个错误"'final_response‘必须被设置。“但是它可以在Dialogflow上工作,所以我不知道哪里出了问题。我在这里留下我的代码,希望你们中的一些人能帮助我!谢谢!

代码语言:javascript
复制
'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:*'; // enables lib debugging statements
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

// Variables
var procedure;
var procedure;
var finish = "Ok, thank you. We have finished the questions";
var status_questions = [
    {question: 'Ok, here is your first question. Please, could you tell me how do you feel on a scale from 1 to 10 ? Where 1 is very bad and 10 is very good'},
    {question: 'Your workload is very high, high, normal, low or very low?'},
    {question: 'Tell me what is your level of monotony on a scale from 1 to 10. Where 1 is very bad and 10 is very good'}];

var currentIndex = 0;
var currentQuestion = "";
var flag = 0;

var list_answers = [];
var list_index = [];
var list_timestamps = [];
var list_questions = [];
const dialogflowAgentRef = db.collection('dialogflow').doc();
//

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  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 manual(agent) {
    const problem = agent.parameters.manual_problems;
    if (problem == "DDoS problem"){
        procedure = `Ok! Let's see how to solve your `+ problem + `. Specify here the procedure to resolve DDoS problem`;     
    }
    else {
        procedure = `Sorry, we don't have a manual to resolve that problem`;
    }

    agent.add((procedure));
  }

  function user_name(agent){
      const user = agent.parameters.names;
        return db.runTransaction(t => {
        t.set(dialogflowAgentRef, {name: user});
        return Promise.resolve('Write complete');
    }).then(doc => {
      agent.add(`Ok ${user}, are you ready?`);
    }).catch(err => {
      console.log(`Error writing to Firestore: ${err}`);
      agent.add(`Failed to write "${user}" to the Firestore database.`);
    });
  }

//WHEN IT IS CALLING THIS FUNCTION I GOT THE ERROR

  function questions_ready(agent) {
    if(currentIndex === 0){
        list_index=[];
        list_answers=[];
        list_questions=[];
        list_timestamps=[];
        list_index.push(currentIndex);
        currentQuestion = status_questions[currentIndex++].question;
    }
    else if(currentIndex >=1 && currentIndex <= 10){
        list_index.push(currentIndex);
        currentQuestion = status_questions[currentIndex++].question;
        flag = 1;
        const answParam = agent.parameters.answers;
        const ans = answParam;
        list_answers.push(ans);

    }
    else {
        currentIndex = 0;
        currentQuestion = finish;
        flag=0;
        const answParam = agent.parameters.answers;
        const ans = answParam;
        list_answers.push(ans);

        agent.add(currentQuestion);

        return db.runTransaction(t => {
        t.update(dialogflowAgentRef, {time: list_timestamps});
        t.update(dialogflowAgentRef, {index: list_index});
        t.update(dialogflowAgentRef, {question: list_questions});
        t.update(dialogflowAgentRef, {answer: list_answers});
        return Promise.resolve('Write complete');
    });
    }

    const ques = currentQuestion;
    list_questions.push(ques);

    var timestamp = Date.now();
    list_timestamps.push(timestamp);

    let ctx = {'name': 'projects/prueba-firebase-v1/agent/sessions/545ec712-8f69-6999-a50b-4127d38bce82/contexts/questions_ready', 'lifespan': 14, 
    'parameters': {'timestamp': list_timestamps, 'list_index': list_index, 'list_questions': list_questions, 'list_answers': list_answers}}; //, 'list_index': list_index
    agent.setContext(ctx);

    agent.add(currentQuestion);

  }

  // 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(enter code here'Manual', manual);
  intentMap.set('User_Name', user_name);
  intentMap.set('Questions_Ready', questions_ready);

  agent.handleRequest(intentMap);
}); 

我在Google上获得的关于操作的消息是:

-On模拟器显示: Prueba应用程序现在没有响应。请稍后重试。

-Errors:必须设置MalformedResponse 'final_response‘。

-Debug:

代码语言:javascript
复制
{
  "response": "Prueba application isn't responding right now. Try again soon.",
  "expectUserResponse": false,
  "conversationToken": "GidzaW11bG...",
  "audioResponse": "//NExAASWK...",
  "debugInfo": {
    "assistantToAgentDebug": {
      "curlCommand": "curl -v 'https://api.api.ai/api/integrations/google?token=6094e3dbd9e242679d0dcc603568b120&versionId=3' -H 'Content-Type: application/json;charset=UTF-8' -H 'Google-Actions-API-Version: 2' -H 'Authorization: eyJhbGciOiJSUzI1NiIsImtpZCI6ImQxZTg2OWU3YmY0MGRkYzNkM2RlMDgwNDI1OThiYTgzNTA5NzBmMGEiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhdWQiOiJjeWJlcm9wcy1maXJlYmFzZS12MSIsIm5iZiI6MTU0MjcxMTY5MCwiaWF0IjoxNTQyNzExOTkwLCJleHAiOjE1NDI3MTIxMTAsImp0aSI6Ijc5NWYyZTViZGRjNzk5ZDAxMTY2MDZhZmEyZjJiMDRlYjU3MDk4ZGQifQ.XNBl3DcL2Zhw9bXHvPG52U21ATIb52snsQ5YF9T57cf9HrEeau6XTPfbtALdkiTEqhRfcihQTwLu7wAMdvmqTeeDaRW3F8C2xDCitT2bjPryeDJ3eyoJvI2cTy5Vhf1oN3WwsHdlM0D59JYyNtTH1NE-B60bnLCPQNe7Mv23aUnipdo-LsAytF_d9Bpz93SR_WZITqP6-FpqHSSuUHL3qi8idqGNQrtFF6RQ5-AGKkLkqE-V_Sa2iLmpqDsi4fP3RYW0bajuSFrn74JvrziQKQR4ZaFc4ITjPtJlhboCTgJusOqpFvOYV_-LF5FqgswaiMqUtaX8YBW_EKLLMLoS2A'  -A 'Mozilla/5.0 (compatible; Google-Cloud-Functions/2.1; +http://www.google.com/bot.html)' -X POST -d '{\"user\":{\"userId\":\"ABwppHFD2VxLtzrmnMXp4XsxyE13Xc7mxOhaf7cbxMUQg7OEe_I1qRVlcDck8Rl-bESCZBPi3cHvESEbHYfvecHr59o\",\"locale\":\"en-US\",\"lastSeen\":\"2018-11-20T10:51:47Z\"},\"conversation\":{\"conversationId\":\"ABwppHH7q6m-4okbTf3aKCU-dgpEAoOmeCLle2AZjocfLI6i8BS1Lhqcx4InD3QBKboVr4yyTPcaOhAOMgQsaHIgHRU\",\"type\":\"ACTIVE\",\"conversationToken\":\"[]\"},\"inputs\":[{\"intent\":\"actions.intent.TEXT\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"yes\"}],\"arguments\":[{\"name\":\"text\",\"rawText\":\"yes\",\"textValue\":\"yes\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]}],\"requestType\":\"SIMULATOR\"}'",
      "assistantToAgentJson": "{\"user\":{\"userId\":\"ABwppHFD2VxLtzrmnMXp4XsxyE13Xc7mxOhaf7cbxMUQg7OEe_I1qRVlcDck8Rl-bESCZBPi3cHvESEbHYfvecHr59o\",\"locale\":\"en-US\",\"lastSeen\":\"2018-11-20T10:51:47Z\"},\"conversation\":{\"conversationId\":\"ABwppHH7q6m-4okbTf3aKCU-dgpEAoOmeCLle2AZjocfLI6i8BS1Lhqcx4InD3QBKboVr4yyTPcaOhAOMgQsaHIgHRU\",\"type\":\"ACTIVE\",\"conversationToken\":\"[]\"},\"inputs\":[{\"intent\":\"actions.intent.TEXT\",\"rawInputs\":[{\"inputType\":\"KEYBOARD\",\"query\":\"yes\"}],\"arguments\":[{\"name\":\"text\",\"rawText\":\"yes\",\"textValue\":\"yes\"}]}],\"surface\":{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.MEDIA_RESPONSE_AUDIO\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]},\"isInSandbox\":true,\"availableSurfaces\":[{\"capabilities\":[{\"name\":\"actions.capability.AUDIO_OUTPUT\"},{\"name\":\"actions.capability.WEB_BROWSER\"},{\"name\":\"actions.capability.SCREEN_OUTPUT\"}]}],\"requestType\":\"SIMULATOR\"}"
    },
    "agentToAssistantDebug": {
      "agentToAssistantJson": "{\n  \"responseMetadata\": {\n    \"status\": {\n      \"code\": 10,\n      \"message\": \"Failed to parse Dialogflow response into AppResponse because of empty speech response\",\n      \"details\": [{\n        \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n        \"value\": \"{\\\"id\\\":\\\"95a80a4d-4a98-461f-b183-88a358d87ebc\\\",\\\"timestamp\\\":\\\"2018-11-20T11:06:30.765Z\\\",\\\"lang\\\":\\\"en-us\\\",\\\"result\\\":{},\\\"alternateResult\\\":{},\\\"status\\\":{\\\"code\\\":206,\\\"errorType\\\":\\\"partial_content\\\",\\\"errorDetails\\\":\\\"Webhook call failed. Error: Webhook response was empty.\\\"},\\\"sessionId\\\":\\\"ABwppHH7q6m-4okbTf3aKCU-dgpEAoOmeCLle2AZjocfLI6i8BS1Lhqcx4InD3QBKboVr4yyTPcaOhAOMgQsaHIgHRU\\\"}\"\n      }]\n    }\n  }\n}"
    },
    "sharedDebugInfoList": [
      {
        "name": "ResponseValidation",
        "debugInfo": "",
        "subDebugEntryList": [
          {
            "name": "MalformedResponse",
            "debugInfo": "'final_response' must be set.",
            "subDebugEntryList": []
          }
        ]
      }
    ]
  },
  "visualResponse": {
    "visualElementsList": [
      {
        "displayText": {
          "content": "Prueba application isn't responding right now. Try again soon."
        }
      }
    ],
    "suggestionsList": [],
    "agentLogoUrl": ""
  },
  "clientError": 0,
  "is3pResponse": 1,
  "clientOperationList": []
}

这里有我的Questions_Ready意图和对话流建立的对话框中的图像,所有这些都可以完美地工作。问题是当我试图在Google上测试动作技能时

Questions_Ready Intent (I)

Questions_Ready Intent (II)

Answers Entities

Dialogflow dialog (I)

Dialogflow dialog (II)

Result obtained on Actions on Google

EN

回答 2

Stack Overflow用户

发布于 2018-11-21 02:33:50

在Debug json上:

debugInfo.agentToAssistantDebug.agentToAssistantJson:“由于语音响应为空,无法将对话流响应解析为AppResponse”

我们可以看到,Dialogflow没有返回Google上的操作能够理解的任何响应。Example response for AoG

因此,我的想法是webhook没有为Google上的操作返回正确的格式,这与Dialogflow不同。

这里有一个存储库,用于存储Google上的操作的响应示例:https://github.com/dialogflow/fulfillment-webhook-json/tree/master/responses/v2/ActionsOnGoogle/RichResponses

很抱歉,我不能对node.js代码提供进一步的帮助,我用另一种语言实现了webhooks,但是它们的json响应都是相同的。

票数 0
EN

Stack Overflow用户

发布于 2019-08-08 05:29:30

从您提供的代码示例中,您似乎一直在使用Dialogflow的实现库,而不是Google客户端库上的操作,您可以测试各种samples并查看Github上的依赖关系,以此sample为例。在使用Google Node.js库上的操作时,index.js文件将声明以下导入:

代码语言:javascript
复制
const {dialogflow} = require('actions-on-google');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53392719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档