Showing
1 changed file
with
43 additions
and
9 deletions
1 | const Address = require('./Address.js'); | 1 | const Address = require('./Address.js'); |
2 | const express = require('express'); | 2 | const express = require('express'); |
3 | +const request = require('request'); | ||
4 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
5 | +const TOKEN = '채널 토큰으로 변경' | ||
6 | +const fs = require('fs'); | ||
7 | +const path = require('path'); | ||
8 | +const HTTPS = require('https'); | ||
9 | +const domain = "도메인 변경" | ||
10 | +const sslport = 23023; | ||
11 | +const bodyParser = require('body-parser'); | ||
3 | const app = express(); | 12 | const app = express(); |
4 | 13 | ||
5 | 14 | ||
... | @@ -12,15 +21,40 @@ app.get('',(req,res)=> { | ... | @@ -12,15 +21,40 @@ app.get('',(req,res)=> { |
12 | res.send('tset') | 21 | res.send('tset') |
13 | }) | 22 | }) |
14 | 23 | ||
15 | -app.post('/hook', function(request,response){ | 24 | +app.post('/hook', function (req, res) { |
16 | - var eventObj = request.body.events[0]; | 25 | + var eventObj = req.body.events[0]; |
17 | - | 26 | + var source = eventObj.source; |
18 | - console.log("---------------",new Date(),"-----------------"); | 27 | + var message = eventObj.message; |
19 | - response.sendStatus(200); | 28 | + // request log |
20 | - | 29 | + console.log('======================', new Date() ,'======================'); |
21 | - | 30 | + console.log('[request]', req.body); |
22 | - | 31 | + console.log('[request source] ', eventObj.source); |
23 | -}) | 32 | + console.log('[request message]', eventObj.message); |
33 | + request.post( | ||
34 | + { | ||
35 | + url: TARGET_URL, | ||
36 | + headers: { | ||
37 | + 'Authorization': `Bearer ${TOKEN}` | ||
38 | + }, | ||
39 | + json: { | ||
40 | + "replyToken":eventObj.replyToken, | ||
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 | + res.sendStatus(200); | ||
57 | +}); | ||
24 | 58 | ||
25 | 59 | ||
26 | app.get('/keyboard', (req, res) => { | 60 | app.get('/keyboard', (req, res) => { | ... | ... |
-
Please register or login to post a comment