Skip to content

Commit

Permalink
Add youth keywords for tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Aug 3, 2023
1 parent 62cc8a4 commit 7438a80
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- youth-keyword

jobs:
build:
Expand Down
13 changes: 12 additions & 1 deletion yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
"connect",
"i saw this on facebook",
}
TRACKING_KEYWORDS_ROUND_3 = {
"youth",
"yth",
"yuth",
"yut",
"yoth",
"yot",
"yoh"
}
OPTOUT_KEYWORDS = {"stop", "opt out", "cancel", "quit"}
ONBOARDING_REMINDER_KEYWORDS = {
"continue",
Expand Down Expand Up @@ -143,6 +152,7 @@ async def process_message(self, message):
keyword in GREETING_KEYWORDS
or keyword in TRACKING_KEYWORDS
or keyword in TRACKING_KEYWORDS_ROUND_2
or keyword in TRACKING_KEYWORDS_ROUND_3
):
self.user.session_id = None
self.state_name = self.START_STATE
Expand Down Expand Up @@ -252,7 +262,7 @@ async def state_start(self):
inbound = utils.clean_inbound(self.inbound.content)

# Save keywords that are used for source tracking
if inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2:
if inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2 or inbound in TRACKING_KEYWORDS_ROUND_3:
self.save_answer("state_source_tracking", inbound)

if inbound in OPTOUT_KEYWORDS:
Expand All @@ -261,6 +271,7 @@ async def state_start(self):
inbound in GREETING_KEYWORDS
or inbound in TRACKING_KEYWORDS
or inbound in TRACKING_KEYWORDS_ROUND_2
or inbound in TRACKING_KEYWORDS_ROUND_3
):
if terms_accepted and onboarding_completed:
return await self.go_to_state(MainMenuApplication.START_STATE)
Expand Down
26 changes: 26 additions & 0 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,32 @@ async def test_tracked_keywords_saved_for_new_user_ads_round_2(
tester.assert_answer("state_source_tracking", "hi")


@pytest.mark.asyncio
async def test_tracked_keywords_saved_ads_round_3(
tester: AppTester, rapidpro_mock, contentrepo_api_mock
):
rapidpro_mock.tstate.contact_fields["onboarding_completed"] = "True"
rapidpro_mock.tstate.contact_fields["terms_accepted"] = "True"
await tester.user_input("youth")
tester.assert_state("state_mainmenu")
tester.assert_num_messages(2)

tester.assert_answer("state_source_tracking", "youth")


@pytest.mark.asyncio
async def test_tracked_keywords_saved_for_new_user_ads_round_3(
tester: AppTester, rapidpro_mock, contentrepo_api_mock
):
rapidpro_mock.tstate.contact_fields["onboarding_completed"] = ""
rapidpro_mock.tstate.contact_fields["terms_accepted"] = ""
await tester.user_input("yoth")
tester.assert_state("state_welcome")
tester.assert_num_messages(1)

tester.assert_answer("state_source_tracking", "yoth")


@pytest.mark.asyncio
async def test_onboarding_reminder_response_to_reminder_handler(
tester: AppTester, rapidpro_mock
Expand Down

0 comments on commit 7438a80

Please sign in to comment.