From f26fb804276087d32a15ecc82c76598c24bb0895 Mon Sep 17 00:00:00 2001 From: buhle79 Date: Mon, 22 Jul 2024 10:54:57 +0200 Subject: [PATCH] changing code for readability --- go-app-ussd_clinic_rapidpro.js | 17 +++++++---------- src/ussd_clinic_rapidpro.js | 17 +++++++---------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/go-app-ussd_clinic_rapidpro.js b/go-app-ussd_clinic_rapidpro.js index daed645c..fdb2fdac 100644 --- a/go-app-ussd_clinic_rapidpro.js +++ b/go-app-ussd_clinic_rapidpro.js @@ -1368,13 +1368,6 @@ go.app = function() { }); self.add("state_accept_popi_2", function(name, opts) { - var answers = self.im.user.answers; - var next_state = "state_get_whatsapp_template_status"; - - if (!answers.status_id || answers.preferred_channel == "SMS"){ - next_state = "state_trigger_rapidpro_flow"; - } - return new MenuState(name, { question: $([ "Do you accept the MomConnect Privacy Policy?", @@ -1387,7 +1380,7 @@ go.app = function() { "Enter the number that matches your answer." ].join("\n")), choices: [ - new Choice(next_state, $("Accept")), + new Choice("state_get_whatsapp_template_status", $("Accept")), new Choice("state_accept_popi_confirm", $("Exit")) ], }); @@ -1429,10 +1422,14 @@ go.app = function() { }); self.add("state_get_whatsapp_template_status", function(name, opts) { - var status_id = self.im.user.answers.status_id; + var answers = self.im.user.answers; + + if (!answers.status_id || answers.preferred_channel == "SMS"){ + return self.states.create("state_trigger_rapidpro_flow"); + } return self.hub - .get_whatsapp_template_status(status_id) + .get_whatsapp_template_status(answers.status_id) .then(function(data) { self.im.user.answers.preferred_channel = data.preferred_channel; return self.states.create("state_trigger_rapidpro_flow"); diff --git a/src/ussd_clinic_rapidpro.js b/src/ussd_clinic_rapidpro.js index 31bef396..4e50f759 100644 --- a/src/ussd_clinic_rapidpro.js +++ b/src/ussd_clinic_rapidpro.js @@ -1107,13 +1107,6 @@ go.app = function() { }); self.add("state_accept_popi_2", function(name, opts) { - var answers = self.im.user.answers; - var next_state = "state_get_whatsapp_template_status"; - - if (!answers.status_id || answers.preferred_channel == "SMS"){ - next_state = "state_trigger_rapidpro_flow"; - } - return new MenuState(name, { question: $([ "Do you accept the MomConnect Privacy Policy?", @@ -1126,7 +1119,7 @@ go.app = function() { "Enter the number that matches your answer." ].join("\n")), choices: [ - new Choice(next_state, $("Accept")), + new Choice("state_get_whatsapp_template_status", $("Accept")), new Choice("state_accept_popi_confirm", $("Exit")) ], }); @@ -1168,10 +1161,14 @@ go.app = function() { }); self.add("state_get_whatsapp_template_status", function(name, opts) { - var status_id = self.im.user.answers.status_id; + var answers = self.im.user.answers; + + if (!answers.status_id || answers.preferred_channel == "SMS"){ + return self.states.create("state_trigger_rapidpro_flow"); + } return self.hub - .get_whatsapp_template_status(status_id) + .get_whatsapp_template_status(answers.status_id) .then(function(data) { self.im.user.answers.preferred_channel = data.preferred_channel; return self.states.create("state_trigger_rapidpro_flow");