Showing
1 changed file
with
65 additions
and
5 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | -var cfr = require('./cfr_module.js'); | 2 | +var client_id = 'v3M4wjolGLkrvNA3GUIW'; |
3 | +var client_secret = 'fKF6vjkWhE'; | ||
3 | const request = require('request'); | 4 | const request = require('request'); |
4 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 5 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
5 | const TOKEN = 'w5i8sURqF5bof6DWeB87n+oCeWrYaFf7a5YZzfzN1jeITIlZ3PcOmZRcdGCo/djTuHhNxybfJ69y7Jex+7tipBNRynngfyWX9CK1L3EupuhnX8rubeCmJda7HvsQWXVo8ZDcwl2aLwXsE3kiYF2qEwdB04t89/1O/w1cDnyilFU=' | 6 | const TOKEN = 'w5i8sURqF5bof6DWeB87n+oCeWrYaFf7a5YZzfzN1jeITIlZ3PcOmZRcdGCo/djTuHhNxybfJ69y7Jex+7tipBNRynngfyWX9CK1L3EupuhnX8rubeCmJda7HvsQWXVo8ZDcwl2aLwXsE3kiYF2qEwdB04t89/1O/w1cDnyilFU=' |
... | @@ -18,6 +19,9 @@ app.use(bodyParser.json()); | ... | @@ -18,6 +19,9 @@ app.use(bodyParser.json()); |
18 | 19 | ||
19 | var usingMessage = '' | 20 | var usingMessage = '' |
20 | var content_id = '' | 21 | var content_id = '' |
22 | +var imgDownloaded = false; | ||
23 | +var downloadedImg = '' | ||
24 | + | ||
21 | app.post('/hook', function (req, res) { | 25 | app.post('/hook', function (req, res) { |
22 | 26 | ||
23 | var eventObj = req.body.events[0]; | 27 | var eventObj = req.body.events[0]; |
... | @@ -57,14 +61,19 @@ app.post('/hook', function (req, res) { | ... | @@ -57,14 +61,19 @@ app.post('/hook', function (req, res) { |
57 | } | 61 | } |
58 | } else if (eventObj.message.type == 'image') { | 62 | } else if (eventObj.message.type == 'image') { |
59 | content_id = eventObj.message.id; | 63 | content_id = eventObj.message.id; |
60 | - const downloadPath = path.join(__dirname, `${content_id}.jpg`); | 64 | + const downloadPath = path.join(__dirname, 'sample.jpg'); |
61 | downloadContent(content_id, downloadPath); | 65 | downloadContent(content_id, downloadPath); |
62 | - | 66 | + //downloadedImg = content_id; |
67 | + //imgDownloaded = true; | ||
68 | + Checking(eventObj.replyToken); | ||
69 | + res.sendStatus(200); | ||
70 | + } else if (text == '계속 진행') { | ||
63 | //사진으로 얼굴 인식해주는 함수 | 71 | //사진으로 얼굴 인식해주는 함수 |
64 | - cfr.imgtodata('./test2.jpg'); | 72 | + imgtodata('sample.jpg'); |
65 | SendingLocation(eventObj.replyToken); | 73 | SendingLocation(eventObj.replyToken); |
66 | res.sendStatus(200); | 74 | res.sendStatus(200); |
67 | - } else { | 75 | + } |
76 | + else { | ||
68 | usingMessage = text; | 77 | usingMessage = text; |
69 | initReply(eventObj.replyToken); | 78 | initReply(eventObj.replyToken); |
70 | res.sendStatus(200); | 79 | res.sendStatus(200); |
... | @@ -258,6 +267,29 @@ function QuickReplyCfrNo (replyToken) { | ... | @@ -258,6 +267,29 @@ function QuickReplyCfrNo (replyToken) { |
258 | }); | 267 | }); |
259 | } | 268 | } |
260 | 269 | ||
270 | +function Checking (replyToken) { | ||
271 | + request.post( | ||
272 | + { | ||
273 | + url: TARGET_URL, | ||
274 | + headers: { | ||
275 | + 'Authorization': `Bearer ${TOKEN}` | ||
276 | + }, | ||
277 | + json: { | ||
278 | + "replyToken": replyToken, | ||
279 | + "messages": [ | ||
280 | + { | ||
281 | + "type": "text", | ||
282 | + "label": "계속 진행", | ||
283 | + "text": "계속 진행하시려면 '계속 진행'을 입력해주세요." | ||
284 | + }, | ||
285 | + ], | ||
286 | + } | ||
287 | + },(error, response, body) => { | ||
288 | + console.log(body) | ||
289 | + }); | ||
290 | +} | ||
291 | + | ||
292 | +//추천 결과 | ||
261 | function RecommendationResult(replyToken) { | 293 | function RecommendationResult(replyToken) { |
262 | request.post( | 294 | request.post( |
263 | { | 295 | { |
... | @@ -301,6 +333,34 @@ function RecommendationResult(replyToken) { | ... | @@ -301,6 +333,34 @@ function RecommendationResult(replyToken) { |
301 | }); | 333 | }); |
302 | } | 334 | } |
303 | 335 | ||
336 | +imgtodata = function(dir){ | ||
337 | + var api_url = 'https://openapi.naver.com/v1/vision/face'; // 얼굴 감지 | ||
338 | + | ||
339 | + var _formData = { | ||
340 | + image:'image', | ||
341 | + image: fs.createReadStream(path.join(__dirname, dir)) // FILE 이름 | ||
342 | + }; | ||
343 | + | ||
344 | + request.post( | ||
345 | + { url:api_url, | ||
346 | + formData:_formData, | ||
347 | + headers: {'X-Naver-Client-Id':client_id, | ||
348 | + 'X-Naver-Client-Secret': client_secret} | ||
349 | + }, (err,response,body) =>{ | ||
350 | + console.log(response.statusCode); // 200 | ||
351 | + //console.log(response.headers['content-type']) | ||
352 | + | ||
353 | + data=JSON.parse(body); | ||
354 | + gender=data.faces[0].gender.value; | ||
355 | + emotion=data.faces[0].emotion.value | ||
356 | + | ||
357 | + console.log(gender); | ||
358 | + console.log(emotion); | ||
359 | + | ||
360 | + //return {gender:gender,emotion:emotion}; | ||
361 | + }); | ||
362 | + } | ||
363 | + | ||
304 | //사용자가 보낸 사진 저장 | 364 | //사용자가 보낸 사진 저장 |
305 | const config = ({ | 365 | const config = ({ |
306 | channelAccessToken: `${TOKEN}`, | 366 | channelAccessToken: `${TOKEN}`, | ... | ... |
-
Please register or login to post a comment