장재훈

챔피언 정보 출력 기능 추가

Showing 1 changed file with 33 additions and 47 deletions
......@@ -2,7 +2,7 @@ const express = require('express');
const app = express();
const logger = require('morgan');
const bodyParser = require('body-parser');
const fs = require('fs');
const apiRouter = express.Router();
app.use(logger('dev', {}));
......@@ -13,42 +13,50 @@ app.use(bodyParser.urlencoded({
app.use('/api', apiRouter);
apiRouter.post('/sayHello', function(req, res) {
apiRouter.post('/champion', function(req, res) {
console.log(req.body)
const championName = req["detailParams"]["champion_name"]["value"];
let championRawData = fs.readFileSync('data/json data/champions.json');
let championData = JSON.parse(championRawData);
var i = 0;
for (i; i < championData.length; ++i){
if(championData[i].name == championName){
break;
}
};
const championQuery = (championData[i].championID).replace(/"TF3_"/g,'');
const responseBody = {
version: "2.0",
template: {
outputs: [
"version": "2.0",
"template": {
"outputs": [
{
simpleText: {
text: "hello I'm Ryan"
"basicCard": {
"title": championName,
"description": "비용 : " + championData[i].cost + "\n" + "시너지 : " + championData[i].traits,
"thumbnail": {
"imageUrl": "data/Image data/champions/" + championName + ".png"
},
"buttons": [
{
"action": "webLink",
"label": "상세한 정보 확인",
"webLinkUrl": "https://lolchess.gg/champions/set3.5/" + championQuery
}
]
}
}
]
}
};
}
res.status(200).send(responseBody);
});
apiRouter.post('/showHello', function(req, res) {
console.log(req.body);
const responseBody = {
version: "2.0",
template: {
outputs: [
{
simpleImage: {
imageUrl: "https://t1.daumcdn.net/friends/prod/category/M001_friends_ryan2.jpg",
altText: "hello I'm Ryan"
}
}
]
}
};
res.status(200).send(responseBody);
app.listen(23023, function() {
console.log('Example skill server listening on port 23023!');
});
/*
const fs = require('fs');
app.post('/champion',function(req,res){
......@@ -63,26 +71,4 @@ app.post('/champion',function(req,res){
}
}
})
app.get('/', function(req, res){
res.send('Hello, World!');
})
app.get('/test', function(req, res){
res.send('Hello, TEST!');
})
app.put('/oss', function(req, res){
res.send('Hello, OSS!');
})
app.get('/users/:userId/books/:bookId', function(req, res){
console.log(req.params.userId)
console.log(req.params.bookId)
res.send(req.params);
})
*/
app.listen(3000, function(){
console.log("Example skill server listening on port 3000!");
});
......