From 03f05d091f74b234fd28a3fcd2f3237cb5a6bf01 Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Mon, 31 Jul 2023 09:52:44 +0200 Subject: [PATCH] endline reminder not interested and remind me tomorrow --- yal/assessments.py | 44 ++++++++++++++++++++++++++++--- yal/main.py | 13 ++++++--- yal/tests/states_dictionary.md | 1 + yal/tests/surveys/test_endline.py | 27 ++++++++++++++++++- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/yal/assessments.py b/yal/assessments.py index e3e0c44f..c700f618 100644 --- a/yal/assessments.py +++ b/yal/assessments.py @@ -142,6 +142,7 @@ class Application(BaseApplication): START_STATE = "state_survey_start" LATER_STATE = "state_assessment_later_submit" REMINDER_STATE = "state_handle_assessment_reminder_response" + REMINDER_NOT_INTERESTED_STATE = "state_reminder_not_interested" def clean_name(self, name): return name.removeprefix("state_").removesuffix("_assessment") @@ -626,10 +627,47 @@ async def state_reschedule_assessment_reminder(self): return await self.go_to_state("state_generic_what_would_you_like_to_do") async def state_remind_tomorrow(self): + + endline_survey_started = self.user.metadata.get("endline_survey_started") + + question = "No problem! I'll remind you tomorrow" + + if endline_survey_started: + return FreeText(self, question=question, next=None) + else: + return WhatsAppButtonState( + self, + question=question, + choices=[Choice("menu", "Go to main menu")], + next="state_pre_mainmenu", + error=self._(get_generic_error()), + ) + + async def state_reminder_not_interested(self): + + choices = [ + Choice("menu", "Go to the menu"), + Choice("aaq", "Ask a question"), + ] + + question = self._( + "\n".join( + [ + "[persona_emoji] *No problem! You will no longer be part" + " of this study.*", + "", + "Remember, you can still use the menu to get the info you need.", + ] + ) + ) + return WhatsAppButtonState( self, - question=self._("No problem! I'll remind you tomorrow"), - choices=[Choice("menu", "Go to main menu")], - next="state_pre_mainmenu", + question=question, + choices=choices, error=self._(get_generic_error()), + next={ + "menu": "state_pre_mainmenu", + "aaq": "state_aaq_start", + }, ) diff --git a/yal/main.py b/yal/main.py index b8d06de5..c9004f01 100644 --- a/yal/main.py +++ b/yal/main.py @@ -185,7 +185,6 @@ async def process_message(self, message): if self.user.metadata.get("onboarding_reminder_sent"): self.user.session_id = None self.state_name = OnboardingApplication.REMINDER_STATE - if keyword in ASSESSMENT_REENGAGEMENT_KEYWORDS: if self.user.metadata.get("assessment_reminder_sent"): self.user.session_id = None @@ -202,6 +201,8 @@ async def process_message(self, message): "endline_survey_completed" ) + endline_survey_started = self.user.metadata.get("endline_survey_started") + if ( keyword in EJAF_ENDLINE_SURVEY_KEYWORDS and baseline_survey_completed @@ -214,8 +215,14 @@ async def process_message(self, message): self.user.session_id = None self.state_name = AssessmentApplication.REMINDER_STATE elif keyword == "i m not interested": - self.user.session_id = None - self.state_name = EndlineTermsApplication.NO_CONSENT_STATE + if endline_survey_started: + self.user.session_id = None + self.state_name = ( + AssessmentApplication.REMINDER_NOT_INTERESTED_STATE + ) + else: + self.user.session_id = None + self.state_name = EndlineTermsApplication.NO_CONSENT_STATE else: self.user.session_id = None self.state_name = EndlineTermsApplication.START_STATE diff --git a/yal/tests/states_dictionary.md b/yal/tests/states_dictionary.md index 787458c0..9ee2ff83 100644 --- a/yal/tests/states_dictionary.md +++ b/yal/tests/states_dictionary.md @@ -249,6 +249,7 @@ | state_stop_assessment_reminders | TRUE | Text | TRUE | Sets the user to no longer get assessment reminders, asks user if they would like to go to menu or aaq | | state_reschedule_assessment_reminder | | | | Schedules the assessment reminders | | state_remind_tomorrow | TRUE | Text | TRUE | Lets the user know we will remind them tomorrow, asks the user if they would like to go to the mainmenu | +| state_reminder_not_interested | True | Text | TRUE | Lets the user know that they will no longer be prt of the study | ### Service finder flow diff --git a/yal/tests/surveys/test_endline.py b/yal/tests/surveys/test_endline.py index 58e7c6a2..586c2bed 100644 --- a/yal/tests/surveys/test_endline.py +++ b/yal/tests/surveys/test_endline.py @@ -102,7 +102,7 @@ async def test_endline_invitation_remind_me_tomorrow( addr="278201234567", state=StateData(), session_id=1, - metadata={"baseline_survey_completed": True}, + metadata={"baseline_survey_completed": True, "endline_survey_started": True}, ) app = Application(user) msg = Message( @@ -143,6 +143,31 @@ async def test_endline_invitation_not_interested( assert user.state.name == "state_no_consent" +@pytest.mark.asyncio +async def test_endline_reminder_not_interested( + tester: AppTester, + rapidpro_mock, +): + user = User( + addr="278201234567", + state=StateData(), + session_id=1, + metadata={"baseline_survey_completed": True, "endline_survey_started": True}, + ) + app = Application(user) + msg = Message( + content="I'm not interested", + to_addr="27820001002", + from_addr="27820001003", + transport_name="whatsapp", + transport_type=Message.TRANSPORT_TYPE.HTTP_API, + ) + + [reply] = await app.process_message(msg) + + assert user.state.name == "state_reminder_not_interested" + + @pytest.mark.asyncio async def test_endline_invitation_answer(tester: AppTester, rapidpro_mock):