app.js
7.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// var express = require('express');
// const request = require('request');
// const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
// const TOKEN = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
// const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
// const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
// const fs = require('fs');
// const path = require('path');
// const HTTPS = require('https');
// const domain = "2019102175.oss-2021.tk"
// const sslport = 23023;
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2019102175.oss-2021.tk"
const sslport = 23023;
var spring = 0
var summer = 0
var fall = 0
var winter = 0
var files = [
'https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png',
'https://www.colorcombos.com/images/colors/990000.png'
// 'https://plainbackground.com/download.php?imagename=5b0000.png',
// 'https://www.solidbackgrounds.com/images/2048x2048/2048x2048-red-munsell-solid-color-background.jpg',
// 'https://www.cmu.edu/brand/brand-guidelines/images/colors-carnegie-red-600x600.png',
// 'https://3.imimg.com/data3/FO/EO/MY-149995/lake-amaranth-food-color-250x250.jpg'
]
var previews = [
'https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png',
'https://www.colorcombos.com/images/colors/990000/preview.png'
]
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const USER_ID = 'Ub99bb2ebebbbc1e06efe715b76ec9fcd'
const bodyParser = require('body-parser');
var app = express();
request.post(
{
url: BROAD_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"messages": [
{
"type": "text",
"text": "안녕하세요! "
},
{
"type": "text",
"text": "제시되는 4가지 사진 중 자신의 피부와 가장 잘 어울리는 사진의 번호를 입력하세요"
},
{
"type": "text",
"text": "퍼스널 컬러 진단 테스트를 시작하시겠습니까? [Y/N]"
}
]
}
}, (error, response, body) => {
console.log(body)
});
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
test1(eventObj.replyToken, eventObj.message.text)
test2(eventObj.replyToken, eventObj.message.text)
res.sendStatus(200);
});
function test1(replyToken, message) {
if (message == "Y") {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "test1"
},
{
"type": "image",
// "originalContentUrl": files[i],
// "previewImageUrl": previews[i],
"originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
"previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
}
function test2(replyToken, message) {
if (message == "1" || message == "2" || message == "3" || message == "4") {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "test2"
},
{
"type": "image",
"originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
"previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
{
"type": "image",
"originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
"previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
{
"type": "image",
"originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
"previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
{
"type": "image",
"originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
"previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
},
],
}
}, (error, response, body) => {
console.log(body)
});
}
if (message == "1") spring += 1
else if (message == "2") summer += 1
else if (message == "3") fall += 1
else if (message == "4") winter += 1
console.log(spring, summer, fall, winter)
}
function start(replyToken, message) {
if (message == "Y") {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": "네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요"
}
]
}
}, (error, response, body) => {
console.log(body)
});
}
}
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
};
HTTPS.createServer(option, app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}