如何在Dialogflow完整功能上唯一地标识用户?

时间:2018-08-20 13:27:52

标签: dialogflow actions-on-google voice-recognition

我需要通过 Dialogflow Fulfillment 向我的Web服务发送一个唯一的标识符,以便我识别谁在发出请求。 为此,我需要唯一地标识Dialogflow实现上的用户,但是我找不到在 Inline Editor 内部获取令牌或类似令牌的方法,以便可以标识正在制作令牌的设备。请求。

我试图查看agent变量内有什​​么。 但是我发现没有什么可用来识别向我的Web服务发出请求的用户。

我还尝试获取userStorage,就像在How to identify unique users with Diagflow上看到的那样,但是它返回了以下错误:

Cannot read property 'userStorage' of undefined
    at verificarBiologia (/user_code/index.js:37:76)
    at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:273:44)
    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:52:9)
    at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
    at /var/tmp/worker/worker.js:686:7
    at /var/tmp/worker/worker.js:670:9
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)

可能是因为变量user未定义。

这是我的代码:

// 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');

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

  function verificarBiologia(agent) {

    agent.add('Inicio do metodo');

    console.log('Build 059');

    console.log(agent);

    let payload = request.body.originalDetectIntentRequest.payload;
    console.log(payload);


    let userStorage = request.body.originalDetectIntentRequest.payload.user.userStorage || JSON.stringify({});
    let userId;
    console.log("userStorage", userStorage);
    userStorage = JSON.parse(userStorage);
    console.log("userStorage_after_parsing", userStorage);


    agent.add('Final do metodo');
  }

  // 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('VerificarBiologia', verificarBiologia);
  agent.handleRequest(intentMap);
});

编辑

请求正文如下:

{
   "responseId":"f4ce5ff7-ac5f-4fec-b5bd-4e5007e4c2de",
   "queryResult":{
      "queryText":"Quando tenho prova de biologia?",
      "parameters":{
         "disciplinaBiologia":"biologia"
      },
      "allRequiredParamsPresent":true,
      "fulfillmentText":"Voc� tem uma prova de biologia no dia 30. Tire suas d�vidas com o professor.",
      "fulfillmentMessages":[
         {
            "text":{
               "text":[
                  "Voc� tem uma prova de biologia no dia 30. N�o deixe de fazer os exerc�cios."
               ]
            }
         }
      ],
      "intent":{
         "name":"projects/verificadorprovas/agent/intents/020017a0-e3a9-46f0-9a2e-d93009f5ac42",
         "displayName":"VerificarBiologia"
      },
      "intentDetectionConfidence":1,
      "languageCode":"en"
   },
   "originalDetectIntentRequest":{
      "payload":{

      }
   },
   "session":"projects/verificadorprovas/agent/sessions/3700fddf-3572-4221-fffc-a0dc1bf28330"
}

有人可以帮我吗?我该怎么做才能获得可以用来识别用户的信息?

预先感谢

2 个答案:

答案 0 :(得分:1)

在Dialogflow模拟器中使用“立即尝试”进行测试不会模拟Google环境下的操作。为此,您需要使用Google Simulator上的操作,只需单击几行即可单击“查看其在Google Assistant中的工作方式”。

enter image description here

答案 1 :(得分:0)

如果您打算通过Google上的“操作”使用Google Assistant,那么识别用户的最佳方法是使用“帐户关联”。有关获取Google Assistant用户信息的更多信息,请查看以下link