Showing
4 changed files
with
165 additions
and
5 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | var app = express(); | 2 | var app = express(); |
3 | const line = require('@line/bot-sdk'); | 3 | const line = require('@line/bot-sdk'); |
4 | -const config = require('./config'); | 4 | +const config = require('./config.js'); |
5 | 5 | ||
6 | 6 | ||
7 | //papago api | 7 | //papago api |
... | @@ -23,7 +23,11 @@ const client = new line.Client(config.line_config); | ... | @@ -23,7 +23,11 @@ const client = new line.Client(config.line_config); |
23 | 23 | ||
24 | // register a webhook handler with middleware | 24 | // register a webhook handler with middleware |
25 | // about the middleware, please refer to doc | 25 | // about the middleware, please refer to doc |
26 | -app.post('/webhook', line.middleware(config), (req, res) => { | 26 | + |
27 | +const bodyParser = require('body-parser'); | ||
28 | +app.use(bodyParser.json()); | ||
29 | + | ||
30 | +app.post('/webhook', line.middleware(config.line_config), (req, res) => { | ||
27 | Promise | 31 | Promise |
28 | .all(req.body.events.map(handleEvent)) | 32 | .all(req.body.events.map(handleEvent)) |
29 | .then((result) => res.json(result)) | 33 | .then((result) => res.json(result)) |
... | @@ -31,15 +35,23 @@ app.post('/webhook', line.middleware(config), (req, res) => { | ... | @@ -31,15 +35,23 @@ app.post('/webhook', line.middleware(config), (req, res) => { |
31 | console.error(err); | 35 | console.error(err); |
32 | res.status(200).end(); | 36 | res.status(200).end(); |
33 | }); | 37 | }); |
38 | + console.log('[result]', req.json(result)); | ||
39 | + console.log('[request]', req.body); | ||
40 | + console.log('[request source]', req.body.events[0].source); | ||
41 | + console.log('[request message]', req.body.events[0].message); | ||
34 | }); | 42 | }); |
35 | 43 | ||
44 | + | ||
36 | // event handler | 45 | // event handler |
37 | function handleEvent(event) { | 46 | function handleEvent(event) { |
47 | + console.log("event.message.text"); | ||
38 | if (event.type !== 'message' || event.message.type !== 'text') { | 48 | if (event.type !== 'message' || event.message.type !== 'text') { |
49 | + console.log("2"); | ||
39 | // ignore non-text-message event | 50 | // ignore non-text-message event |
40 | return Promise.resolve(null); | 51 | return Promise.resolve(null); |
41 | } | 52 | } |
42 | return new Promise(function(resolve, reject) { | 53 | return new Promise(function(resolve, reject) { |
54 | + console.log("3"); | ||
43 | //언어 감지 option | 55 | //언어 감지 option |
44 | var detect_options = { | 56 | var detect_options = { |
45 | url : languagedetect_api_url, | 57 | url : languagedetect_api_url, |
... | @@ -49,6 +61,7 @@ function handleEvent(event) { | ... | @@ -49,6 +61,7 @@ function handleEvent(event) { |
49 | 61 | ||
50 | //papago 언어 감지 | 62 | //papago 언어 감지 |
51 | request.post(detect_options,function(error,response,body){ | 63 | request.post(detect_options,function(error,response,body){ |
64 | + console.log("4"); | ||
52 | console.log(response.statusCode); | 65 | console.log(response.statusCode); |
53 | if(!error && response.statusCode == 200){ | 66 | if(!error && response.statusCode == 200){ |
54 | var detect_body = JSON.parse(response.body); | 67 | var detect_body = JSON.parse(response.body); |
... | @@ -62,6 +75,7 @@ function handleEvent(event) { | ... | @@ -62,6 +75,7 @@ function handleEvent(event) { |
62 | 75 | ||
63 | //번역은 한국어->영어 / 영어->한국어만 지원 | 76 | //번역은 한국어->영어 / 영어->한국어만 지원 |
64 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ | 77 | if(detect_body.langCode == 'ko'||detect_body.langCode == 'en'){ |
78 | + console.log("5"); | ||
65 | source = detect_body.langCode == 'ko' ? 'ko':'en'; | 79 | source = detect_body.langCode == 'ko' ? 'ko':'en'; |
66 | target = source == 'ko' ? 'en':'ko'; | 80 | target = source == 'ko' ? 'en':'ko'; |
67 | //papago 번역 option | 81 | //papago 번역 option |
... | @@ -74,7 +88,7 @@ function handleEvent(event) { | ... | @@ -74,7 +88,7 @@ function handleEvent(event) { |
74 | 88 | ||
75 | // Naver Post API | 89 | // Naver Post API |
76 | request.post(options, function(error, response, body){ | 90 | request.post(options, function(error, response, body){ |
77 | - // Translate API Sucess | 91 | + // Translate API Success |
78 | if(!error && response.statusCode == 200){ | 92 | if(!error && response.statusCode == 200){ |
79 | // JSON | 93 | // JSON |
80 | var objBody = JSON.parse(response.body); | 94 | var objBody = JSON.parse(response.body); | ... | ... |
menu.js
0 → 100644
1 | +curl - v - X POST https: //api.line.me/v2/bot/richmenu \ | ||
2 | + -H 'Authorization: Bearer FemJMku1wbyrrbrvVcrppKimYhKbtsJKNZ5F4DgxtRKvZNYqY8lLamQLau8IlucsNKMgimU35uD+HaqVKHtrZ1L9IaPNBMdIBo5YSgcDwAf9lVMvieFK1dwpddi98XCdI2ma7kEIy5h3LzmEF3CLOQdB04t89/1O/w1cDnyilFU='\ | ||
3 | + -H 'Content-Type:application/json'\ | ||
4 | + -d\ '{ | ||
5 | +"size": { | ||
6 | + "width": 800, | ||
7 | + "height": 540 | ||
8 | +}, | ||
9 | +"selected": false, | ||
10 | +"name": "번역 옵션", | ||
11 | +"chatBarText": "번역 옵션", | ||
12 | +"areas": [{ | ||
13 | + "bounds": { | ||
14 | + "x": 0, | ||
15 | + "y": 270, | ||
16 | + "width": 400, | ||
17 | + "height": 270 | ||
18 | + }, | ||
19 | + "action": { | ||
20 | + "type": "message", | ||
21 | + "text": "문법을 검사합니다." | ||
22 | + } | ||
23 | + }, | ||
24 | + { | ||
25 | + "bounds": { | ||
26 | + "x": 400, | ||
27 | + "y": 270, | ||
28 | + "width": 400, | ||
29 | + "height": 270 | ||
30 | + }, | ||
31 | + "action": { | ||
32 | + "type": "message", | ||
33 | + "text": "이미지 내 문장을 번역합니다." | ||
34 | + } | ||
35 | + }, | ||
36 | + { | ||
37 | + "bounds": { | ||
38 | + "x": 0, | ||
39 | + "y": 540, | ||
40 | + "width": 400, | ||
41 | + "height": 270 | ||
42 | + }, | ||
43 | + "action": { | ||
44 | + "type": "message", | ||
45 | + "quickReply": { | ||
46 | + "items": [{ | ||
47 | + "type": "action", | ||
48 | + "action": { | ||
49 | + "type": "message", | ||
50 | + "label": "영어", | ||
51 | + "text": "영어" | ||
52 | + } | ||
53 | + }, | ||
54 | + { | ||
55 | + "type": "action", | ||
56 | + "action": { | ||
57 | + "type": "message", | ||
58 | + "label": "일본어", | ||
59 | + "text": "일본어" | ||
60 | + } | ||
61 | + }, | ||
62 | + { | ||
63 | + "type": "action", | ||
64 | + "action": { | ||
65 | + "type": "message", | ||
66 | + "label": "중국어", | ||
67 | + "text": "중국어" | ||
68 | + } | ||
69 | + }, | ||
70 | + { | ||
71 | + "type": "action", | ||
72 | + "action": { | ||
73 | + "type": "message", | ||
74 | + "label": "스페인어", | ||
75 | + "text": "스페인어" | ||
76 | + } | ||
77 | + }, | ||
78 | + { | ||
79 | + "type": "action", | ||
80 | + "action": { | ||
81 | + "type": "message", | ||
82 | + "label": "독일어", | ||
83 | + "text": "독일어" | ||
84 | + } | ||
85 | + }, | ||
86 | + { | ||
87 | + "type": "action", | ||
88 | + "action": { | ||
89 | + "type": "message", | ||
90 | + "label": "프랑스어", | ||
91 | + "text": "프랑스어" | ||
92 | + } | ||
93 | + }, | ||
94 | + { | ||
95 | + "type": "action", | ||
96 | + "action": { | ||
97 | + "type": "message", | ||
98 | + "label": "러시아어", | ||
99 | + "text": "러시아어" | ||
100 | + } | ||
101 | + }, | ||
102 | + { | ||
103 | + "type": "action", | ||
104 | + "action": { | ||
105 | + "type": "message", | ||
106 | + "label": "태국어", | ||
107 | + "text": "태국어" | ||
108 | + } | ||
109 | + }, | ||
110 | + { | ||
111 | + "type": "action", | ||
112 | + "action": { | ||
113 | + "type": "message", | ||
114 | + "label": "인도네시아어", | ||
115 | + "text": "인도네시아어" | ||
116 | + } | ||
117 | + }, | ||
118 | + { | ||
119 | + "type": "action", | ||
120 | + "action": { | ||
121 | + "type": "message", | ||
122 | + "label": "베트남어", | ||
123 | + "text": "베트남어" | ||
124 | + } | ||
125 | + } | ||
126 | + ] | ||
127 | + } | ||
128 | + } | ||
129 | + }, | ||
130 | + { | ||
131 | + "bounds": { | ||
132 | + "x": 400, | ||
133 | + "y": 540, | ||
134 | + "width": 400, | ||
135 | + "height": 270 | ||
136 | + }, | ||
137 | + "action": { | ||
138 | + "type": "message", | ||
139 | + "text": "음성 듣기를 수행합니다." | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | +] | ||
144 | +}' | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
... | @@ -5,12 +5,14 @@ | ... | @@ -5,12 +5,14 @@ |
5 | "main": "app.js", | 5 | "main": "app.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
8 | - "start": "node server.js" | 8 | + "start": "node app.js" |
9 | }, | 9 | }, |
10 | "author": "강수인", | 10 | "author": "강수인", |
11 | "license": "MIT", | 11 | "license": "MIT", |
12 | "dependencies": { | 12 | "dependencies": { |
13 | "@line/bot-sdk": "^6.4.0", | 13 | "@line/bot-sdk": "^6.4.0", |
14 | - "express": "^4.16.4" | 14 | + "babel": "^6.23.0", |
15 | + "express": "^4.17.1", | ||
16 | + "request": "^2.88.0" | ||
15 | } | 17 | } |
16 | } | 18 | } | ... | ... |
-
Please register or login to post a comment