박찬수

reply, soccer commit

...@@ -74,3 +74,48 @@ try { ...@@ -74,3 +74,48 @@ try {
74 console.log(error); 74 console.log(error);
75 } 75 }
76 76
77 +module.exports = {
78 + StartReply : function(){
79 + app.post('/hook', function (req, res) {
80 +
81 + var eventObj = req.body.events[0];
82 + var source = eventObj.source;
83 + var message = eventObj.message;
84 +
85 + // request log
86 + console.log('======================', new Date() ,'======================');
87 + console.log('[request]', req.body);
88 + console.log('[request source] ', eventObj.source);
89 + console.log('[request message]', eventObj.message);
90 + console.log("Receive Message : ", eventObj.message.text);
91 +
92 + console.log(soccer.GetPlayerInfo(276, 2019));
93 +
94 + request.post(
95 + {
96 + url: TARGET_URL,
97 + headers: {
98 + 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
99 + },
100 + json: {
101 + "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
102 + "messages":[
103 + {
104 + "type":"text",
105 + "text":"Hello, user"
106 + },
107 + {
108 + "type":"text",
109 + "text":"May I help you?"
110 + }
111 + ]
112 + }
113 + },(error, response, body) => {
114 + console.log(body);
115 + });
116 +
117 +
118 + res.sendStatus(200);
119 + });
120 + }
121 +}
...\ No newline at end of file ...\ No newline at end of file
......
1 +var reply = require('./reply.js');
2 +
1 module.exports = { 3 module.exports = {
2 GetPlayerInfo : function(playerID, season){ 4 GetPlayerInfo : function(playerID, season){
3 var request = require('request'); 5 var request = require('request');
...@@ -13,6 +15,7 @@ module.exports = { ...@@ -13,6 +15,7 @@ module.exports = {
13 request(options, function (error, response) { 15 request(options, function (error, response) {
14 if (error) throw new Error(error); 16 if (error) throw new Error(error);
15 console.log(response.body); 17 console.log(response.body);
18 + reply.StartReply();
16 }); 19 });
17 } 20 }
18 -} 21 +}
...\ No newline at end of file ...\ No newline at end of file
......