agent.add(conv)在dialogflow-fulfillment-library中不起作用?

时间:2018-10-09 18:19:53

标签: dialogflow actions-on-google

我正在使用dialogflow-fulfillment的0.5.0版本。

这是测试功能

function test(agent){
   let conv = agent.conv();
   conv.ask("HEY");
   agent.add(conv);  // line 54
}

在Google模拟器上测试操作时遇到的错误

TypeError: Cannot read property 'forEach' of undefined
    at V2Agent.addActionsOnGoogle_ (/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:334:28)
    at WebhookClient.addResponse_ (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:279:19)
    at WebhookClient.add (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:254:12)
    at test (/user_code/index.js:54:18)
    at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:1692:9)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
    at /var/tmp/worker/worker.js:689:7
    at /var/tmp/worker/worker.js:673:9
    at _combinedTickCallback (internal/process/next_tick.js:73:7

这是完整的代码

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(agent){
    let conv = agent.conv();
    conv.ask("HEY");
    return agent.add(conv);
}

let intentMap = new Map();
intentMap.set('test', test);

 agent.handleRequest(intentMap);

});

记录说Dialogflow请求正文的行

{
  "responseId": "d9d451ce-98e1-4602-9a6f-d01b0d958ff6",
  "queryResult": {
    "queryText": "test",
    "parameters": {},
    "allRequiredParamsPresent": true,
    "fulfillmentMessages": [
      {
        "text": {
          "text": [
            ""
          ]
        }
      }
    ],
    "outputContexts": [
      {
        "name": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA/contexts/actions_capability_screen_output"
      },
      {
        "name": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA/contexts/actions_capability_audio_output"
      },
      {
        "name": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA/contexts/google_assistant_input_type_keyboard"
      },
      {
        "name": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA/contexts/actions_capability_web_browser"
      },
      {
        "name": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA/contexts/actions_capability_media_response_audio"
      }
    ],
    "intent": {
      "name": "projects/test-agent-51539/agent/intents/9916fb2f-20c2-435e-bba1-3b4c381c6188",
      "displayName": "test"
    },
    "intentDetectionConfidence": 1,
    "languageCode": "en-us"
  },
  "originalDetectIntentRequest": {
    "source": "google",
    "version": "2",
    "payload": {
      "isInSandbox": true,
      "surface": {
        "capabilities": [
          {
            "name": "actions.capability.SCREEN_OUTPUT"
          },
          {
            "name": "actions.capability.AUDIO_OUTPUT"
          },
          {
            "name": "actions.capability.WEB_BROWSER"
          },
          {
            "name": "actions.capability.MEDIA_RESPONSE_AUDIO"
          }
        ]
      },
      "requestType": "SIMULATOR",
      "inputs": [
        {
          "rawInputs": [
            {
              "query": "test",
              "inputType": "KEYBOARD"
            }
          ],
          "arguments": [
            {
              "rawText": "test",
              "textValue": "test",
              "name": "text"
            }
          ],
          "intent": "actions.intent.TEXT"
        }
      ],
      "user": {
        "userStorage": "{\"data\":{\"hotel\":1,\"room\":201}}",
        "lastSeen": "2018-10-09T18:40:23Z",
        "locale": "en-US",
        "userId": "ABwppHFwiyaj7VK3lnGpv8MrtJUkaa5e6WDNIQ0MogRWRzH_CgDM5ZFDbgTkmBhH7lDjAfO-iZTjgIWNlmBncQ"
      },
      "conversation": {
        "conversationId": "ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA",
        "type": "ACTIVE",
        "conversationToken": "[]"
      },
      "availableSurfaces": [
        {
          "capabilities": [
            {
              "name": "actions.capability.SCREEN_OUTPUT"
            },
            {
              "name": "actions.capability.AUDIO_OUTPUT"
            },
            {
              "name": "actions.capability.WEB_BROWSER"
            }
          ]
        }
      ]
    }
  },
  "session": "projects/test-agent-51539/agent/sessions/ABwppHFfSX2ZtvQuN9m5qt5CpY3awhl5OXnfZcJ0vmroCTrgQ_KRkmxkDTNsFATkB8fE3WNjt2JqaYM_4qSbfA"
}

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,将packages.json中的依赖项更新为以下解决了该问题:

"actions-on-google": "^2.5.0",
"dialogflow-fulfillment": "^0.6.1"

答案 1 :(得分:0)

将conv作为默认会话变量,请尝试使用其他变量