简体   繁体   English

获取意图,实体,上下文和所有数据

[英]Get intents, entities, contexts and all data

In the case, the actually conversation-simple have one function with all the values, but the function update every time if flows conversation. 在这种情况下,实际上很简单的对话具有一个具有所有值的函数,但是如果每次进行对话,该函数都会更新。

I want create one function or other form to be able to capture all that data that is currently on the data. 我想创建一个函数或其他形式来捕获当前数据中的所有数据。

In the case have Intents, context, entities, etc. 在这种情况下,有意图,上下文,实体等。

conversation.message(payload, function(err, data) {
    if (err) {
      return res.status(err.code || 500).json(err);
    }
    return res.json(updateMessage(payload, data));
  });
});

The data inside updateMessage parameter have all I need, but if I create other function and try get this values, does not work. updateMessage参数中的数据具有我所需要的全部,但是如果我创建其他函数并尝试获取此值,则无法使用。

In the case I use the values and get with app.js for open some REST webservice. 在这种情况下,我使用这些值并使用app.js来打开一些REST Web服务。 I try it: 我尝试一下:

function login (req, res) {    
      numberOrigin = null;
      sessionid = null;

      var dataLogin = {
        data:  { "userName":"xxxxx","password":"xxxxx","platform":"MyPlatform" },
        headers: { "Content-Type": "application/json" }
      };

      client.registerMethod("postMethod", "xxxxxxxxxxxxxxx/services/login", "POST");        
      client.methods.postMethod(dataLogin, function (data, response) {

        if(Buffer.isBuffer(data)){
          data = data.toString('utf8');
          console.log(data);
          var re = /(sessionID: )([^,}]*)/g;
          var match = re.exec(data);
          var sessionid = match[2]
          console.log(sessionid);              
        }
      });
    }

    function openRequest(data, sessionid, numberOrigin ){
      //console.log(data); dont show the values.. show the data response of login
         var dataRequest = {
         data: {"sessionID": sessionid,
                "synchronize":false,
        "sourceRequest":{
             "numberOrigin":numberOrigin,
             "description": JSON.stringify(data.context.email) } },
         headers: { "Content-Type": "application/json" }
         };

         numberOrigin +=1;
         client.post("xxxxxxxxxxxxxxxxxx/services/request/create", dataRequest, function (data, response) {         
          if(Buffer.isBuffer(data)){
          data = data.toString('utf8');    
          console.log(data);          
          }
        });
      }

    function updateMessage(res, input, data, numberOrigin) {
      var email = data.context.email;  // this recognize but this function is responsible for other thing        
       if (email === 'xxxxxxxxxxxx@test.com') {
        console.log(data);
        login(data);
        openRequest(data, sessionid, numberOrigin)
       }
     }

In case, I just want get the values with my app.js for use inside REST. 以防万一,我只想通过我的app.js get值以在REST中使用。 I got it with ajax but everything on the client side (index.html), and that made me show my credentials, so I decided to do it in REST for security my code.. If have some form to solved this, please let me know. 我使用ajax它,但是客户端上的所有内容(index.html)都使我显示了我的凭据,因此为了安全起见,我决定在REST中执行我的代码。如果有某种形式可以解决此问题,请让我知道。 If have other form to do it, I'll be happy to know. 如果可以采用其他形式,我将很高兴知道。

Thanks advance. 谢谢前进。

The issue is likely that you need to write to the response object res .. In the updateMessage function the response is passed in. In order for data to be sent back to the browser you need to write to the response. 问题可能是您需要写入响应对象res ..在updateMessage函数中传递响应。为了将数据发送回浏览器,您需要写入响应。 I have a demo app which calls the weather channel to get the weather based on an intent, similar to what you are trying to do with your login function. 我有一个演示应用程序,该应用程序调用天气频道以根据意图获取天气,类似于您尝试使用登录功能执行的操作。 Please take a look at this code https://github.com/doconnor78/conversation-simple-weather/blob/master/app.js#L130 请看一下这段代码https://github.com/doconnor78/conversation-simple-weather/blob/master/app.js#L130

You will need to pass the original res (response) object into the appropriate function and then write data to the response (res) once you get it from the third party service. 您需要将原始res(响应)对象传递到适当的函数中,然后从第三方服务获得响应后将数据写入响应(res)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM