Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sigma 1155 capi registration ussd #637

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions go-app-ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1261,10 +1261,9 @@ go.app = function() {
return self.hub
.send_whatsapp_template_message(msisdn, template_name, media)
.then(function(data) {
console.log("Template Data: ", data);
self.im.user.answers.preferred_channel = data.preferred_channel;
self.im.user.answers.status_id = data.status_id;
console.log("ID: ", self.im.user.answers.status_id);

if (data.preferred_channel == "SMS") {
return self.rapidpro.get_global_flag("sms_registrations_enabled")
.then(function(sms_registration_enabled) {
Expand Down Expand Up @@ -1423,12 +1422,15 @@ go.app = function() {
});

self.add("state_get_whatsapp_template_status", function(name, opts) {
var status_id = self.im.user.answers.status_id;
console.log(">>>>>>", 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) {
console.log("Status Data: ", data);
self.im.user.answers.preferred_channel = data.preferred_channel;
return self.states.create("state_trigger_rapidpro_flow");
}).catch(function(e) {
Expand Down Expand Up @@ -1515,6 +1517,7 @@ go.app = function() {
return self.states.create("state_registration_complete");
}).catch(function(e) {
// Go to error state after 3 failed HTTP requests
console.log("Trigger RP: ", e.message);
Buhle79 marked this conversation as resolved.
Show resolved Hide resolved
opts.http_error_count = _.get(opts, "http_error_count", 0) + 1;
if (opts.http_error_count === 3) {
self.im.log.error(e.message);
Expand Down
15 changes: 9 additions & 6 deletions src/ussd_clinic_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,9 @@ go.app = function() {
return self.hub
.send_whatsapp_template_message(msisdn, template_name, media)
.then(function(data) {
console.log("Template Data: ", data);
self.im.user.answers.preferred_channel = data.preferred_channel;
self.im.user.answers.status_id = data.status_id;
console.log("ID: ", self.im.user.answers.status_id);

if (data.preferred_channel == "SMS") {
return self.rapidpro.get_global_flag("sms_registrations_enabled")
.then(function(sms_registration_enabled) {
Expand Down Expand Up @@ -1162,12 +1161,15 @@ go.app = function() {
});

self.add("state_get_whatsapp_template_status", function(name, opts) {
var status_id = self.im.user.answers.status_id;
console.log(">>>>>>", 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) {
console.log("Status Data: ", data);
self.im.user.answers.preferred_channel = data.preferred_channel;
return self.states.create("state_trigger_rapidpro_flow");
}).catch(function(e) {
Expand Down Expand Up @@ -1254,6 +1256,7 @@ go.app = function() {
return self.states.create("state_registration_complete");
}).catch(function(e) {
// Go to error state after 3 failed HTTP requests
console.log("Trigger RP: ", e.message);
opts.http_error_count = _.get(opts, "http_error_count", 0) + 1;
if (opts.http_error_count === 3) {
self.im.log.error(e.message);
Expand Down
118 changes: 65 additions & 53 deletions test/ussd_clinic_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1678,15 +1678,6 @@ describe("ussd_clinic app", function() {
state_clinic_code: "123456",
preferred_channel: "SMS",
state_language: "eng",
status_id: "status-id-uuid",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid",
"SMS"
)
);
})
.setup(function(api) {
api.http.fixtures.add(
Expand All @@ -1704,7 +1695,6 @@ describe("ussd_clinic app", function() {
dob: "1990-01-02T00:00:00Z",
swt: "1",
preferred_channel: "SMS",
status_id: "status-id-uuid",
}
)
);
Expand All @@ -1721,17 +1711,16 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 2);
assert.equal(api.http.requests.length, 1);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
"https://rapidpro/api/v2/flow_starts.json"
]);
assert.equal(api.log.error.length, 0);
})
.run();
});
it("should make a request to the RapidPro APIs for prebirth if message type is skipped", function() {
it("should make a request to the RapidPro APIs for prebirth if message type is skipped for WA", function() {
return tester
.setup.user.state("state_accept_popi_2")
.setup.user.answers({
Expand All @@ -1742,7 +1731,7 @@ describe("ussd_clinic app", function() {
state_edd_month: "201502",
state_edd_day: "13",
state_clinic_code: "123456",
preferred_channel: "SMS",
preferred_channel: "WhatApp",
state_language: "eng",
status_id: "status-id-uuid",

Expand All @@ -1751,7 +1740,7 @@ describe("ussd_clinic app", function() {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid",
"SMS"
"WhatsApp"
)
);
})
Expand All @@ -1769,8 +1758,8 @@ describe("ussd_clinic app", function() {
clinic_code: "123456",
sa_id_number: "9001020005087",
dob: "1990-01-02T00:00:00Z",
swt: "1",
preferred_channel: "SMS",
swt: "7",
preferred_channel: "WhatsApp",
status_id: "status-id-uuid",
}
)
Expand All @@ -1783,7 +1772,7 @@ describe("ussd_clinic app", function() {
"You're done!",
"",
"This number 0820001001 will start getting messages from " +
"MomConnect on SMS."
"MomConnect on WhatsApp."
].join("\n")
})
.check.reply.ends_session()
Expand All @@ -1798,31 +1787,78 @@ describe("ussd_clinic app", function() {
})
.run();
});
it("should make a request to the RapidPro APIs for prebirth underage registree mom with sa_id on accept selection", function() {
it("should make a request to the RapidPro APIs for prebirth if message type is skipped for USSD", function() {
return tester
.setup.user.state("state_accept_popi_2")
.setup.user.answers({
state_message_type: "state_edd_month",
state_research_consent: "no",
state_enter_msisdn: "0820001001",
state_id_type: "state_sa_id_no",
state_sa_id_no: "1301020005087",
state_sa_id_no: "9001020005087",
state_edd_month: "201502",
state_edd_day: "13",
state_clinic_code: "123456",
state_underage_registree: "Yes",
preferred_channel: "SMS",
state_language: "eng",
status_id: "status-id-uuid",

})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid",
"SMS"
fixtures_rapidpro.start_flow(
"prebirth-flow-uuid", null, "whatsapp:27820001001", {
research_consent: "TRUE",
registered_by: "+27123456789",
language: "eng",
timestamp: "2014-04-04T07:07:07Z",
source: "Clinic USSD",
id_type: "sa_id",
edd: "2015-02-13T00:00:00Z",
clinic_code: "123456",
sa_id_number: "9001020005087",
dob: "1990-01-02T00:00:00Z",
swt: "1",
preferred_channel: "SMS",
}
)
);
})
.input("1")
.check.interaction({
state: "state_registration_complete",
reply: [
"You're done!",
"",
"This number 0820001001 will start getting messages from " +
"MomConnect on SMS."
].join("\n")
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 1);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"https://rapidpro/api/v2/flow_starts.json"
]);
assert.equal(api.log.error.length, 0);
})
.run();
});
it("should make a request to the RapidPro APIs for prebirth underage registree mom with sa_id on accept selection", function() {
return tester
.setup.user.state("state_accept_popi_2")
.setup.user.answers({
state_message_type: "state_edd_month",
state_research_consent: "no",
state_enter_msisdn: "0820001001",
state_id_type: "state_sa_id_no",
state_sa_id_no: "1301020005087",
state_edd_month: "201502",
state_edd_day: "13",
state_clinic_code: "123456",
state_underage_registree: "Yes",
preferred_channel: "SMS",
state_language: "eng",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_rapidpro.start_flow(
Expand All @@ -1840,7 +1876,6 @@ describe("ussd_clinic app", function() {
dob: "2013-01-02T00:00:00Z",
swt: "1",
preferred_channel: "SMS",
status_id: "status-id-uuid",
}
)
);
Expand All @@ -1857,10 +1892,9 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 2);
assert.equal(api.http.requests.length, 1);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
"https://rapidpro/api/v2/flow_starts.json"
]);
assert.equal(api.log.error.length, 0);
Expand All @@ -1884,15 +1918,6 @@ describe("ussd_clinic app", function() {
state_underage_registree: "Yes",
preferred_channel: "SMS",
state_language: "eng",
status_id: "status-id-uuid",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid",
"SMS"
)
);
})
.setup(function(api) {
api.http.fixtures.add(
Expand All @@ -1912,7 +1937,6 @@ describe("ussd_clinic app", function() {
swt: "1",
age: "16",
preferred_channel: "SMS",
status_id: "status-id-uuid",
}
)
);
Expand All @@ -1929,10 +1953,9 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 2);
assert.equal(api.http.requests.length, 1);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
"https://rapidpro/api/v2/flow_starts.json"
]);
assert.equal(api.log.error.length, 0);
Expand All @@ -1956,15 +1979,6 @@ describe("ussd_clinic app", function() {
state_underage_registree: "Yes",
preferred_channel: "SMS",
state_language: "eng",
status_id: "status-id-uuid",
})
.setup(function(api) {
api.http.fixtures.add(
fixtures_hub.get_whatsapp_template_status(
"status-id-uuid",
"SMS"
)
);
})
.setup(function(api) {
api.http.fixtures.add(
Expand All @@ -1982,7 +1996,6 @@ describe("ussd_clinic app", function() {
swt: "1",
dob: "2014-10-25T00:00:00Z",
preferred_channel: "SMS",
status_id: "status-id-uuid",
}
)
);
Expand All @@ -1999,10 +2012,9 @@ describe("ussd_clinic app", function() {
})
.check.reply.ends_session()
.check(function(api) {
assert.equal(api.http.requests.length, 2);
assert.equal(api.http.requests.length, 1);
var urls = _.map(api.http.requests, "url");
assert.deepEqual(urls, [
"http://hub/api/v2/whatsapptemplatesendstatus/status-id-uuid/",
"https://rapidpro/api/v2/flow_starts.json"
]);
assert.equal(api.log.error.length, 0);
Expand Down
Loading