Showing
3 changed files
with
83 additions
and
0 deletions
reply/app.js
0 → 100644
| 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 = 'xAcMgunmVCPFumwQa+XlStTaxrW8Jjt3PJbulC/qoG4vDiMaJ4vJDWroCMYLzqDy7svDnUJvfdanKUQDn+yZgLh4axZcjUClOGZBWujleiD9QIMn/7l0YJkxmz1oCPlmIXb/z96Q0h3rINwxx6MxbQdB04t89/1O/w1cDnyilFU=' | ||
| 5 | +const fs = require('fs'); | ||
| 6 | +const path = require('path'); | ||
| 7 | +const HTTPS = require('https'); | ||
| 8 | +const domain = "www.osstest78910.ml" | ||
| 9 | +const sslport = 23023; | ||
| 10 | + | ||
| 11 | +const bodyParser = require('body-parser'); | ||
| 12 | +var app = express(); | ||
| 13 | +app.use(bodyParser.json()); | ||
| 14 | +app.post('/hook', function (req, res) { | ||
| 15 | + | ||
| 16 | + var eventObj = req.body.events[0]; | ||
| 17 | + var source = eventObj.source; | ||
| 18 | + var message = eventObj.message; | ||
| 19 | + | ||
| 20 | + // request log | ||
| 21 | + console.log('======================', new Date() ,'======================'); | ||
| 22 | + console.log('[request]', req.body); | ||
| 23 | + console.log('[request source] ', eventObj.source); | ||
| 24 | + console.log('[request message]', eventObj.message); | ||
| 25 | + | ||
| 26 | + request.post( | ||
| 27 | + { | ||
| 28 | + url: TARGET_URL, | ||
| 29 | + headers: { | ||
| 30 | + 'Authorization': `Bearer ${TOKEN}` | ||
| 31 | + }, | ||
| 32 | + json: { | ||
| 33 | + "replyToken":eventObj.replyToken, | ||
| 34 | + "messages":[ | ||
| 35 | + { | ||
| 36 | + "type":"text", | ||
| 37 | + "text":"Hello, user" | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + "type":"text", | ||
| 41 | + "text":"May I help you?" | ||
| 42 | + } | ||
| 43 | + ] | ||
| 44 | + } | ||
| 45 | + },(error, response, body) => { | ||
| 46 | + console.log(body) | ||
| 47 | + }); | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + res.sendStatus(200); | ||
| 51 | +}); | ||
| 52 | + | ||
| 53 | +try { | ||
| 54 | + const option = { | ||
| 55 | + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | ||
| 56 | + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | ||
| 57 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
| 58 | + }; | ||
| 59 | + | ||
| 60 | + HTTPS.createServer(option, app).listen(sslport, () => { | ||
| 61 | + console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
| 62 | + }); | ||
| 63 | + } catch (error) { | ||
| 64 | + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
| 65 | + console.log(error); | ||
| 66 | + } | ||
| 67 | + |
reply/package-lock.json
0 → 100644
This diff is collapsed. Click to expand it.
reply/package.json
0 → 100644
| 1 | +{ | ||
| 2 | + "name": "reply", | ||
| 3 | + "version": "1.0.0", | ||
| 4 | + "description": "", | ||
| 5 | + "main": "app.js", | ||
| 6 | + "scripts": { | ||
| 7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
| 8 | + }, | ||
| 9 | + "author": "", | ||
| 10 | + "license": "ISC", | ||
| 11 | + "dependencies": { | ||
| 12 | + "body-parser": "^1.19.0", | ||
| 13 | + "express": "^4.17.1", | ||
| 14 | + "request": "^2.88.2" | ||
| 15 | + } | ||
| 16 | +} |
-
Please register or login to post a comment