김예미

Edit Template 4 - payload.substr

1 let request = require('request'), 1 let request = require('request'),
2 template = require('./template'); 2 template = require('./template');
3 3
4 -// Views - handle Message, handle Postback
5 -
6 // Handles message events 4 // Handles message events
7 exports.handleMessage = (sender_psid, received_message) => { 5 exports.handleMessage = (sender_psid, received_message) => {
8 - let payload = recieved_message.payload;
9 -
10 - if(payload === 'CHOICE_BY_PROF'){
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);
16 - }
17 } 6 }
18 7
19 exports.handlePostback = (sender_psid, received_postback) => { 8 exports.handlePostback = (sender_psid, received_postback) => {
...@@ -26,14 +15,11 @@ exports.handlePostback = (sender_psid, received_postback) => { ...@@ -26,14 +15,11 @@ exports.handlePostback = (sender_psid, received_postback) => {
26 if(payload === 'Greeting'){ 15 if(payload === 'Greeting'){
27 response = template.greetingTemplate(); 16 response = template.greetingTemplate();
28 callSendAPI(sender_psid, response); 17 callSendAPI(sender_psid, response);
29 - } 18 + }else if(payload.substr(0,14)=== 'CHOICE_BY_PROF'){
30 -
31 - let first_choice = payload.first_choice;
32 - if(first_choice=== 'CHOICE_BY_PROF'){
33 handlePostback_choiceByProf(sender_psid, received_postback); 19 handlePostback_choiceByProf(sender_psid, received_postback);
34 - }else if(first_choice=== 'CHOICE_BY_LECT'){ 20 + }else if(payload.substr(0,14)=== 'CHOICE_BY_LECT'){
35 handlePostback_choiceByLect(sender_psid, recieved_postback); 21 handlePostback_choiceByLect(sender_psid, recieved_postback);
36 - }else if(first_choice=== 'HELP'){ 22 + }else if(payload.substr(0,14) ==='CHOICE_BY_HELP'){
37 handlePostback_help(sender_psid, recieved_postback); 23 handlePostback_help(sender_psid, recieved_postback);
38 } 24 }
39 } 25 }
...@@ -41,7 +27,7 @@ exports.handlePostback = (sender_psid, received_postback) => { ...@@ -41,7 +27,7 @@ exports.handlePostback = (sender_psid, received_postback) => {
41 const handlePostback_choiceByProf = (sender_psid, received) => { 27 const handlePostback_choiceByProf = (sender_psid, received) => {
42 let response; 28 let response;
43 29
44 - let stat = received.payload.stat; 30 + let stat = received.payload.substr(14);
45 31
46 if(stat === 'stat_0'){ 32 if(stat === 'stat_0'){
47 response = template.getProfNameTemplate(received); 33 response = template.getProfNameTemplate(received);
...@@ -56,7 +42,7 @@ const handlePostback_choiceByProf = (sender_psid, received) => { ...@@ -56,7 +42,7 @@ const handlePostback_choiceByProf = (sender_psid, received) => {
56 const handlePostback_choiceByLect = (sender_psid, recieved) => { 42 const handlePostback_choiceByLect = (sender_psid, recieved) => {
57 let response; 43 let response;
58 44
59 - let stat = recieved.stat; 45 + let stat = recieved.payload.substr(14);
60 46
61 if(stat === 'stat_0'){ 47 if(stat === 'stat_0'){
62 response = template.getLectNameTemplate(received); 48 response = template.getLectNameTemplate(received);
...@@ -75,7 +61,7 @@ const handlePostback_choiceByLect = (sender_psid, recieved) => { ...@@ -75,7 +61,7 @@ const handlePostback_choiceByLect = (sender_psid, recieved) => {
75 const handlePostback_help = (sender_psid, received) => { 61 const handlePostback_help = (sender_psid, received) => {
76 let response; 62 let response;
77 63
78 - let stat = received.stat; 64 + let stat = received.payload.substr(14);
79 65
80 if(stat === 'stat_0'){ 66 if(stat === 'stat_0'){
81 response = template.howToTemplate(received); 67 response = template.howToTemplate(received);
......
...@@ -13,26 +13,17 @@ exports.greetingTemplate = () => { ...@@ -13,26 +13,17 @@ exports.greetingTemplate = () => {
13 { 13 {
14 "type":"postback", 14 "type":"postback",
15 "title":greetingTitle[0], 15 "title":greetingTitle[0],
16 - "payload":{ 16 + "payload":"CHOICE_BY_PROFstat_0"
17 - first_choice:"CHOICE_BY_PROF",
18 - stat:"stat_0"
19 - }
20 }, 17 },
21 { 18 {
22 "type":"postback", 19 "type":"postback",
23 "title":greetingTitle[1], 20 "title":greetingTitle[1],
24 - "payload":{ 21 + "payload":"CHOICE_BY_LECTstat_0"
25 - first_choice:"CHOICE_BY_LECT",
26 - stat: "stat_0"
27 - }
28 }, 22 },
29 { 23 {
30 "type":"postback", 24 "type":"postback",
31 "title":greetingTitle[2], 25 "title":greetingTitle[2],
32 - "payload":{ 26 + "payload":"CHOICE_BY_HELPstat_0"
33 - first_choice:"HELP",
34 - stat: "stat_0"
35 - }
36 } 27 }
37 ] 28 ]
38 } 29 }
...@@ -52,11 +43,12 @@ exports.getProfNameTemplate = (received) => { ...@@ -52,11 +43,12 @@ exports.getProfNameTemplate = (received) => {
52 { 43 {
53 "type":"postback", 44 "type":"postback",
54 "title":"처음으로", 45 "title":"처음으로",
55 - "payload":{ 46 + "payload":'Greeting'
56 - first_choice:'Greeting', 47 + },
57 - stat:'stat_0', 48 + {
58 - rate:{} 49 + "type":"postback",
59 - } 50 + "title":"stat_1로",
51 + "payload":"CHOICE_BY_PROFstat_1"
60 } 52 }
61 ] 53 ]
62 } 54 }
......