Showing
4 changed files
with
72 additions
and
77 deletions
| ... | @@ -11,7 +11,7 @@ | ... | @@ -11,7 +11,7 @@ |
| 11 | "skipFiles": [ | 11 | "skipFiles": [ |
| 12 | "<node_internals>/**" | 12 | "<node_internals>/**" |
| 13 | ], | 13 | ], |
| 14 | - "program": "${workspaceFolder}/playlistbyid.js" | 14 | + "program": "${workspaceFolder}/video_list_sad.js" |
| 15 | } | 15 | } |
| 16 | ] | 16 | ] |
| 17 | } | 17 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -14,9 +14,11 @@ const bodyParser = require('body-parser'); | ... | @@ -14,9 +14,11 @@ const bodyParser = require('body-parser'); |
| 14 | var app = express(); | 14 | var app = express(); |
| 15 | app.use(bodyParser.json()); | 15 | app.use(bodyParser.json()); |
| 16 | 16 | ||
| 17 | +// var { google } = require('googleapis'); | ||
| 18 | + | ||
| 17 | /// ---- | 19 | /// ---- |
| 18 | -var { google } = require('googleapis'); | 20 | +var sad = require('./video_sad'); |
| 19 | -/// ---- | 21 | + |
| 20 | 22 | ||
| 21 | app.post('/hook', function (req, res) { | 23 | app.post('/hook', function (req, res) { |
| 22 | 24 | ||
| ... | @@ -35,7 +37,6 @@ app.post('/hook', function (req, res) { | ... | @@ -35,7 +37,6 @@ app.post('/hook', function (req, res) { |
| 35 | 37 | ||
| 36 | res.sendStatus(200); | 38 | res.sendStatus(200); |
| 37 | }); | 39 | }); |
| 38 | - | ||
| 39 | function trans(replyToken, message) { | 40 | function trans(replyToken, message) { |
| 40 | 41 | ||
| 41 | request.post( | 42 | request.post( |
| ... | @@ -48,92 +49,29 @@ function trans(replyToken, message) { | ... | @@ -48,92 +49,29 @@ function trans(replyToken, message) { |
| 48 | 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | 49 | 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` |
| 49 | }, | 50 | }, |
| 50 | body: 'source=ko&target=en&text=' + message, | 51 | body: 'source=ko&target=en&text=' + message, |
| 51 | - json:true | 52 | + json: true |
| 52 | }, | 53 | }, |
| 53 | - | 54 | + |
| 54 | - (error, response, body) => { | 55 | + (error, response, body) => { |
| 55 | - if(!error && response.statusCode == 200) | 56 | + if (!error && response.statusCode == 200) { |
| 56 | - { | ||
| 57 | // message 가 사용자에게서 입력받은 메시지 내용입니다. sendMessage 는 보낼 메시지 내용입니다. | 57 | // message 가 사용자에게서 입력받은 메시지 내용입니다. sendMessage 는 보낼 메시지 내용입니다. |
| 58 | // 위에 PAPAGO API부분은 추후 API를 연동시킬 때 맞춰서 작성하기 쉽도록 템플릿을 남겨놓았습니다. 자세한 정보는 교수님 학습 자료의 experiment의 trans 폴더를 참고하세요. | 58 | // 위에 PAPAGO API부분은 추후 API를 연동시킬 때 맞춰서 작성하기 쉽도록 템플릿을 남겨놓았습니다. 자세한 정보는 교수님 학습 자료의 experiment의 trans 폴더를 참고하세요. |
| 59 | // (현재 코드에선 PAPAGO API의 작동 결과는 반영되지 않습니다.) | 59 | // (현재 코드에선 PAPAGO API의 작동 결과는 반영되지 않습니다.) |
| 60 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ | 60 | //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ |
| 61 | // var sendMessage; | 61 | // var sendMessage; |
| 62 | 62 | ||
| 63 | - // -------- | 63 | + // -------- |
| 64 | - if (message=="노래 추천해줘") | 64 | + if (message == "슬픈노래") { |
| 65 | - { | 65 | + sad.check(message,replyToken); |
| 66 | - var sendMessage = "아이유의 노래를 추천드립니다."; | ||
| 67 | - console.log(typeof(sendMessage)); | ||
| 68 | - console.log(sendMessage); | ||
| 69 | - | ||
| 70 | - } | ||
| 71 | - else | ||
| 72 | - { | ||
| 73 | - // var sendMessage = "무슨 말인지 못알아먹겠습니다"; | ||
| 74 | - | ||
| 75 | - // -------- | ||
| 76 | - var service = google.youtube('v3'); | ||
| 77 | - service.videos.list({ | ||
| 78 | - key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518', | ||
| 79 | - part: 'snippet,statistics', | ||
| 80 | - id: 'p5iu1V30myk', // 동영상 Id | ||
| 81 | - fields: 'items(snippet(title))' | ||
| 82 | - }, function(err, response) { | ||
| 83 | - if (err) { | ||
| 84 | - console.log('The API returned an error: ',err); | ||
| 85 | - return; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - var video = response.data.items; | ||
| 89 | - if(video.length ==0){ | ||
| 90 | - console.log('검색된 동영상이 없습니다.'); | ||
| 91 | - } else { | ||
| 92 | - // var sendMessage ="123"; | ||
| 93 | - // console.log(JSON.stringify(response.data.items[0].snippet.title));// 콘솔에 출력 | ||
| 94 | - // console.log(JSON.stringify(response.data.items[0].snippet));// 콘솔에 출력 | ||
| 95 | - // console.log(JSON.stringify(response.data.items[0]));// 콘솔에 출력 | ||
| 96 | - // console.log(JSON.stringify(response.data));// 콘솔에 출력 | ||
| 97 | - | ||
| 98 | 66 | ||
| 99 | - var sendMessage = JSON.stringify(response.data.items[0].snippet.title); | ||
| 100 | - // sendMessage = response.data.items[0].snippet.title; | ||
| 101 | - console.log(sendMessage); | ||
| 102 | - console.log(typeof (sendMessage)); | ||
| 103 | - } | ||
| 104 | - }) | ||
| 105 | - // // -------- | ||
| 106 | } | 67 | } |
| 107 | - //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ | 68 | + else { |
| 108 | - | 69 | + sad.check(message, replyToken); |
| 109 | - | 70 | + } |
| 110 | - console.log("11111"); | ||
| 111 | - console.log(body.message); | ||
| 112 | - console.log("11111"); | ||
| 113 | - // console.log(typeof(response.data.items[0].snippet.title)); | ||
| 114 | 71 | ||
| 115 | - request.post( | ||
| 116 | - { | ||
| 117 | - url: TARGET_URL, | ||
| 118 | - headers: { | ||
| 119 | - 'Authorization': `Bearer ${TOKEN}` | ||
| 120 | - }, | ||
| 121 | - json: { | ||
| 122 | - "replyToken":replyToken, | ||
| 123 | - "messages":[ | ||
| 124 | - { | ||
| 125 | - "type":"text", | ||
| 126 | - "text":sendMessage | ||
| 127 | - } | ||
| 128 | - ] | ||
| 129 | - } | ||
| 130 | - },(error, response, body) => { | ||
| 131 | - console.log(body) | ||
| 132 | - }); | ||
| 133 | } | 72 | } |
| 134 | }); | 73 | }); |
| 135 | } | 74 | } |
| 136 | - | ||
| 137 | try { | 75 | try { |
| 138 | const option = { | 76 | const option = { |
| 139 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 77 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
index_Temp.js
0 → 100644
This diff is collapsed. Click to expand it.
video_sad.js
0 → 100644
| 1 | +exports.check = function(message,replyToken){ | ||
| 2 | + | ||
| 3 | + const rand_0to9 = Math.floor(Math.random() * 10); // 0~9까지 난수생성 | ||
| 4 | + var ids = ['p5iu1V30myk', 'i-SBnhaZSSU', 'Etfgb6A7hSI', 'IN2mml9xs_s', // 모든 동영상 id를 관리하는 배열 | ||
| 5 | + 'tp1uoFAfgHE', 'Qx22TnVVIfU', '3y1QIqR115A', 'VXBI1wt8XII', 'aWMBn2--E0Q', 'HyTbgBlnLCo']; | ||
| 6 | + | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + const request = require('request'); | ||
| 10 | + const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
| 11 | + const TOKEN = 'Kb1/rQYz4MUhF8XyKQv7z9x0MxVQ5bX/XO8S/yt/1qQEJVAbsEFAaMvXKEOx9Umr7KhivfyDPfZHRRLFPngR0O4ZGWV2VFses8ufPE7uAdvYr4G6keBNAU69nBz5IC71HfbIrUHxXYqD7GfhVwXzpwdB04t89/1O/w1cDnyilFU=' | ||
| 12 | + var { google } = require('googleapis'); | ||
| 13 | + | ||
| 14 | + var service = google.youtube('v3'); | ||
| 15 | + service.videos.list({ | ||
| 16 | + key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518', | ||
| 17 | + part: 'snippet', | ||
| 18 | + id: ids[rand_0to9], // 동영상 Id random input | ||
| 19 | + fields: 'items(snippet(title))' | ||
| 20 | + }, function (err, response) { | ||
| 21 | + if (err) { | ||
| 22 | + console.log('The API returned an error: ', err); | ||
| 23 | + return; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + var video = response.data.items; | ||
| 27 | + if (video.length == 0) { | ||
| 28 | + console.log('검색된 동영상이 없습니다.'); | ||
| 29 | + } else { | ||
| 30 | + sendMessage = JSON.stringify(response.data.items[0].snippet.title); | ||
| 31 | + console.log(sendMessage); | ||
| 32 | + request.post( | ||
| 33 | + { | ||
| 34 | + url: TARGET_URL, | ||
| 35 | + headers: { | ||
| 36 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 37 | + }, | ||
| 38 | + json: { | ||
| 39 | + "replyToken": replyToken, | ||
| 40 | + "messages": [ | ||
| 41 | + { | ||
| 42 | + "type": "text", | ||
| 43 | + "text": sendMessage | ||
| 44 | + } | ||
| 45 | + ] | ||
| 46 | + } | ||
| 47 | + }, (error, response, body) => { | ||
| 48 | + console.log(body) | ||
| 49 | + }); | ||
| 50 | + } | ||
| 51 | + }) | ||
| 52 | + | ||
| 53 | + | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +} |
-
Please register or login to post a comment