Showing
1 changed file
with
75 additions
and
13 deletions
... | @@ -15,39 +15,101 @@ const data = require('./functions/dataFunctions') | ... | @@ -15,39 +15,101 @@ const data = require('./functions/dataFunctions') |
15 | const find = require('./functions/findFunction') | 15 | const find = require('./functions/findFunction') |
16 | 16 | ||
17 | // 0초 0분 0시 아무날 아무달 아무년 | 17 | // 0초 0분 0시 아무날 아무달 아무년 |
18 | -const saveData = schedule.scheduleJob('55 54 18 * * *', data.save) | 18 | +const saveData = schedule.scheduleJob('00 0 00 * * *', data.save) |
19 | 19 | ||
20 | var app = express(); | 20 | var app = express(); |
21 | app.use(bodyParser.json()); | 21 | app.use(bodyParser.json()); |
22 | app.post('/hook', function (req, res) { | 22 | app.post('/hook', function (req, res) { |
23 | var eventObj = req.body.events[0]; | 23 | var eventObj = req.body.events[0]; |
24 | + | ||
24 | var source = eventObj.source; | 25 | var source = eventObj.source; |
25 | var message = eventObj.message; | 26 | var message = eventObj.message; |
26 | // request log | 27 | // request log |
27 | console.log('======================', new Date() ,'======================'); | 28 | console.log('======================', new Date() ,'======================'); |
29 | + console.log('[queryString]', req.query) | ||
28 | console.log('[request]', req.body); | 30 | console.log('[request]', req.body); |
29 | - console.log('[request source] ', eventObj.source); | 31 | + console.log('[request source] ', eventObj.source, eventObj2.source); |
30 | - console.log('[request message]', eventObj.message); | 32 | + console.log('[request message]', eventObj.message, eventObj2.message); |
31 | - request.post( | 33 | + console.log('[request postback]', eventObj.postback, eventObj2.postback); |
34 | + const messageData = find.byCompanyName('naver') | ||
35 | + const messageResult = [] | ||
36 | + let string | ||
37 | + let start | ||
38 | + let finish | ||
39 | + let data | ||
40 | + let button | ||
41 | + let flag = true | ||
42 | + if (!eventObj.postback){ | ||
43 | + start = 0; | ||
44 | + finish = start + 4 | ||
45 | + } | ||
46 | + else{ | ||
47 | + start = parseInt(eventObj.postback.data.split(" ")[1]) | ||
48 | + finish = start + 4 | ||
49 | + if (finish >= messageData.length){ | ||
50 | + finish = messageData.length | ||
51 | + flag = false | ||
52 | + } | ||
53 | + } | ||
54 | + data = `kakao ${finish}` | ||
55 | + button = { | ||
56 | + "type" : "flex", | ||
57 | + "altText" : "test FLEX", | ||
58 | + "contents" : { | ||
59 | + "type": "bubble", | ||
60 | + "body": { | ||
61 | + "type": "box", | ||
62 | + "layout" : "vertical", | ||
63 | + "contents" : [ | ||
32 | { | 64 | { |
65 | + "type": "button", | ||
66 | + "action": { | ||
67 | + "type":"postback", | ||
68 | + "label":"다음 보기", | ||
69 | + "data": data | ||
70 | + }, | ||
71 | + "style": "primary", | ||
72 | + "color": "#0000ff" | ||
73 | + } | ||
74 | + ] | ||
75 | + } | ||
76 | + } | ||
77 | + } | ||
78 | + console.log(start, finish, data) | ||
79 | + for(start ; start < finish; start++){ | ||
80 | + string = "제목 : " + messageData[start].title +"\n" + "회사명 : " + messageData[start].companyName + "\n" + "tags : " + messageData[start].tags.toString() +"\n" + "링크 : " + messageData[start].url + "\n" | ||
81 | + messageResult.push({ | ||
82 | + "type" : "text", | ||
83 | + "text" : string | ||
84 | + }) | ||
85 | + } | ||
86 | + if(flag){ | ||
87 | + messageResult.push(button) | ||
88 | + result = { | ||
33 | url: TARGET_URL, | 89 | url: TARGET_URL, |
34 | headers: { | 90 | headers: { |
35 | 'Authorization': `Bearer ${TOKEN}` | 91 | 'Authorization': `Bearer ${TOKEN}` |
36 | }, | 92 | }, |
37 | json: { | 93 | json: { |
38 | "replyToken":eventObj.replyToken, | 94 | "replyToken":eventObj.replyToken, |
39 | - "messages":[ | 95 | + "messages": messageResult |
40 | - { | 96 | + } |
41 | - "type":"text", | 97 | + } |
42 | - "text":"Hello, user" | 98 | + } |
99 | + else{ | ||
100 | + result = { | ||
101 | + url: TARGET_URL, | ||
102 | + headers: { | ||
103 | + 'Authorization': `Bearer ${TOKEN}` | ||
43 | }, | 104 | }, |
44 | - { | 105 | + json: { |
45 | - "type":"text", | 106 | + "replyToken":eventObj.replyToken, |
46 | - "text":"May I help you?" | 107 | + "messages": messageResult |
108 | + } | ||
47 | } | 109 | } |
48 | - ] | ||
49 | } | 110 | } |
50 | - },(error, response, body) => { | 111 | + |
112 | + request.post(result ,(error, response, body) => { | ||
51 | console.log(body) | 113 | console.log(body) |
52 | }); | 114 | }); |
53 | 115 | ... | ... |
-
Please register or login to post a comment