Skip to content

Commit

Permalink
Merge pull request #645 from praekeltfoundation/survey_keywords
Browse files Browse the repository at this point in the history
Survey keywords
  • Loading branch information
Hlamallama committed Jul 27, 2023
2 parents f4fab92 + 91876cd commit f25f03f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 9 deletions.
9 changes: 4 additions & 5 deletions yal/endline_terms_and_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class Application(BaseApplication):
START_STATE = "state_start_terms"
NO_CONSENT_STATE = "state_no_consent"

async def state_start_terms(self):
question = self._(
Expand Down Expand Up @@ -220,7 +221,7 @@ async def state_set_reminder_timer(self):
question = self._(
"\n".join(
[
"[persona_emoji] No worries, we get it!",
"No worries, we get it!",
"",
"I'll send you a reminder message in 30 mins, so you can come back "
"and answer these questions.",
Expand All @@ -230,12 +231,10 @@ async def state_set_reminder_timer(self):
)
)

return WhatsAppButtonState(
return FreeText(
self,
question=question,
choices=[Choice("menu", "Go to main menu")],
error=get_generic_error(),
next="state_pre_mainmenu",
next=None,
)

async def state_submit_terms_and_conditions_endline(self):
Expand Down
23 changes: 20 additions & 3 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@
QA_RESET_FEEDBACK_TIMESTAMP_KEYWORDS = {"resetfeedbacktimestampobzvmp"}
EMERGENCY_KEYWORDS = utils.get_keywords("emergency")
AAQ_KEYWORDS = {"ask a question"}
EJAF_ENDLINE_SURVEY_KEYWORDS = {"answer", "yes i want to answer"}
EJAF_ENDLINE_SURVEY_KEYWORDS = {
"answer",
"yes i want to answer",
"remind me tomorrow",
"i m not interested",
}


class Application(
Expand Down Expand Up @@ -196,13 +201,25 @@ async def process_message(self, message):
endline_survey_completed = self.user.metadata.get(
"endline_survey_completed"
)

if (
keyword in EJAF_ENDLINE_SURVEY_KEYWORDS
and baseline_survey_completed
and not endline_survey_completed
):
self.user.session_id = None
self.state_name = EndlineTermsApplication.START_STATE
self.save_metadata("assessment_reminder_sent", False)
self.save_metadata("assessment_reminder_name", "")

if keyword == "remind me tomorrow":
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
else:
self.user.session_id = None
self.state_name = EndlineTermsApplication.START_STATE

# Fields that RapidPro sets after a feedback push message
feedback_state = await self.get_feedback_state()
if feedback_state:
Expand Down
50 changes: 50 additions & 0 deletions yal/tests/surveys/test_endline.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,56 @@ async def test_endline_invitation_i_want_to_answer(tester: AppTester, rapidpro_m
assert user.state.name == "state_start_terms"


@pytest.mark.asyncio
async def test_endline_invitation_remind_me_tomorrow(
tester: AppTester,
rapidpro_mock,
):
user = User(
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True},
)
app = Application(user)
msg = Message(
content="Remind me tomorrow",
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_remind_tomorrow"


@pytest.mark.asyncio
async def test_endline_invitation_not_interested(
tester: AppTester,
rapidpro_mock,
):
user = User(
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": 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_no_consent"


@pytest.mark.asyncio
async def test_endline_invitation_answer(tester: AppTester, rapidpro_mock):

Expand Down
2 changes: 1 addition & 1 deletion yal/tests/test_endline_terms_and_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def test_state_accept_consent_reminder(tester: AppTester, rapidpro_mock):

message = "\n".join(
[
"🤖 No worries, we get it!",
"No worries, we get it!",
"",
"I'll send you a reminder message in 30 mins, so you can come back"
" and answer these questions.",
Expand Down

0 comments on commit f25f03f

Please sign in to comment.