Showing
3 changed files
with
0 additions
and
239 deletions
file02_sync.txt
deleted
100644 → 0
1 | -hello | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
file_write.js
deleted
100644 → 0
1 | -var fs = require('fs'); | ||
2 | - | ||
3 | -fs.readFile('getids.js', 'utf-8', function(error, data) { | ||
4 | - console.log('01 readAsync: %s',data); | ||
5 | - if(error){ | ||
6 | - try{ | ||
7 | - fs.writeFileSync('file02_sync.txt', "hello", 'utf-8'); | ||
8 | - console.log('02 WRITE DONE!'); | ||
9 | - }catch(e){ | ||
10 | - console.log(e); | ||
11 | - } | ||
12 | - } | ||
13 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
script.js
deleted
100644 → 0
1 | -const request = require('request'); | ||
2 | -const TARGET_URL = 'https://api.line.me/v2/bot/message/push' | ||
3 | -const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | ||
4 | -const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | ||
5 | -const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU=' | ||
6 | -const USER_ID = '사Uc4258407a7677769f74ba184ec036651' | ||
7 | - | ||
8 | -var express = require('express'); | ||
9 | -//const request = require('request'); | ||
10 | -const fs = require('fs'); | ||
11 | -const path = require('path'); | ||
12 | -const HTTPS = require('https'); | ||
13 | -const domain = "2018102191.osschatbot2022.tk" | ||
14 | -const sslport = 23023; | ||
15 | - | ||
16 | -// Reply Script | ||
17 | - | ||
18 | -const bodyParser = require('body-parser'); | ||
19 | -var app = express(); | ||
20 | -app.use(bodyParser.json()); | ||
21 | -app.post('/hook', function (req, res) { | ||
22 | - | ||
23 | - var eventObj = req.body.events[0]; | ||
24 | - var source = eventObj.source; | ||
25 | - var message = eventObj.message; | ||
26 | - | ||
27 | - // request log | ||
28 | - console.log('======================', new Date() ,'======================'); | ||
29 | - console.log('[request]', req.body); | ||
30 | - console.log('[request source] ', eventObj.source); | ||
31 | - console.log('[request message]', eventObj.message); | ||
32 | - | ||
33 | - request.post( | ||
34 | - { | ||
35 | - url: TARGET_URL, | ||
36 | - headers: { | ||
37 | - 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증. | ||
38 | - }, | ||
39 | - json: { | ||
40 | - "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해! | ||
41 | - "messages":[ | ||
42 | - { | ||
43 | - "type":"text", | ||
44 | - "text":"Hello, user" | ||
45 | - }, | ||
46 | - { | ||
47 | - "type":"text", | ||
48 | - "text":"May I help you?" | ||
49 | - } | ||
50 | - ] | ||
51 | - } | ||
52 | - },(error, response, body) => { | ||
53 | - console.log(body) | ||
54 | - }); | ||
55 | - | ||
56 | - | ||
57 | - res.sendStatus(200); | ||
58 | -}); | ||
59 | - | ||
60 | -try { | ||
61 | - const option = { | ||
62 | - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
63 | - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
64 | - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
65 | - }; | ||
66 | - | ||
67 | - HTTPS.createServer(option, app).listen(sslport, () => { | ||
68 | - console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
69 | - }); | ||
70 | - } catch (error) { | ||
71 | - console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
72 | - console.log(error); | ||
73 | - } | ||
74 | - | ||
75 | -// Push Script | ||
76 | - | ||
77 | -function SinglePush() | ||
78 | -{ | ||
79 | - request.post( | ||
80 | - { | ||
81 | - url: TARGET_URL, | ||
82 | - headers: { | ||
83 | - 'Authorization': `Bearer ${TOKEN}` | ||
84 | - }, | ||
85 | - json: { | ||
86 | - "to": `${USER_ID}`, | ||
87 | - "messages":[ | ||
88 | - { | ||
89 | - "type":"text", | ||
90 | - "text":"Hello, user" | ||
91 | - }, | ||
92 | - { | ||
93 | - "type":"text", | ||
94 | - "text":"May I help you?" | ||
95 | - } | ||
96 | - ] | ||
97 | - } | ||
98 | - },(error, response, body) => { | ||
99 | - console.log(body) | ||
100 | - }); | ||
101 | -} | ||
102 | - | ||
103 | -function MultiPush() | ||
104 | -{ | ||
105 | - request.post( | ||
106 | - { | ||
107 | - url: MULTI_TARGET_URL, | ||
108 | - headers: { | ||
109 | - 'Authorization': `Bearer ${TOKEN}` | ||
110 | - }, | ||
111 | - json: { | ||
112 | - "to": [`${USER_ID}`], | ||
113 | - "messages":[ | ||
114 | - { | ||
115 | - "type":"text", | ||
116 | - "text":"Hello, user" | ||
117 | - }, | ||
118 | - { | ||
119 | - "type":"text", | ||
120 | - "text":"May I help you?" | ||
121 | - } | ||
122 | - ] | ||
123 | - } | ||
124 | - },(error, response, body) => { | ||
125 | - console.log(body) | ||
126 | - }); | ||
127 | -} | ||
128 | - | ||
129 | -function BroadCast() | ||
130 | -{ | ||
131 | - request.post( | ||
132 | - { | ||
133 | - url: BROAD_TARGET_URL, | ||
134 | - headers: { | ||
135 | - 'Authorization': `Bearer ${TOKEN}` | ||
136 | - }, | ||
137 | - json: { | ||
138 | - "messages":[ | ||
139 | - { | ||
140 | - "type":"text", | ||
141 | - "text":"Hello, user" | ||
142 | - }, | ||
143 | - { | ||
144 | - "type":"text", | ||
145 | - "text":"May I help you?" | ||
146 | - } | ||
147 | - ] | ||
148 | - } | ||
149 | - },(error, response, body) => { | ||
150 | - console.log(body) | ||
151 | - }); | ||
152 | -} | ||
153 | - | ||
154 | -// Single User | ||
155 | -// request.post( | ||
156 | -// { | ||
157 | -// url: TARGET_URL, | ||
158 | -// headers: { | ||
159 | -// 'Authorization': `Bearer ${TOKEN}` | ||
160 | -// }, | ||
161 | -// json: { | ||
162 | -// "to": `${USER_ID}`, | ||
163 | -// "messages":[ | ||
164 | -// { | ||
165 | -// "type":"text", | ||
166 | -// "text":"Hello, user" | ||
167 | -// }, | ||
168 | -// { | ||
169 | -// "type":"text", | ||
170 | -// "text":"May I help you?" | ||
171 | -// } | ||
172 | -// ] | ||
173 | -// } | ||
174 | -// },(error, response, body) => { | ||
175 | -// console.log(body) | ||
176 | -// }); | ||
177 | - | ||
178 | - | ||
179 | -// Multicast User | ||
180 | -// request.post( | ||
181 | -// { | ||
182 | -// url: MULTI_TARGET_URL, | ||
183 | -// headers: { | ||
184 | -// 'Authorization': `Bearer ${TOKEN}` | ||
185 | -// }, | ||
186 | -// json: { | ||
187 | -// "to": [`${USER_ID}`], | ||
188 | -// "messages":[ | ||
189 | -// { | ||
190 | -// "type":"text", | ||
191 | -// "text":"Hello, user" | ||
192 | -// }, | ||
193 | -// { | ||
194 | -// "type":"text", | ||
195 | -// "text":"May I help you?" | ||
196 | -// } | ||
197 | -// ] | ||
198 | -// } | ||
199 | -// },(error, response, body) => { | ||
200 | -// console.log(body) | ||
201 | -// }); | ||
202 | - | ||
203 | - | ||
204 | -// Broadcast | ||
205 | - // request.post( | ||
206 | - // { | ||
207 | - // url: BROAD_TARGET_URL, | ||
208 | - // headers: { | ||
209 | - // 'Authorization': `Bearer ${TOKEN}` | ||
210 | - // }, | ||
211 | - // json: { | ||
212 | - // "messages":[ | ||
213 | - // { | ||
214 | - // "type":"text", | ||
215 | - // "text":"Hello, user" | ||
216 | - // }, | ||
217 | - // { | ||
218 | - // "type":"text", | ||
219 | - // "text":"May I help you?" | ||
220 | - // } | ||
221 | - // ] | ||
222 | - // } | ||
223 | - // },(error, response, body) => { | ||
224 | - // console.log(body) | ||
225 | - // }); |
-
Please register or login to post a comment