김예미

Edit Template 4 - payload.substr

let request = require('request'),
template = require('./template');
// Views - handle Message, handle Postback
// Handles message events
exports.handleMessage = (sender_psid, received_message) => {
let payload = recieved_message.payload;
if(payload === 'CHOICE_BY_PROF'){
handlePostback_choiceByProf(sender_psid, received_message);
}else if(payload === 'CHOICE_BY_LECT'){
handlePostback_choiceByLect(sender_psid, recieved_message);
}else if(payload === 'HELP'){
handlePostback_help(sender_psid, recieved_message);
}
}
exports.handlePostback = (sender_psid, received_postback) => {
......@@ -26,14 +15,11 @@ exports.handlePostback = (sender_psid, received_postback) => {
if(payload === 'Greeting'){
response = template.greetingTemplate();
callSendAPI(sender_psid, response);
}
let first_choice = payload.first_choice;
if(first_choice=== 'CHOICE_BY_PROF'){
}else if(payload.substr(0,14)=== 'CHOICE_BY_PROF'){
handlePostback_choiceByProf(sender_psid, received_postback);
}else if(first_choice=== 'CHOICE_BY_LECT'){
}else if(payload.substr(0,14)=== 'CHOICE_BY_LECT'){
handlePostback_choiceByLect(sender_psid, recieved_postback);
}else if(first_choice=== 'HELP'){
}else if(payload.substr(0,14) ==='CHOICE_BY_HELP'){
handlePostback_help(sender_psid, recieved_postback);
}
}
......@@ -41,7 +27,7 @@ exports.handlePostback = (sender_psid, received_postback) => {
const handlePostback_choiceByProf = (sender_psid, received) => {
let response;
let stat = received.payload.stat;
let stat = received.payload.substr(14);
if(stat === 'stat_0'){
response = template.getProfNameTemplate(received);
......@@ -56,7 +42,7 @@ const handlePostback_choiceByProf = (sender_psid, received) => {
const handlePostback_choiceByLect = (sender_psid, recieved) => {
let response;
let stat = recieved.stat;
let stat = recieved.payload.substr(14);
if(stat === 'stat_0'){
response = template.getLectNameTemplate(received);
......@@ -75,7 +61,7 @@ const handlePostback_choiceByLect = (sender_psid, recieved) => {
const handlePostback_help = (sender_psid, received) => {
let response;
let stat = received.stat;
let stat = received.payload.substr(14);
if(stat === 'stat_0'){
response = template.howToTemplate(received);
......
......@@ -13,26 +13,17 @@ exports.greetingTemplate = () => {
{
"type":"postback",
"title":greetingTitle[0],
"payload":{
first_choice:"CHOICE_BY_PROF",
stat:"stat_0"
}
"payload":"CHOICE_BY_PROFstat_0"
},
{
"type":"postback",
"title":greetingTitle[1],
"payload":{
first_choice:"CHOICE_BY_LECT",
stat: "stat_0"
}
"payload":"CHOICE_BY_LECTstat_0"
},
{
"type":"postback",
"title":greetingTitle[2],
"payload":{
first_choice:"HELP",
stat: "stat_0"
}
"payload":"CHOICE_BY_HELPstat_0"
}
]
}
......@@ -52,11 +43,12 @@ exports.getProfNameTemplate = (received) => {
{
"type":"postback",
"title":"처음으로",
"payload":{
first_choice:'Greeting',
stat:'stat_0',
rate:{}
}
"payload":'Greeting'
},
{
"type":"postback",
"title":"stat_1로",
"payload":"CHOICE_BY_PROFstat_1"
}
]
}
......