diff --git a/go-app-ussd_public_rapidpro.js b/go-app-ussd_public_rapidpro.js index 34a1d525..fc0b499a 100644 --- a/go-app-ussd_public_rapidpro.js +++ b/go-app-ussd_public_rapidpro.js @@ -434,7 +434,7 @@ go.app = function() { // Skip this state if they haven't opted out var contact = self.im.user.get_answer("contact"); if(_.toUpper(_.get(contact, "fields.opted_out")) !== "TRUE") { - return self.states.create("state_trigger_rapidpro_flow"); + return self.states.create("state_send_welcome_template"); } return new MenuState(name, { question: $( @@ -514,8 +514,11 @@ go.app = function() { timestamp: new moment.utc(self.im.config.testing_today).format(), registered_by: msisdn, mha: 6, - preferred_channel: self.im.user.answers.preferred_channel + swt: self.im.user.get_answer("preferred_channel") === "SMS" ? "1" : "7", + preferred_channel: self.im.user.get_answer("preferred_channel"), + }; + return self.rapidpro .start_flow(self.im.config.flow_uuid, null, "whatsapp:" + _.trim(msisdn, "+"), data) .then(function() { diff --git a/src/ussd_public_rapidpro.js b/src/ussd_public_rapidpro.js index d04899ea..41ab3042 100644 --- a/src/ussd_public_rapidpro.js +++ b/src/ussd_public_rapidpro.js @@ -270,7 +270,7 @@ go.app = function() { // Skip this state if they haven't opted out var contact = self.im.user.get_answer("contact"); if(_.toUpper(_.get(contact, "fields.opted_out")) !== "TRUE") { - return self.states.create("state_trigger_rapidpro_flow"); + return self.states.create("state_send_welcome_template"); } return new MenuState(name, { question: $( @@ -350,8 +350,11 @@ go.app = function() { timestamp: new moment.utc(self.im.config.testing_today).format(), registered_by: msisdn, mha: 6, - preferred_channel: self.im.user.answers.preferred_channel + swt: self.im.user.get_answer("preferred_channel") === "SMS" ? "1" : "7", + preferred_channel: self.im.user.get_answer("preferred_channel"), + }; + return self.rapidpro .start_flow(self.im.config.flow_uuid, null, "whatsapp:" + _.trim(msisdn, "+"), data) .then(function() { diff --git a/test/ussd_public_rapidpro.test.js b/test/ussd_public_rapidpro.test.js index 0f0b0ee8..e4a4f344 100644 --- a/test/ussd_public_rapidpro.test.js +++ b/test/ussd_public_rapidpro.test.js @@ -477,7 +477,21 @@ describe("ussd_public app", function() { }); it("should skip the opt in if the user hasn't opted out before", function() { return tester + .setup.user.answers({ + state_research_consent: "no", + state_opt_in: "yes", + opted_out: "False", + preferred_channel: "Whatsapp" + }) .setup(function(api) { + api.http.fixtures.add( + fixtures_hub.send_whatsapp_template_message( + "+27123456789", + "test-welcome-template", + null, + "Whatsapp" + ) + ); api.http.fixtures.add( fixtures_rapidpro.start_flow( "rapidpro-flow-uuid", @@ -489,7 +503,9 @@ describe("ussd_public app", function() { "source": "Public USSD", "timestamp": "2014-04-04T07:07:07Z", "registered_by": "+27123456789", - "mha": 6 + "mha": 6, + "swt": "7", + "preferred_channel": "Whatsapp" } ) ); @@ -503,6 +519,9 @@ describe("ussd_public app", function() { describe("state_trigger_rapidpro_flow", function() { it("should start a flow with the correct metadata", function() { return tester + .setup.user.answers({ + preferred_channel: "Whatsapp" + }) .setup(function(api) { api.http.fixtures.add( fixtures_rapidpro.start_flow( @@ -515,7 +534,9 @@ describe("ussd_public app", function() { "source": "Public USSD", "timestamp": "2014-04-04T07:07:07Z", "registered_by": "+27123456789", - "mha": 6 + "mha": 6, + "swt": "7", + "preferred_channel": "Whatsapp" } ) ); @@ -529,6 +550,9 @@ describe("ussd_public app", function() { }); it("should retry in the case of HTTP failures", function() { return tester + .setup.user.answers({ + preferred_channel: "Whatsapp" + }) .setup(function(api) { api.http.fixtures.add( fixtures_rapidpro.start_flow( @@ -541,7 +565,9 @@ describe("ussd_public app", function() { "source": "Public USSD", "timestamp": "2014-04-04T07:07:07Z", "registered_by": "+27123456789", - "mha": 6 + "mha": 6, + "swt": "7", + "preferred_channel": "Whatsapp" }, true ) @@ -564,7 +590,21 @@ describe("ussd_public app", function() { describe("state_registration_complete", function() { it("should show the complete message for all users", function() { return tester + .setup.user.answers({ + state_research_consent: "no", + state_opt_in: "yes", + opted_out: "False", + preferred_channel: "Whatsapp" + }) .setup(function(api) { + api.http.fixtures.add( + fixtures_hub.send_whatsapp_template_message( + "+27123456789", + "test-welcome-template", + null, + "Whatsapp" + ) + ); api.http.fixtures.add( fixtures_rapidpro.start_flow( "rapidpro-flow-uuid", @@ -576,7 +616,9 @@ describe("ussd_public app", function() { "source": "Public USSD", "timestamp": "2014-04-04T07:07:07Z", "registered_by": "+27123456789", - "mha": 6 + "mha": 6, + "swt": "7", + "preferred_channel": "Whatsapp" } ) ); @@ -777,7 +819,8 @@ describe("ussd_public app", function() { timestamp: "2014-04-04T07:07:07Z", source: "Public USSD", mha: 6, - preferred_channel: "SMS" + swt: "1", + preferred_channel: "SMS", } ) ); @@ -825,7 +868,8 @@ describe("ussd_public app", function() { timestamp: "2014-04-04T07:07:07Z", source: "Public USSD", mha: 6, - preferred_channel: "Whatsapp" + swt: "7", + preferred_channel: "Whatsapp", } ) );