Skip to content

Commit

Permalink
Merge pull request #681 from praekeltfoundation/tiktok-triggers
Browse files Browse the repository at this point in the history
Add tiktok trigger keyword
  • Loading branch information
erikh360 authored Aug 30, 2023
2 parents 376acfb + 1f28cae commit 61ba2a3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"i saw this on facebook",
}
TRACKING_KEYWORDS_ROUND_3 = {"youth", "yth", "yuth", "yut", "yoth", "yot", "yoh"}
TRACKING_KEYWORDS_TIKTOK = {"sho"}
OPTOUT_KEYWORDS = {"stop", "opt out", "cancel", "quit"}
ONBOARDING_REMINDER_KEYWORDS = {
"continue",
Expand Down Expand Up @@ -156,6 +157,7 @@ async def process_message(self, message):
or keyword in TRACKING_KEYWORDS
or keyword in TRACKING_KEYWORDS_ROUND_2
or keyword in TRACKING_KEYWORDS_ROUND_3
or keyword in TRACKING_KEYWORDS_TIKTOK
):
self.user.session_id = None
self.state_name = self.START_STATE
Expand Down Expand Up @@ -329,6 +331,7 @@ async def state_start(self):
inbound in TRACKING_KEYWORDS
or inbound in TRACKING_KEYWORDS_ROUND_2
or inbound in TRACKING_KEYWORDS_ROUND_3
or inbound in TRACKING_KEYWORDS_TIKTOK
):
self.save_answer("state_source_tracking", inbound)

Expand All @@ -339,6 +342,7 @@ async def state_start(self):
or inbound in TRACKING_KEYWORDS
or inbound in TRACKING_KEYWORDS_ROUND_2
or inbound in TRACKING_KEYWORDS_ROUND_3
or inbound in TRACKING_KEYWORDS_TIKTOK
):
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 @@ -987,6 +987,32 @@ async def test_tracked_keywords_saved_for_new_user_ads_round_3(
tester.assert_answer("state_source_tracking", "yoth")


@pytest.mark.asyncio
async def test_tracked_keywords_tiktok(
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("sho")
tester.assert_state("state_mainmenu")
tester.assert_num_messages(2)

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


@pytest.mark.asyncio
async def test_tracked_keywords_saved_for_new_user_tiktok(
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("sho")
tester.assert_state("state_welcome")
tester.assert_num_messages(1)

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


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

0 comments on commit 61ba2a3

Please sign in to comment.