suhyunpark

image test

Showing 1 changed file with 88 additions and 39 deletions
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 = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
5 +// const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
6 +// const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
7 +// const fs = require('fs');
8 +// const path = require('path');
9 +// const HTTPS = require('https');
10 +// const domain = "2019102175.oss-2021.tk"
11 +// const sslport = 23023;
12 +
13 +
1 var express = require('express'); 14 var express = require('express');
2 const request = require('request'); 15 const request = require('request');
3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 16 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = 'dClDD+86CVGoR/ozUsC1ViT0lyRMsFwQ3bOoUejOVI4yJ2AQRKHFyBF+CjYW5DLtF7EztDgigy+VSDFQxYNtvGqLGngGNYz1Fzq6kxxI7YqlDnVRV7gHFVkc42VfcEMQ/ozXTqeCY1JYFAmw30fBXQdB04t89/1O/w1cDnyilFU=' 17 +const TOKEN = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
5 -const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
6 -const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
7 const fs = require('fs'); 18 const fs = require('fs');
8 const path = require('path'); 19 const path = require('path');
9 const HTTPS = require('https'); 20 const HTTPS = require('https');
10 -const domain = "2019102195.oss2021.tk" 21 +const domain = "2019102175.oss-2021.tk"
11 const sslport = 23023; 22 const sslport = 23023;
12 23
24 +const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
25 +const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
26 +const USER_ID = 'Ub99bb2ebebbbc1e06efe715b76ec9fcd'
27 +
13 const bodyParser = require('body-parser'); 28 const bodyParser = require('body-parser');
14 var app = express(); 29 var app = express();
15 30
...@@ -20,23 +35,26 @@ request.post( ...@@ -20,23 +35,26 @@ request.post(
20 'Authorization': `Bearer ${TOKEN}` 35 'Authorization': `Bearer ${TOKEN}`
21 }, 36 },
22 json: { 37 json: {
23 - "messages":[ 38 + "messages": [
39 + {
40 + "type": "text",
41 + "text": "안녕하세요! "
42 + },
24 { 43 {
25 - "type":"text", 44 + "type": "text",
26 - "text":"안녕하세요! 테스트입니다." 45 + "text": "제시되는 4가지 사진 중 자신의 피부와 가장 잘 어울리는 사진의 번호를 입력하세요"
27 }, 46 },
28 { 47 {
29 - "type":"text", 48 + "type": "text",
30 - "text":"저에게 '테스트'라고 입력해주세요!" 49 + "text": "퍼스널 컬러 진단 테스트를 시작하시겠습니까? [Y/N]"
31 } 50 }
32 ] 51 ]
33 } 52 }
34 - },(error, response, body) => { 53 + }, (error, response, body) => {
35 console.log(body) 54 console.log(body)
36 }); 55 });
37 56
38 57
39 -
40 app.use(bodyParser.json()); 58 app.use(bodyParser.json());
41 app.post('/hook', function (req, res) { 59 app.post('/hook', function (req, res) {
42 60
...@@ -44,13 +62,16 @@ app.post('/hook', function (req, res) { ...@@ -44,13 +62,16 @@ app.post('/hook', function (req, res) {
44 var source = eventObj.source; 62 var source = eventObj.source;
45 var message = eventObj.message; 63 var message = eventObj.message;
46 64
47 - // request log
48 - console.log('======================', new Date() ,'======================');
49 - console.log('[request]', req.body);
50 - console.log('[request source] ', eventObj.source);
51 - console.log('[request message]', eventObj.message);
52 65
53 - if(eventObj.message.text=='테스트'){ 66 + start(eventObj.replyToken, eventObj.message.text);
67 + test1(eventObj.replyToken, eventObj.message.text);
68 +
69 +
70 + res.sendStatus(200);
71 +});
72 +
73 +function start(replyToken, message) {
74 + if (message == "Y") {
54 request.post( 75 request.post(
55 { 76 {
56 url: TARGET_URL, 77 url: TARGET_URL,
...@@ -58,45 +79,73 @@ app.post('/hook', function (req, res) { ...@@ -58,45 +79,73 @@ app.post('/hook', function (req, res) {
58 'Authorization': `Bearer ${TOKEN}` 79 'Authorization': `Bearer ${TOKEN}`
59 }, 80 },
60 json: { 81 json: {
61 - "replyToken":eventObj.replyToken, 82 + "replyToken": replyToken,
62 - "messages":[ 83 + "messages": [
84 + {
85 + "type": "image",
86 + "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
87 + "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
88 + },
89 + {
90 + "type": "image",
91 + "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
92 + "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
93 + },
63 { 94 {
64 - "type":"text", 95 + "type": "image",
65 - "text":"테스트라고 입력해주셨군요!" 96 + "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
97 + "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
66 }, 98 },
67 { 99 {
68 - "type":"text", 100 + "type": "image",
69 - "text":"다음 단계로 넘어가고 싶으신가요? [Y/N]" 101 + "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
102 + "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
103 + },
104 + ],
105 +
106 + }
107 + }, (error, response, body) => {
108 + console.log(body)
109 + });
110 + }
111 +}
112 +
113 +function test1(replyToken, message) {
114 + if (message == "네") {
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": "네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요"
70 } 127 }
71 ] 128 ]
72 } 129 }
73 - },(error, response, body) => { 130 + }, (error, response, body) => {
74 console.log(body) 131 console.log(body)
75 }); 132 });
76 } 133 }
77 -
78 -
79 - res.sendStatus(200);
80 -});
81 -
82 -function color_chatbot_test1(replyToken, message){
83 -
84 } 134 }
85 135
86 136
87 137
88 try { 138 try {
89 const option = { 139 const option = {
90 - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), 140 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
91 - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), 141 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
92 - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), 142 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
93 }; 143 };
94 - 144 +
95 HTTPS.createServer(option, app).listen(sslport, () => { 145 HTTPS.createServer(option, app).listen(sslport, () => {
96 - console.log(`[HTTPS] Server is started on port ${sslport}`); 146 + console.log(`[HTTPS] Server is started on port ${sslport}`);
97 }); 147 });
98 - } catch (error) { 148 +} catch (error) {
99 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); 149 console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
100 console.log(error); 150 console.log(error);
101 - }
102 -
...\ No newline at end of file ...\ No newline at end of file
151 +}
......