오규림

basic function

Showing 1 changed file with 94 additions and 74 deletions
var express = require("express");
var http = require("http");
var bodyParser = require("body-parser");
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'dClDD+86CVGoR/ozUsC1ViT0lyRMsFwQ3bOoUejOVI4yJ2AQRKHFyBF+CjYW5DLtF7EztDgigy+VSDFQxYNtvGqLGngGNYz1Fzq6kxxI7YqlDnVRV7gHFVkc42VfcEMQ/ozXTqeCY1JYFAmw30fBXQdB04t89/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 = "2019102195.oss2021.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
app.get("/Personal_color_chatbot", function (req, res) {
var data = {
type: "buttons",
buttons: ["퍼스널 컬러 진단하기", "봄웜", "여름쿨", "가을웜", "겨울쿨"],
};
res.json(data);
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post("/message", function (req, res) {
var msg = req.body.content;
console.log("전달받은 메세지: " + msg);
var send = {};
switch (msg) {
case "퍼스널 컬러 진단하기":
send = {
message: {
text: "퍼스널 컬러 진단하기 선택",
},
};
break;
case "봄웜":
send = {
message: {
text: "봄웜 선택",
},
};
break;
case "여름쿨":
send = {
message: {
text: "여름쿨 선택",
request.post(
{
url: BROAD_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
};
break;
json: {
"messages":[
{
"type":"text",
"text":"안녕하세요! 테스트입니다."
},
{
"type":"text",
"text":"저에게 '테스트'라고 입력해주세요!"
}
]
}
},(error, response, body) => {
console.log(body)
});
case "가을웜":
send = {
message: {
text: "가을웜 선택",
},
};
break;
case "겨울쿨":
send = {
message: {
text: "겨을쿨 선택",
},
};
break;
default:
send = {
message: {
text: "알 수 없는 명령입니다.",
},
};
break;
}
res.json(send);
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
if(eventObj.message.text=='테스트'){
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":eventObj.replyToken,
"messages":[
{
"type":"text",
"text":"테스트라고 입력해주셨군요!"
},
{
"type":"text",
"text":"다음 단계로 넘어가고 싶으신가요? [Y/N]"
}
]
}
},(error, response, body) => {
console.log(body)
});
}
res.sendStatus(200);
});
http.createServer(app).listen(9090, function () {
console.log("서버실행중..");
});
function color_chatbot_test1(replyToken, message){
}
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);
}
\ No newline at end of file
......