Showing
2 changed files
with
84 additions
and
67 deletions
... | @@ -5,14 +5,15 @@ let request = require('request'), | ... | @@ -5,14 +5,15 @@ let request = require('request'), |
5 | 5 | ||
6 | // Handles message events | 6 | // Handles message events |
7 | exports.handleMessage = (sender_psid, received_message) => { | 7 | exports.handleMessage = (sender_psid, received_message) => { |
8 | - let response; | 8 | + let payload = recieved_message.payload; |
9 | 9 | ||
10 | - if(received_message.text){ | 10 | + if(payload === 'CHOICE_BY_PROF'){ |
11 | - response = template.messageTemplate(); | 11 | + handlePostback_choiceByProf(sender_psid, received_message); |
12 | + }else if(payload === 'CHOICE_BY_LECT'){ | ||
13 | + handlePostback_choiceByLect(sender_psid, recieved_message); | ||
14 | + }else if(payload === 'HELP'){ | ||
15 | + handlePostback_help(sender_psid, recieved_message); | ||
12 | } | 16 | } |
13 | - | ||
14 | - // Sends the reponse message | ||
15 | - callSendAPI(sender_psid, response); | ||
16 | } | 17 | } |
17 | 18 | ||
18 | exports.handlePostback = (sender_psid, received_postback) => { | 19 | exports.handlePostback = (sender_psid, received_postback) => { |
... | @@ -26,20 +27,60 @@ exports.handlePostback = (sender_psid, received_postback) => { | ... | @@ -26,20 +27,60 @@ exports.handlePostback = (sender_psid, received_postback) => { |
26 | response = template.greetingTemplate(); | 27 | response = template.greetingTemplate(); |
27 | callSendAPI(sender_psid, response); | 28 | callSendAPI(sender_psid, response); |
28 | }else if(payload === 'CHOICE_BY_PROF'){ | 29 | }else if(payload === 'CHOICE_BY_PROF'){ |
29 | - response = template.choicebyprofTemplate(); | 30 | + handlePostback_choiceByProf(sender_psid, received_postback); |
30 | - callSendAPI(sender_psid, response); | ||
31 | }else if(payload === 'CHOICE_BY_LECT'){ | 31 | }else if(payload === 'CHOICE_BY_LECT'){ |
32 | - response = template.choicebylectTemplate(); | 32 | + handlePostback_choiceByLect(sender_psid, recieved_postback); |
33 | - callSendAPI(sender_psid, response); | ||
34 | }else if(payload === 'HELP'){ | 33 | }else if(payload === 'HELP'){ |
35 | - response = template.help(); | 34 | + handlePostback_help(sender_psid, recieved_postback); |
36 | - callSendAPI(sender_psid, response); | ||
37 | - }else if(payload.match('rate')){ | ||
38 | - response = template.rate(payload); | ||
39 | - callSendAPI(sender_psid, response); | ||
40 | } | 35 | } |
41 | } | 36 | } |
42 | 37 | ||
38 | +const handlePostback_choiceByProf = (sender_psid, received) => { | ||
39 | + let response; | ||
40 | + | ||
41 | + let stat = received.stat; | ||
42 | + | ||
43 | + if(stat === 'stat_0'){ | ||
44 | + response = template.getProfNameTemplate(received); | ||
45 | + }else if(stat === 'stat_1'){ | ||
46 | + response = template.choiceLectOfProfTemplate(received); | ||
47 | + }else if(stat === 'stat_2'){ | ||
48 | + response = template.rateTemplate(received); | ||
49 | + } | ||
50 | + callSendAPI(sender_psid, response); | ||
51 | +} | ||
52 | + | ||
53 | +const handlePostback_choiceByLect = (sender_psid, recieved) => { | ||
54 | + let response; | ||
55 | + | ||
56 | + let stat = recieved.stat; | ||
57 | + | ||
58 | + if(stat === 'stat_0'){ | ||
59 | + response = template.getLectNameTemplate(received); | ||
60 | + }else if(stat === 'stat_1'){ | ||
61 | + response = template.choiceLectTemplate(received); | ||
62 | + }else if(stat === 'stat_2'){ | ||
63 | + response = template.choiceProfOfLectTemplate(received); | ||
64 | + }else if(stat === 'stat_3'){ | ||
65 | + response = template.rateTemplate(received); | ||
66 | + }else if(stat === 'stat_4'){ | ||
67 | + response = template.goToChoiceByProfTemplate(received); | ||
68 | + } | ||
69 | + callSendAPI(sender_psid, response); | ||
70 | +} | ||
71 | + | ||
72 | +const handlePostback_help = (sender_psid, received) => { | ||
73 | + let response; | ||
74 | + | ||
75 | + let stat = received.stat; | ||
76 | + | ||
77 | + if(stat === 'stat_0'){ | ||
78 | + response = template.howToTemplate(received); | ||
79 | + }else if(stat ==== 'stat_1'){ | ||
80 | + response = template.goToGreetTemplate(received); | ||
81 | + } | ||
82 | + callSendAPI(sender_psid, response); | ||
83 | +} | ||
43 | 84 | ||
44 | // Sends response messages via the Send API | 85 | // Sends response messages via the Send API |
45 | const callSendAPI = (sender_psid, response, cb = null) => { | 86 | const callSendAPI = (sender_psid, response, cb = null) => { | ... | ... |
1 | -let images = require("./pics"); | ||
2 | - | ||
3 | -exports.messageTemplate = (text) => { | ||
4 | - //메세지 | ||
5 | -} | ||
6 | - | ||
7 | let greetingText = "안녕하세요! 컴공/소융 강의평가 봇이에요. 아래에 버튼 3개를 눌러주세요."; // 인사말 | 1 | let greetingText = "안녕하세요! 컴공/소융 강의평가 봇이에요. 아래에 버튼 3개를 눌러주세요."; // 인사말 |
8 | let greetingTitle = ["교수명으로 검색", "강의명으로 검색", "HELP"]; | 2 | let greetingTitle = ["교수명으로 검색", "강의명으로 검색", "HELP"]; |
9 | 3 | ||
... | @@ -19,17 +13,23 @@ exports.greetingTemplate = () => { | ... | @@ -19,17 +13,23 @@ exports.greetingTemplate = () => { |
19 | { | 13 | { |
20 | "type":"postback", | 14 | "type":"postback", |
21 | "title":greetingTitle[0], | 15 | "title":greetingTitle[0], |
22 | - "payload":"CHOICE_BY_PROF" | 16 | + "payload":"CHOICE_BY_PROF", |
17 | + "stat":"stat_0", | ||
18 | + "rate":{}; | ||
23 | }, | 19 | }, |
24 | { | 20 | { |
25 | "type":"postback", | 21 | "type":"postback", |
26 | "title":greetingTitle[1], | 22 | "title":greetingTitle[1], |
27 | "payload":"CHOICE_BY_LECT" | 23 | "payload":"CHOICE_BY_LECT" |
24 | + "stat":"stat_0", | ||
25 | + "rate":{}; | ||
28 | }, | 26 | }, |
29 | { | 27 | { |
30 | "type":"postback", | 28 | "type":"postback", |
31 | "title":greetingTitle[2], | 29 | "title":greetingTitle[2], |
32 | "payload":"HELP" | 30 | "payload":"HELP" |
31 | + "stat":"stat_0", | ||
32 | + "rate":{}; | ||
33 | } | 33 | } |
34 | ] | 34 | ] |
35 | } | 35 | } |
... | @@ -37,70 +37,46 @@ exports.greetingTemplate = () => { | ... | @@ -37,70 +37,46 @@ exports.greetingTemplate = () => { |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | -exports.choicebyprofTemplate = () => { | 40 | +//payload === 'CHOICE_BY_PROF' |
41 | - return {text: "교수명을 입력하세요."}; | 41 | +exports.getProfNameTemplate = (received) => { |
42 | - //교수님 성함 사용자 입력 받기 | ||
43 | - //교수님 목록 띄우기_버튼 | ||
44 | - //강의명 목록 띄우기_버튼 | ||
45 | - //->강의평가 띄우기 | ||
46 | -} | ||
47 | 42 | ||
48 | -exports.choicebylectTemplate = () => { | ||
49 | - //강의명 사용자 입력 받기 | ||
50 | - //일치하는 강의 없으면 추측 강의 목록 띄우기_버튼 | ||
51 | - //max n개 강의 목록 띄우기_버튼 | ||
52 | - //->그 중에 없으면 교수명 입력으로 | ||
53 | - //->있으면 강의평가 띄우기 | ||
54 | } | 43 | } |
55 | 44 | ||
56 | -exports.help = () => { | 45 | +exports.choiceLectOfProfTemplate = (received) => { |
57 | - //소개, 뒤로가기 | ||
58 | -} | ||
59 | 46 | ||
60 | -exports.rate = (payload) => { | ||
61 | - return {text:"강의평가입니다."}; | ||
62 | - //강의평가 | ||
63 | } | 47 | } |
64 | 48 | ||
49 | +exports.rateTemplate = (received) => { | ||
65 | 50 | ||
51 | +} | ||
66 | 52 | ||
53 | +//payload === 'CHOICE_BY_LECT' | ||
54 | +exports.getLectNameTemplate = (received) => { | ||
67 | 55 | ||
56 | +} | ||
68 | 57 | ||
58 | +exports.choiceLectTemplate= (received) => { | ||
69 | 59 | ||
60 | +} | ||
70 | 61 | ||
62 | +exports.choiceProfOfLectTemplate= (received) => { | ||
71 | 63 | ||
64 | +} | ||
72 | 65 | ||
66 | +exports.rateTemplate= (received) => { | ||
73 | 67 | ||
68 | +} | ||
74 | 69 | ||
70 | +exports.goToChoiceByProfTemplate= (received) => { | ||
75 | 71 | ||
72 | +} | ||
76 | 73 | ||
77 | -let users = {}; | 74 | +//payload === 'HELP' |
78 | - | 75 | +exports.howToTemplate= (received) => { |
79 | -const getImage= (type, sender_id) => { | ||
80 | - // create user if doesn't exist | ||
81 | - if(users[sender_id] === undefined){ | ||
82 | - users = Object.assign({ | ||
83 | - [sender_id] : { | ||
84 | - 'cats_count' : 0, | ||
85 | - 'dogs_count' : 0 | ||
86 | - } | ||
87 | - }, users); | ||
88 | - } | ||
89 | - | ||
90 | - let count = images[type].length, // total available images by type | ||
91 | - user = users[sender_id], // // user requesting image | ||
92 | - user_type_count = user[type+'_count']; | ||
93 | 76 | ||
77 | +} | ||
94 | 78 | ||
95 | - // update user before returning image | 79 | +exports.goToGreetTemplate = (received) => { |
96 | - let updated_user = { | ||
97 | - [sender_id] : Object.assign(user, { | ||
98 | - [type+'_count'] : count === user_type_count + 1 ? 0 : user_type_count + 1 | ||
99 | - }) | ||
100 | - }; | ||
101 | - // update users | ||
102 | - users = Object.assign(users, updated_user); | ||
103 | 80 | ||
104 | - console.log(users); | ||
105 | - return images[type][user_type_count]; | ||
106 | } | 81 | } |
82 | + | ... | ... |
-
Please register or login to post a comment