Skip to content

Commit

Permalink
Handle contacts with active postbirth messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
DevChima committed Jan 29, 2025
1 parent 7e0f958 commit 0d5492b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
15 changes: 14 additions & 1 deletion go-app-ussd_public_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ go.app = function() {
return self.states.create("state_public_subscription");
} else if(_.inRange(_.get(contact, "fields.prebirth_messaging"), 1, 7)) {
return self.states.create("state_clinic_subscription");
} else {
} else if(_.toUpper(_.get(contact, "fields.postbirth_messaging")) === "TRUE"){
return self.states.create("state_postbirth_subscription");
}
else {
return self.states.create("state_pregnant");
}
}).catch(function(e) {
Expand Down Expand Up @@ -313,6 +316,16 @@ go.app = function() {
});
});

self.states.add("state_postbirth_subscription", function(name) {
return new EndState(name, {
next: "state_start",
text: $(
"Hello mom! You're getting postbirth messages. Reply with questions, compliments, or " +
"complaints. We'll get back to you soon."
)
});
});

self.states.add("state_pregnant", function(name) {
return new MenuState(name, {
question: $(
Expand Down
15 changes: 14 additions & 1 deletion src/ussd_public_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ go.app = function() {
return self.states.create("state_public_subscription");
} else if(_.inRange(_.get(contact, "fields.prebirth_messaging"), 1, 7)) {
return self.states.create("state_clinic_subscription");
} else {
} else if(_.toUpper(_.get(contact, "fields.postbirth_messaging")) === "TRUE"){
return self.states.create("state_postbirth_subscription");
}
else {
return self.states.create("state_pregnant");
}
}).catch(function(e) {
Expand Down Expand Up @@ -149,6 +152,16 @@ go.app = function() {
});
});

self.states.add("state_postbirth_subscription", function(name) {
return new EndState(name, {
next: "state_start",
text: $(
"Hello mom! You're getting postbirth messages. Reply with questions, compliments, or " +
"complaints. We'll get back to you soon."
)
});
});

self.states.add("state_pregnant", function(name) {
return new MenuState(name, {
question: $(
Expand Down
20 changes: 20 additions & 0 deletions test/ussd_public_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ describe("ussd_public app", function() {
})
.run();
});
it("should give the user compliment/complaint instructions if they're receiving postbirth messages", function() {
return tester
.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.get_contact({
urn: "whatsapp:27123456789",
exists: true,
fields: {postbirth_messaging: "TRUE"}
})
);
})
.start()
.check.interaction({
state: "state_postbirth_subscription",
reply:
"Hello mom! You're getting postbirth messages. Reply with questions, compliments, or " +
"complaints. We'll get back to you soon."
})
.run();
});
it("should welcome the user if they don't have a subscription", function() {
return tester
.setup(function(api) {
Expand Down

0 comments on commit 0d5492b

Please sign in to comment.