Showing
1 changed file
with
67 additions
and
13 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | 2 | ||
3 | -// ----------crawling modules--------------- | ||
4 | -var puppeteer = require('puppeteer'); | ||
5 | -var gmarket = require('./crawling/gmarket'); | ||
6 | -var coupang = require('./crawling/coupang'); | ||
7 | -var auction = require('./crawling/auction'); | ||
8 | -//------------------------------------------ | ||
9 | - | ||
10 | const request = require('request'); | 3 | const request = require('request'); |
4 | + | ||
5 | +//--------------- Line messanger modules ------------------- | ||
11 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 6 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
12 | const TOKEN = 'LFi+FvOOFOydz0EKN22WRnQyiilnEiyxe2HVV1WrI54Jnght6+Gga07m7pxqSQltBJG2AV2lYnYOAk4TqxzZFKW9R36CJcQs+NaNEiNKJtgBfT/t3tEta/J6GtXxGz/DqdHnfZqSSfLFpXzun/ITTwdB04t89/1O/w1cDnyilFU=' | 7 | const TOKEN = 'LFi+FvOOFOydz0EKN22WRnQyiilnEiyxe2HVV1WrI54Jnght6+Gga07m7pxqSQltBJG2AV2lYnYOAk4TqxzZFKW9R36CJcQs+NaNEiNKJtgBfT/t3tEta/J6GtXxGz/DqdHnfZqSSfLFpXzun/ITTwdB04t89/1O/w1cDnyilFU=' |
8 | +//---------------------------------------------------------- | ||
13 | 9 | ||
14 | -//-----------------Translating moudules---------------------- | 10 | +//--------------- Translating moudules ---------------------- |
15 | const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | 11 | const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' |
16 | const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb' | 12 | const PAPAGO_ID = 'r_kuebFKCqBeL3SI_dFb' |
17 | const PAPAGO_SECRET = 'Wdz2tudrzB' | 13 | const PAPAGO_SECRET = 'Wdz2tudrzB' |
... | @@ -19,6 +15,15 @@ var trans = require('./trans/trans') | ... | @@ -19,6 +15,15 @@ var trans = require('./trans/trans') |
19 | var trans_counter = 0; | 15 | var trans_counter = 0; |
20 | //----------------------------------------------------------- | 16 | //----------------------------------------------------------- |
21 | 17 | ||
18 | +// ---------- Shopping modules ------------- | ||
19 | +var puppeteer = require('puppeteer'); | ||
20 | +var gmarket = require('./crawling/gmarket'); | ||
21 | +var coupang = require('./crawling/coupang'); | ||
22 | +var auction = require('./crawling/auction'); | ||
23 | +var shopping = 0; // in shopping menu identifier 0 = idle, 1 = shop selecting, 2 = select complete | ||
24 | +var shop_select = undefined // shopping-site identifier | ||
25 | +//------------------------------------------ | ||
26 | + | ||
22 | const fs = require('fs'); | 27 | const fs = require('fs'); |
23 | const path = require('path'); | 28 | const path = require('path'); |
24 | const HTTPS = require('https'); | 29 | const HTTPS = require('https'); |
... | @@ -30,10 +35,11 @@ const bodyParser = require('body-parser'); | ... | @@ -30,10 +35,11 @@ const bodyParser = require('body-parser'); |
30 | 35 | ||
31 | var app = express(); | 36 | var app = express(); |
32 | 37 | ||
33 | -//------middlewares------------------------------ | 38 | +//=============== middlewares ================ |
34 | app.use(bodyParser.json()); | 39 | app.use(bodyParser.json()); |
35 | 40 | ||
36 | -//--------------------Utility Selector---------------------------------------------------------------- | 41 | + |
42 | +//============== Utility Selector ========================================= | ||
37 | app.post('/hook', function (req, res) { | 43 | app.post('/hook', function (req, res) { |
38 | 44 | ||
39 | //-------- request values --------- | 45 | //-------- request values --------- |
... | @@ -49,7 +55,16 @@ app.post('/hook', function (req, res) { | ... | @@ -49,7 +55,16 @@ app.post('/hook', function (req, res) { |
49 | console.log('[request message]', eventObj.message); | 55 | console.log('[request message]', eventObj.message); |
50 | //---------------------------------------------------------------------------- | 56 | //---------------------------------------------------------------------------- |
51 | 57 | ||
52 | - //--------------------language identification & translation------------------- | 58 | + //--------------- Cancel ---------------------------------------------- |
59 | + if(message.text.includes('/취소')){ | ||
60 | + replying(eventObj.replyToken, '진행중인 기능 및 메뉴를 종료합니다.'); | ||
61 | + shopping = 0; | ||
62 | + shop_select = undefined | ||
63 | + trans_counter = 0; | ||
64 | + } | ||
65 | + //--------------------------------------------------------------------- | ||
66 | + | ||
67 | + //----------------------- Translation which includes language-selector ----------------------------------------------- | ||
53 | if(eventObj.message.text.includes('/번역')){ | 68 | if(eventObj.message.text.includes('/번역')){ |
54 | console.log('번역캐치: ', eventObj.message.text); | 69 | console.log('번역캐치: ', eventObj.message.text); |
55 | trans_counter = trans.trans_lng_selector(eventObj.message.text); // after this trans_trigger = 1 | 70 | trans_counter = trans.trans_lng_selector(eventObj.message.text); // after this trans_trigger = 1 |
... | @@ -57,14 +72,53 @@ app.post('/hook', function (req, res) { | ... | @@ -57,14 +72,53 @@ app.post('/hook', function (req, res) { |
57 | else if(trans_counter==1){ | 72 | else if(trans_counter==1){ |
58 | trans_counter = trans.translating(eventObj.replyToken, eventObj.message.text); // after this trans_trigger = 0 | 73 | trans_counter = trans.translating(eventObj.replyToken, eventObj.message.text); // after this trans_trigger = 0 |
59 | } | 74 | } |
60 | - | 75 | + //-------------------------------------------------------------------------------------------------------------------- |
61 | - | 76 | + |
77 | + //---------------------- linking Shoppingcart crawler ---------------------------------------------------------------- | ||
78 | + if(message.text == '/쇼핑' ){ | ||
79 | + replying(eventObj.replyToken, '쇼핑을 선택하셨습니다.\n원하시는 쇼핑몰 사이트를 선택하세요.\n현재 제공되는 사이트는 \n\n/g마켓\n/옥션\n/쿠팡\n\n입니다.\n/취소 로 해당 메뉴에서 퇴장이 가능합니다.'); | ||
80 | + shopping = 1; // 다음 메세지에 선택하지 못할 경우 0으로 되돌릴 필요가있음 | ||
81 | + } | ||
82 | + if(shopping == 1){ | ||
83 | + switch(message.text){ | ||
84 | + case '/g마켓': break; | ||
85 | + case '/옥션': break; | ||
86 | + case '/쿠팡': break; | ||
87 | + default: shopping == 0; | ||
88 | + } | ||
89 | + } | ||
90 | + //-------------------------------------------------------------------------------------------------------------------- | ||
62 | 91 | ||
63 | 92 | ||
64 | res.sendStatus(200); | 93 | res.sendStatus(200); |
65 | }); | 94 | }); |
66 | 95 | ||
67 | 96 | ||
97 | +//================== Just replying specific messages needed =================================== | ||
98 | +function replying(replyToken, sp_message){ // sp_message is message(string) that depends on the situation that user selects | ||
99 | + request.post( | ||
100 | + { | ||
101 | + url: TARGET_URL, | ||
102 | + headers: { | ||
103 | + 'Authorization': `Bearer ${TOKEN}` | ||
104 | + }, | ||
105 | + json: { | ||
106 | + "replyToken":replyToken, | ||
107 | + "messages":[ | ||
108 | + { | ||
109 | + "type":"text", | ||
110 | + "text":sp_message // replying message | ||
111 | + } | ||
112 | + ] | ||
113 | + } | ||
114 | + },(error, response, body) => { | ||
115 | + console.log(body) | ||
116 | + trans_trigger=0; | ||
117 | + return trans_trigger; | ||
118 | + }); | ||
119 | +} | ||
120 | + | ||
121 | +//==================== Creating Server : Port = val sslport =============================== | ||
68 | try { | 122 | try { |
69 | const option = { | 123 | const option = { |
70 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 124 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ... | ... |
-
Please register or login to post a comment