Showing
4 changed files
with
355 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
| 1 | +var express = require('express'); | ||
| 2 | +const request = require('request'); | ||
| 3 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
| 4 | +const TOKEN = 'Kb1/rQYz4MUhF8XyKQv7z9x0MxVQ5bX/XO8S/yt/1qQEJVAbsEFAaMvXKEOx9Umr7KhivfyDPfZHRRLFPngR0O4ZGWV2VFses8ufPE7uAdvYr4G6keBNAU69nBz5IC71HfbIrUHxXYqD7GfhVwXzpwdB04t89/1O/w1cDnyilFU=' | ||
| 5 | +const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | ||
| 6 | +const PAPAGO_ID = 'kwoxKGTi6azBaW9aSVxe' | ||
| 7 | +const PAPAGO_SECRET = 'svB_MM61oD' | ||
| 8 | +const fs = require('fs'); | ||
| 9 | +const path = require('path'); | ||
| 10 | +const HTTPS = require('https'); | ||
| 11 | +const domain = "2020105631.oss2021.tk" | ||
| 12 | +const sslport = 23023; | ||
| 13 | +const bodyParser = require('body-parser'); | ||
| 14 | +var app = express(); | ||
| 15 | +app.use(bodyParser.json()); | ||
| 16 | + | ||
| 17 | +var { google } = require('googleapis'); | ||
| 18 | + | ||
| 19 | +/// ---- | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +app.post('/hook', function (req, res) { | ||
| 23 | + | ||
| 24 | + var eventObj = req.body.events[0]; | ||
| 25 | + var source = eventObj.source; | ||
| 26 | + var message = eventObj.message; | ||
| 27 | + | ||
| 28 | + // request log | ||
| 29 | + console.log('======================', new Date(), '======================'); | ||
| 30 | + console.log('[request]', req.body); | ||
| 31 | + console.log('[request source] ', eventObj.source); | ||
| 32 | + console.log('[request message]', eventObj.message); | ||
| 33 | + | ||
| 34 | + trans(eventObj.replyToken, eventObj.message.text); | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + res.sendStatus(200); | ||
| 38 | +}); | ||
| 39 | +function trans(replyToken, message) { | ||
| 40 | + | ||
| 41 | + request.post( | ||
| 42 | + | ||
| 43 | + { | ||
| 44 | + url: PAPAGO_URL, | ||
| 45 | + headers: { | ||
| 46 | + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
| 47 | + 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
| 48 | + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
| 49 | + }, | ||
| 50 | + body: 'source=ko&target=en&text=' + message, | ||
| 51 | + json: true | ||
| 52 | + }, | ||
| 53 | + | ||
| 54 | + (error, response, body) => { | ||
| 55 | + if (!error && response.statusCode == 200) { | ||
| 56 | + // message 가 사용자에게서 입력받은 메시지 내용입니다. sendMessage 는 보낼 메시지 내용입니다. | ||
| 57 | + // 위에 PAPAGO API부분은 추후 API를 연동시킬 때 맞춰서 작성하기 쉽도록 템플릿을 남겨놓았습니다. 자세한 정보는 교수님 학습 자료의 experiment의 trans 폴더를 참고하세요. | ||
| 58 | + // (현재 코드에선 PAPAGO API의 작동 결과는 반영되지 않습니다.) | ||
| 59 | + //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ | ||
| 60 | + // var sendMessage; | ||
| 61 | + | ||
| 62 | + // -------- | ||
| 63 | + if (message == "노래 추천해줘") { | ||
| 64 | + sendMessage = "아이유의 노래를 추천드립니다."; | ||
| 65 | + console.log(typeof (sendMessage)); | ||
| 66 | + console.log(sendMessage); | ||
| 67 | + | ||
| 68 | + request.post( | ||
| 69 | + { | ||
| 70 | + url: TARGET_URL, | ||
| 71 | + headers: { | ||
| 72 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 73 | + }, | ||
| 74 | + json: { | ||
| 75 | + "replyToken": replyToken, | ||
| 76 | + "messages": [ | ||
| 77 | + { | ||
| 78 | + "type": "text", | ||
| 79 | + "text": sendMessage | ||
| 80 | + } | ||
| 81 | + ] | ||
| 82 | + } | ||
| 83 | + }, (error, response, body) => { | ||
| 84 | + console.log(body) | ||
| 85 | + }); | ||
| 86 | + | ||
| 87 | + } | ||
| 88 | + else { | ||
| 89 | + // var sendMessage = "무슨 말인지 못알아먹겠습니다"; | ||
| 90 | + | ||
| 91 | + // -------- | ||
| 92 | + var service = google.youtube('v3'); | ||
| 93 | + service.videos.list({ | ||
| 94 | + key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518', | ||
| 95 | + part: 'snippet,statistics', | ||
| 96 | + id: 'p5iu1V30myk', // 동영상 Id | ||
| 97 | + fields: 'items(snippet(title))' | ||
| 98 | + }, function (err, response) { | ||
| 99 | + if (err) { | ||
| 100 | + console.log('The API returned an error: ', err); | ||
| 101 | + return; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + var video = response.data.items; | ||
| 105 | + if (video.length == 0) { | ||
| 106 | + console.log('검색된 동영상이 없습니다.'); | ||
| 107 | + } else { | ||
| 108 | + // var sendMessage ="123"; | ||
| 109 | + // console.log(JSON.stringify(response.data.items[0].snippet.title));// 콘솔에 출력 | ||
| 110 | + // console.log(JSON.stringify(response.data.items[0].snippet));// 콘솔에 출력 | ||
| 111 | + // console.log(JSON.stringify(response.data.items[0]));// 콘솔에 출력 | ||
| 112 | + // console.log(JSON.stringify(response.data));// 콘솔에 출력 | ||
| 113 | + | ||
| 114 | + | ||
| 115 | + var sendMessage = JSON.stringify(response.data.items[0].snippet.title); | ||
| 116 | + // sendMessage = response.data.items[0].snippet.title; | ||
| 117 | + console.log(sendMessage); | ||
| 118 | + console.log(typeof (sendMessage)); | ||
| 119 | + } | ||
| 120 | + request.post( | ||
| 121 | + { | ||
| 122 | + url: TARGET_URL, | ||
| 123 | + headers: { | ||
| 124 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 125 | + }, | ||
| 126 | + json: { | ||
| 127 | + "replyToken": replyToken, | ||
| 128 | + "messages": [ | ||
| 129 | + { | ||
| 130 | + "type": "text", | ||
| 131 | + "text": sendMessage | ||
| 132 | + } | ||
| 133 | + ] | ||
| 134 | + } | ||
| 135 | + }, (error, response, body) => { | ||
| 136 | + console.log(body) | ||
| 137 | + }); | ||
| 138 | + }) | ||
| 139 | + // // -------- | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + } | ||
| 143 | + }); | ||
| 144 | +} | ||
| 145 | +// function trans(replyToken, message) { | ||
| 146 | +// request.post( | ||
| 147 | +// { | ||
| 148 | +// url: PAPAGO_URL, | ||
| 149 | +// headers: { | ||
| 150 | +// 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | ||
| 151 | +// 'X-Naver-Client-Id': `${PAPAGO_ID}`, | ||
| 152 | +// 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | ||
| 153 | +// }, | ||
| 154 | +// body: 'source=ko&target=en&text=' + message, | ||
| 155 | +// json:true | ||
| 156 | +// }, | ||
| 157 | + | ||
| 158 | +// (error, response, body) => { | ||
| 159 | +// if(!error && response.statusCode == 200) | ||
| 160 | +// { | ||
| 161 | +// // message 가 사용자에게서 입력받은 메시지 내용입니다. sendMessage 는 보낼 메시지 내용입니다. | ||
| 162 | +// // 위에 PAPAGO API부분은 추후 API를 연동시킬 때 맞춰서 작성하기 쉽도록 템플릿을 남겨놓았습니다. 자세한 정보는 교수님 학습 자료의 experiment의 trans 폴더를 참고하세요. | ||
| 163 | +// // (현재 코드에선 PAPAGO API의 작동 결과는 반영되지 않습니다.) | ||
| 164 | +// //↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ | ||
| 165 | + | ||
| 166 | + | ||
| 167 | + | ||
| 168 | +// var sendMessage; | ||
| 169 | +// // -------- | ||
| 170 | +// if (message=="노래 추천해줘") | ||
| 171 | +// { | ||
| 172 | +// sendMessage = "아이유의 노래를 추천드립니다."; | ||
| 173 | +// console.log(typeof(sendMessage)); | ||
| 174 | +// console.log(sendMessage); | ||
| 175 | + | ||
| 176 | + | ||
| 177 | +// console.log("11111"); | ||
| 178 | +// console.log(body.message); | ||
| 179 | +// console.log("11111"); | ||
| 180 | +// // console.log(typeof(response.data.items[0].snippet.title)); | ||
| 181 | + | ||
| 182 | +// request.post( | ||
| 183 | +// { | ||
| 184 | +// url: TARGET_URL, | ||
| 185 | +// headers: { | ||
| 186 | +// 'Authorization': `Bearer ${TOKEN}` | ||
| 187 | +// }, | ||
| 188 | +// json: { | ||
| 189 | +// "replyToken": replyToken, | ||
| 190 | +// "messages": [ | ||
| 191 | +// { | ||
| 192 | +// "type": "text", | ||
| 193 | +// "text": sendMessage | ||
| 194 | +// } | ||
| 195 | +// ] | ||
| 196 | +// } | ||
| 197 | +// }, (error, response, body) => { | ||
| 198 | +// console.log(body) | ||
| 199 | +// }); | ||
| 200 | +// } | ||
| 201 | +// else | ||
| 202 | +// { | ||
| 203 | +// // var sendMessage = "무슨 말인지 못알아먹겠습니다"; | ||
| 204 | +// // -------- | ||
| 205 | +// var service = google.youtube('v3'); | ||
| 206 | + | ||
| 207 | +// service.videos.list({ | ||
| 208 | +// key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518', | ||
| 209 | +// part: 'snippet,statistics', | ||
| 210 | +// id: 'p5iu1V30myk', // 동영상 Id | ||
| 211 | +// fields: 'items(snippet(title))' | ||
| 212 | +// }, function (err, response) { | ||
| 213 | +// if (err) { | ||
| 214 | +// console.log('The API returned an error: ', err); | ||
| 215 | +// return; | ||
| 216 | +// } | ||
| 217 | + | ||
| 218 | +// var video = response.data.items; | ||
| 219 | +// if (video.length == 0) { | ||
| 220 | +// console.log('검색된 동영상이 없습니다.'); | ||
| 221 | +// } else { | ||
| 222 | +// // var sendMessage ="123"; | ||
| 223 | +// // console.log(JSON.stringify(response.data.items[0].snippet.title));// 콘솔에 출력 | ||
| 224 | +// // console.log(JSON.stringify(response.data.items[0].snippet));// 콘솔에 출력 | ||
| 225 | +// // console.log(JSON.stringify(response.data.items[0]));// 콘솔에 출력 | ||
| 226 | +// // console.log(JSON.stringify(response.data));// 콘솔에 출력 | ||
| 227 | + | ||
| 228 | +// sendMessage = JSON.stringify(response.data.items[0].snippet.title); | ||
| 229 | +// // sendMessage = response.data.items[0].snippet.title; | ||
| 230 | +// console.log(sendMessage); | ||
| 231 | +// console.log(typeof (sendMessage)); | ||
| 232 | +// } | ||
| 233 | +// //console.log(sendMessage); | ||
| 234 | +// }) | ||
| 235 | +// //console.log(sendMessage); | ||
| 236 | +// // // -------- | ||
| 237 | +// /// ---- | ||
| 238 | + | ||
| 239 | + | ||
| 240 | +// console.log("11111"); | ||
| 241 | +// console.log(body.message); | ||
| 242 | +// console.log("11111"); | ||
| 243 | +// // console.log(typeof(response.data.items[0].snippet.title)); | ||
| 244 | + | ||
| 245 | +// request.post( | ||
| 246 | +// { | ||
| 247 | +// url: TARGET_URL, | ||
| 248 | +// headers: { | ||
| 249 | +// 'Authorization': `Bearer ${TOKEN}` | ||
| 250 | +// }, | ||
| 251 | +// json: { | ||
| 252 | +// "replyToken": replyToken, | ||
| 253 | +// "messages": [ | ||
| 254 | +// { | ||
| 255 | +// "type": "text", | ||
| 256 | +// "text": sendMessage | ||
| 257 | +// } | ||
| 258 | +// ] | ||
| 259 | +// } | ||
| 260 | +// }, (error, response, body) => { | ||
| 261 | +// console.log(body) | ||
| 262 | +// }); | ||
| 263 | +// } | ||
| 264 | +// //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ | ||
| 265 | + | ||
| 266 | +// } | ||
| 267 | +// }); | ||
| 268 | +// } | ||
| 269 | + | ||
| 270 | +try { | ||
| 271 | + const option = { | ||
| 272 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), | ||
| 273 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(), | ||
| 274 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(), | ||
| 275 | + }; | ||
| 276 | + | ||
| 277 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
| 278 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
| 279 | + }); | ||
| 280 | +} catch (error) { | ||
| 281 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
| 282 | + console.log(error); | ||
| 283 | +} |
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