Showing
6 changed files
with
18 additions
and
43 deletions
| ... | @@ -50,6 +50,7 @@ app.listen(SERVER_PORT, () => { | ... | @@ -50,6 +50,7 @@ app.listen(SERVER_PORT, () => { |
| 50 | console.log("Server is running on port", process.env.SERVER_PORT); | 50 | console.log("Server is running on port", process.env.SERVER_PORT); |
| 51 | }); | 51 | }); |
| 52 | 52 | ||
| 53 | +//for Line Channel | ||
| 53 | try { | 54 | try { |
| 54 | const option = { | 55 | const option = { |
| 55 | ca: fs.readFileSync('/etc/letsencrypt/live/' + DOMAIN +'/fullchain.pem'), | 56 | ca: fs.readFileSync('/etc/letsencrypt/live/' + DOMAIN +'/fullchain.pem'), | ... | ... |
| 1 | const Router = require("koa-router"); | 1 | const Router = require("koa-router"); |
| 2 | const auth = new Router(); | 2 | const auth = new Router(); |
| 3 | const authCtrl = require("./auth.ctrl"); | 3 | const authCtrl = require("./auth.ctrl"); |
| 4 | -const kakaoAuth = require("./kakaoAuth"); | ||
| 5 | 4 | ||
| 6 | auth.post("/login", authCtrl.login); | 5 | auth.post("/login", authCtrl.login); |
| 7 | auth.post("/logout", authCtrl.logout); | 6 | auth.post("/logout", authCtrl.logout); |
| 8 | auth.post("/register", authCtrl.register); | 7 | auth.post("/register", authCtrl.register); |
| 9 | auth.get("/check", authCtrl.check); | 8 | auth.get("/check", authCtrl.check); |
| 10 | 9 | ||
| 11 | -auth.post("/kakaotoken", kakaoAuth.kakaotoken); | ||
| 12 | - | ||
| 13 | module.exports = auth; | 10 | module.exports = auth; | ... | ... |
| 1 | -const request = require('request'); | ||
| 2 | -const querystring = require('querystring'); | ||
| 3 | - | ||
| 4 | - | ||
| 5 | -exports.kakaotoken = async (ctx) => { | ||
| 6 | - const token = ctx.request.body; | ||
| 7 | - | ||
| 8 | - 'http://kapi.kakao.com/v2/api/talk/memo/default/send' | ||
| 9 | - | ||
| 10 | - console.log(ctx); | ||
| 11 | - console.log("token setted", token); | ||
| 12 | - let template_objectObj = { | ||
| 13 | - object_type: "text", | ||
| 14 | - text: "hi", link: { | ||
| 15 | - web_url: "https://developers.kakao.com", | ||
| 16 | - } | ||
| 17 | - }; | ||
| 18 | - | ||
| 19 | - let template_objectStr = JSON.stringify(template_objectObj); | ||
| 20 | - console.log(template_objectStr); | ||
| 21 | - let options = { | ||
| 22 | - url: "http://kapi.kakao.com/v2/api/talk/memo/default/send", | ||
| 23 | - method: "POST", | ||
| 24 | - headers: { | ||
| 25 | - "Authorization": "Bearer ".concat(token), | ||
| 26 | - "Content-Type": "application/x-www-form-urlencoded" | ||
| 27 | - }, form: { | ||
| 28 | - template_object: template_objectStr | ||
| 29 | - } | ||
| 30 | - }; | ||
| 31 | - request.post(options, (err, res, body) => { | ||
| 32 | - if (err != null) { | ||
| 33 | - console.log(err); | ||
| 34 | - } | ||
| 35 | - }); | ||
| 36 | -}; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
jaksimsamil-server/src/api/line/README.md
0 → 100644
File mode changed
| ... | @@ -8,8 +8,17 @@ const Profile = require("../../models/profile"); | ... | @@ -8,8 +8,17 @@ const Profile = require("../../models/profile"); |
| 8 | const problem_set = require("../../data/problem_set"); | 8 | const problem_set = require("../../data/problem_set"); |
| 9 | const compareBJ = require("../../util/compareBJ"); | 9 | const compareBJ = require("../../util/compareBJ"); |
| 10 | 10 | ||
| 11 | +/* | ||
| 12 | + username : default = "" | ||
| 13 | +*/ | ||
| 11 | let username = ""; | 14 | let username = ""; |
| 12 | 15 | ||
| 16 | +/* | ||
| 17 | +POST api/line/hook | ||
| 18 | +{ | ||
| 19 | + for line reply : recommend and set | ||
| 20 | +} | ||
| 21 | + */ | ||
| 13 | exports.linestart = async(ctx) => { | 22 | exports.linestart = async(ctx) => { |
| 14 | var eventObj = ctx.request.body.events[0]; | 23 | var eventObj = ctx.request.body.events[0]; |
| 15 | 24 | ||
| ... | @@ -20,6 +29,7 @@ exports.linestart = async(ctx) => { | ... | @@ -20,6 +29,7 @@ exports.linestart = async(ctx) => { |
| 20 | console.log('[request message]', eventObj.message); | 29 | console.log('[request message]', eventObj.message); |
| 21 | console.log('[username]', username); | 30 | console.log('[username]', username); |
| 22 | 31 | ||
| 32 | + //first . set User | ||
| 23 | if(username == "") { | 33 | if(username == "") { |
| 24 | username = eventObj.message.text; | 34 | username = eventObj.message.text; |
| 25 | 35 | ||
| ... | @@ -38,7 +48,7 @@ exports.linestart = async(ctx) => { | ... | @@ -38,7 +48,7 @@ exports.linestart = async(ctx) => { |
| 38 | "messages":[ | 48 | "messages":[ |
| 39 | { | 49 | { |
| 40 | "type":"text", | 50 | "type":"text", |
| 41 | - "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." | 51 | + "text": "작심삼일 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." |
| 42 | } | 52 | } |
| 43 | ] | 53 | ] |
| 44 | } | 54 | } |
| ... | @@ -67,7 +77,7 @@ exports.linestart = async(ctx) => { | ... | @@ -67,7 +77,7 @@ exports.linestart = async(ctx) => { |
| 67 | } | 77 | } |
| 68 | }; | 78 | }; |
| 69 | 79 | ||
| 70 | - | 80 | + //second. can reset username |
| 71 | if(eventObj.message.text == "reset ID") { | 81 | if(eventObj.message.text == "reset ID") { |
| 72 | username = ""; | 82 | username = ""; |
| 73 | request.post( | 83 | request.post( |
| ... | @@ -81,7 +91,7 @@ exports.linestart = async(ctx) => { | ... | @@ -81,7 +91,7 @@ exports.linestart = async(ctx) => { |
| 81 | "messages":[ | 91 | "messages":[ |
| 82 | { | 92 | { |
| 83 | "type":"text", | 93 | "type":"text", |
| 84 | - "text": "작심삼일 혹은 백준 사이트의 ID가 초기화 되었습니다." | 94 | + "text": "작심삼일 사이트의 ID가 초기화 되었습니다." |
| 85 | } | 95 | } |
| 86 | ] | 96 | ] |
| 87 | } | 97 | } |
| ... | @@ -90,7 +100,7 @@ exports.linestart = async(ctx) => { | ... | @@ -90,7 +100,7 @@ exports.linestart = async(ctx) => { |
| 90 | }); | 100 | }); |
| 91 | } | 101 | } |
| 92 | 102 | ||
| 93 | - | 103 | + //main : recommend Problem |
| 94 | if(eventObj.message.text == "문제") { | 104 | if(eventObj.message.text == "문제") { |
| 95 | console.log("문제를 추천합니다."); | 105 | console.log("문제를 추천합니다."); |
| 96 | let recommendData = await lineRecommend(username); | 106 | let recommendData = await lineRecommend(username); |
| ... | @@ -101,6 +111,7 @@ exports.linestart = async(ctx) => { | ... | @@ -101,6 +111,7 @@ exports.linestart = async(ctx) => { |
| 101 | 111 | ||
| 102 | } | 112 | } |
| 103 | 113 | ||
| 114 | +//for recommend message | ||
| 104 | function recommendBJ(replyToken, recommendData) { | 115 | function recommendBJ(replyToken, recommendData) { |
| 105 | var recommendProblem = "오늘의 추천문제는 " + recommendData.problem_title + "입니다."; | 116 | var recommendProblem = "오늘의 추천문제는 " + recommendData.problem_title + "입니다."; |
| 106 | var problemURL = "https://www.boj.kr/" + recommendData.problem_number; | 117 | var problemURL = "https://www.boj.kr/" + recommendData.problem_number; | ... | ... |
| 1 | const Router = require("koa-router"); | 1 | const Router = require("koa-router"); |
| 2 | const profile = new Router(); | 2 | const profile = new Router(); |
| 3 | const profileCtrl = require("./profile.ctrl"); | 3 | const profileCtrl = require("./profile.ctrl"); |
| 4 | + | ||
| 4 | profile.post("/solved:id"); | 5 | profile.post("/solved:id"); |
| 5 | profile.get("/solvednum:id"); | 6 | profile.get("/solvednum:id"); |
| 6 | profile.post("/recommend", profileCtrl.recommend); | 7 | profile.post("/recommend", profileCtrl.recommend); |
| 7 | profile.patch("/syncBJ", profileCtrl.syncBJ); | 8 | profile.patch("/syncBJ", profileCtrl.syncBJ); |
| 8 | profile.post("/setprofile", profileCtrl.setProfile); | 9 | profile.post("/setprofile", profileCtrl.setProfile); |
| 9 | profile.post("/getprofile", profileCtrl.getProfile); | 10 | profile.post("/getprofile", profileCtrl.getProfile); |
| 11 | + | ||
| 10 | module.exports = profile; | 12 | module.exports = profile; | ... | ... |
-
Please register or login to post a comment