Skip to content

Commit

Permalink
endline reminder not interested and remind me tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Jul 31, 2023
1 parent 91876cd commit 03f05d0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
44 changes: 41 additions & 3 deletions yal/assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
},
)
13 changes: 10 additions & 3 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions yal/tests/states_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion yal/tests/surveys/test_endline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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):

Expand Down

0 comments on commit 03f05d0

Please sign in to comment.