Showing
1 changed file
with
106 additions
and
7 deletions
| 1 | +var end = false; | ||
| 1 | var count = 0; | 2 | var count = 0; |
| 2 | var choosen = new Array(); | 3 | var choosen = new Array(); |
| 3 | var express = require('express'); | 4 | var express = require('express'); |
| 4 | const request = require('request'); | 5 | const request = require('request'); |
| 5 | -const TARGET_URL = '라인 URL' | 6 | +const TARGET_URL = '타겟 URL' |
| 6 | -const TOKEN = '라인 토큰' | 7 | +const TOKEN = '토큰' |
| 7 | -const PAPAGO_URL = '파파고 API URL' | 8 | +const PAPAGO_URL = '파파고 URL' |
| 8 | const PAPAGO_ID = '파파고 ID' | 9 | const PAPAGO_ID = '파파고 ID' |
| 9 | const PAPAGO_SECRET = '파파고 시크릿' | 10 | const PAPAGO_SECRET = '파파고 시크릿' |
| 10 | const fs = require('fs'); | 11 | const fs = require('fs'); |
| ... | @@ -14,6 +15,8 @@ const domain = "도메인" | ... | @@ -14,6 +15,8 @@ const domain = "도메인" |
| 14 | const sslport = 23023; | 15 | const sslport = 23023; |
| 15 | const bodyParser = require('body-parser'); | 16 | const bodyParser = require('body-parser'); |
| 16 | const res = require('express/lib/response'); | 17 | const res = require('express/lib/response'); |
| 18 | +const { eventNames } = require('process'); | ||
| 19 | +const req = require('express/lib/request'); | ||
| 17 | var app = express(); | 20 | var app = express(); |
| 18 | app.use(bodyParser.json()); | 21 | app.use(bodyParser.json()); |
| 19 | app.post('/hook', function (req, res) { | 22 | app.post('/hook', function (req, res) { |
| ... | @@ -59,13 +62,21 @@ app.post('/hook', function (req, res) { | ... | @@ -59,13 +62,21 @@ app.post('/hook', function (req, res) { |
| 59 | { | 62 | { |
| 60 | choosen.push(eventObj.message.text); | 63 | choosen.push(eventObj.message.text); |
| 61 | count++; | 64 | count++; |
| 65 | + Rmx_comment(eventObj.replyToken); | ||
| 66 | + }else if(count == 6 && end) | ||
| 67 | + { | ||
| 68 | + Rmx(eventObj.replyToken); | ||
| 69 | + count++; | ||
| 70 | + }else if(count ==7 && end && eventObj.message.text == 'y') | ||
| 71 | + { | ||
| 72 | + load_map(eventObj.replyToken); | ||
| 73 | + count++; | ||
| 74 | + }else{ | ||
| 75 | + err(eventObj.replyToken); | ||
| 62 | } | 76 | } |
| 63 | 77 | ||
| 64 | res.sendStatus(200); | 78 | res.sendStatus(200); |
| 65 | - for(var i = 0;i<5;i++) | 79 | + |
| 66 | - { | ||
| 67 | - console.log(choosen[i]); | ||
| 68 | - } | ||
| 69 | }); | 80 | }); |
| 70 | 81 | ||
| 71 | async function start_msg(replyToken, message) { | 82 | async function start_msg(replyToken, message) { |
| ... | @@ -288,8 +299,96 @@ async function opt_5(replyToken, message) { | ... | @@ -288,8 +299,96 @@ async function opt_5(replyToken, message) { |
| 288 | }); | 299 | }); |
| 289 | } | 300 | } |
| 290 | }); | 301 | }); |
| 302 | + end= true; | ||
| 291 | } | 303 | } |
| 292 | 304 | ||
| 305 | +async function Rmx_comment(replyToken) | ||
| 306 | +{ | ||
| 307 | + await request.post( | ||
| 308 | + { | ||
| 309 | + url: TARGET_URL, | ||
| 310 | + headers: { | ||
| 311 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 312 | + }, | ||
| 313 | + json: { | ||
| 314 | + "replyToken": replyToken, | ||
| 315 | + "messages": [ | ||
| 316 | + { | ||
| 317 | + "type": "text", | ||
| 318 | + "text": "계속하려면 아무키나 입력하시오." | ||
| 319 | + } | ||
| 320 | + ] | ||
| 321 | + } | ||
| 322 | + }, (error, response, body) => { | ||
| 323 | + console.log(body) | ||
| 324 | + }); | ||
| 325 | +} | ||
| 326 | + | ||
| 327 | +async function Rmx(replyToken) | ||
| 328 | +{ | ||
| 329 | + await request.post( | ||
| 330 | + { | ||
| 331 | + url: TARGET_URL, | ||
| 332 | + headers: { | ||
| 333 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 334 | + }, | ||
| 335 | + json: { | ||
| 336 | + "replyToken": replyToken, | ||
| 337 | + "messages": [ | ||
| 338 | + { | ||
| 339 | + "type": "text", | ||
| 340 | + "text": "추천 음식은 ~~~~ 입니다.\n 음식점을 추천 받으시겠습니까? (y/n)" | ||
| 341 | + } | ||
| 342 | + ] | ||
| 343 | + } | ||
| 344 | + }, (error, response, body) => { | ||
| 345 | + console.log(body) | ||
| 346 | + }); | ||
| 347 | +} | ||
| 348 | + | ||
| 349 | +async function load_map(replyToken) | ||
| 350 | +{ | ||
| 351 | + await request.post( | ||
| 352 | + { | ||
| 353 | + url: TARGET_URL, | ||
| 354 | + headers: { | ||
| 355 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 356 | + }, | ||
| 357 | + json: { | ||
| 358 | + "replyToken": replyToken, | ||
| 359 | + "messages": [ | ||
| 360 | + { | ||
| 361 | + "type": "herf", | ||
| 362 | + "href": "file:///C:/Users/pnr02/Desktop/opensource_project/selectWestern.html" | ||
| 363 | + } | ||
| 364 | + ] | ||
| 365 | + } | ||
| 366 | + }, (error, response, body) => { | ||
| 367 | + console.log(body) | ||
| 368 | + }); | ||
| 369 | +} | ||
| 370 | + | ||
| 371 | +async function err(replyToken) | ||
| 372 | +{ | ||
| 373 | + await request.post( | ||
| 374 | + { | ||
| 375 | + url: TARGET_URL, | ||
| 376 | + headers: { | ||
| 377 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 378 | + }, | ||
| 379 | + json: { | ||
| 380 | + "replyToken": replyToken, | ||
| 381 | + "messages": [ | ||
| 382 | + { | ||
| 383 | + "type": "text", | ||
| 384 | + "text": "please enter a right thing" | ||
| 385 | + } | ||
| 386 | + ] | ||
| 387 | + } | ||
| 388 | + }, (error, response, body) => { | ||
| 389 | + console.log(body) | ||
| 390 | + }); | ||
| 391 | +} | ||
| 293 | 392 | ||
| 294 | try { | 393 | try { |
| 295 | const option = { | 394 | const option = { | ... | ... |
-
Please register or login to post a comment