은승우

Update app.js

Showing 1 changed file with 2 additions and 6 deletions
1 +
1 var express = require("express"); 2 var express = require("express");
2 var app = express(); 3 var app = express();
3 const line = require('@line/bot-sdk'); 4 const line = require('@line/bot-sdk');
...@@ -56,12 +57,10 @@ const client = new line.Client(config); ...@@ -56,12 +57,10 @@ const client = new line.Client(config);
56 57
57 58
58 app.post('/webhook', line.middleware(config), (req, res) => { 59 app.post('/webhook', line.middleware(config), (req, res) => {
59 -console.log(res.statusCode);
60 Promise 60 Promise
61 .all(req.body.events.map(handleEvent)) 61 .all(req.body.events.map(handleEvent))
62 .then((result) => res.json(result)) 62 .then((result) => res.json(result))
63 .catch((err)=>{console.log(err); 63 .catch((err)=>{console.log(err);
64 - console.log(err.originalError.response)
65 }) 64 })
66 }); 65 });
67 // event handler 66 // event handler
...@@ -80,10 +79,8 @@ function handleEvent(event) { ...@@ -80,10 +79,8 @@ function handleEvent(event) {
80 }; 79 };
81 //papago 언어 감지 80 //papago 언어 감지
82 request.post(detect_options, (error,response,body)=>{ 81 request.post(detect_options, (error,response,body)=>{
83 -
84 if(!error && response.statusCode == 200){ 82 if(!error && response.statusCode == 200){
85 var detect_body = JSON.parse(response.body); 83 var detect_body = JSON.parse(response.body);
86 - console.log(detect_body);
87 var source = ''; 84 var source = '';
88 var target = ''; 85 var target = '';
89 var result = { type: 'text', text:''}; 86 var result = { type: 'text', text:''};
...@@ -103,7 +100,7 @@ function handleEvent(event) { ...@@ -103,7 +100,7 @@ function handleEvent(event) {
103 form: {'source':source, 'target':target, 'text':event.message.text}, 100 form: {'source':source, 'target':target, 'text':event.message.text},
104 headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret,"Content-Type": "application/x-www-form-urlencoded"} 101 headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret,"Content-Type": "application/x-www-form-urlencoded"}
105 }; 102 };
106 - 103 +
107 // Naver Post API 104 // Naver Post API
108 request.post(options, function(error, response, body){ 105 request.post(options, function(error, response, body){
109 // Translate API Sucess 106 // Translate API Sucess
...@@ -113,7 +110,6 @@ function handleEvent(event) { ...@@ -113,7 +110,6 @@ function handleEvent(event) {
113 // Message 잘 찍히는지 확인 110 // Message 잘 찍히는지 확인
114 111
115 result.text = objBody.message.result.translatedText; 112 result.text = objBody.message.result.translatedText;
116 - console.log("source: "+objBody);
117 console.log("result: "+result.text); 113 console.log("result: "+result.text);
118 //번역된 문장 보내기 114 //번역된 문장 보내기
119 client.replyMessage(event.replyToken,result).then(resolve).catch(reject); 115 client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
......