0

이 경우 실제 conversation-simple은 모든 값을 갖는 하나의 함수를 가지지 만 대화가 흐를 때마다 함수가 매번 업데이트됩니다.인 텐트, 엔티티, 컨텍스트 및 모든 데이터 얻기

현재 데이터에있는 모든 데이터를 캡처 할 수 있도록 하나의 함수 또는 다른 형식을 만들고 싶습니다. 경우

내가 다른 함수를 생성하고이 값을 가져하려고하면

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

updateMessage 매개 변수 내부의 데이터가 모든 필요를했지만, 작동하지 않습니다 등 텐트, 문맥, 엔티티를 보유하고 있습니다.

값을 사용하고 일부 REST 웹 서비스를 열기 위해 app.js로 가져 오는 경우. 나는 그것을 시도 :

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 === '[email protected]') { 
     console.log(data); 
     login(data); 
     openRequest(data, sessionid, numberOrigin) 
     } 
    } 

경우는, 그냥 REST 내부 사용에 대한 내 app.jsget 값을합니다. 나는 ajax으로 얻었지만 클라이언트 측 (index.html)의 모든 것을 가지고 내 자격 증명을 보여 주므로 내 코드를 보안을 위해 REST에서 결정했다. 이 문제를 해결할 수있는 양식이 있으면 나도 알아. 다른 양식을 작성해 주시면 기꺼이 알 수 있습니다.

감사합니다.

답변

3

응답 개체 res에 쓰기가 필요할 수 있습니다. updateMessage 함수에서 응답이 전달됩니다. 데이터를 브라우저로 다시 보내려면 응답에 쓰기가 필요합니다. 날씨 채널을 호출하여 로그인 기능을 사용하여 수행하려는 것과 비슷한 의도로 날씨를 가져 오는 데모 앱이 있습니다. 이 코드를 보시기 바랍니다 https://github.com/doconnor78/conversation-simple-weather/blob/master/app.js#L130

원본 res (응답) 개체를 적절한 함수에 전달한 다음 타사 서비스에서 가져온 데이터를 응답 (res)에 기록해야합니다.

+0

대단히 감사합니다. –