Skip to content

Commit

Permalink
WhatsApp copy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rudigiesler committed Jun 29, 2021
1 parent 35460ca commit 5b86384
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 40 deletions.
3 changes: 3 additions & 0 deletions prototype_learnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
We should have some sort of keyword state, that can map keywords to labels. eg. '1' or 'yes' should be labelled 'yes'. This can then be our default state type for most things, and we only use the ChoiceState for dynamic choice lists. This will help simplify things with formatting (eg. if you want the numbers to be bolded on whatsapp), and allow for easier integration into a CMS.

`next` could be a dictionary as a shortcut to map labels to states names (could also allow functions that return state names as values), which could replace MenuStates
9 changes: 8 additions & 1 deletion vaccine/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(
next: Union[str, Callable],
accept_labels: bool = True,
footer: Optional[str] = None,
error_footer: Optional[str] = None,
):
self.app = app
self.question = question
Expand All @@ -63,6 +64,7 @@ def __init__(
self.accept_labels = accept_labels
self.next = next
self.footer = footer
self.error_footer = error_footer

def _normalise_text(self, text: Optional[str]) -> str:
return (text or "").strip().lower()
Expand Down Expand Up @@ -91,7 +93,10 @@ async def _get_next(self, choice):
async def process_message(self, message: Message):
choice = self._get_choice(message.content)
if choice is None:
return self.app.send_message(f"{self.error}\n{self._display_choices}")
text = f"{self.error}\n{self._display_choices}"
if self.error_footer:
text = f"{text}\n{self.footer}"
return self.app.send_message(text)
else:
self.app.save_answer(self.app.state_name, choice.value)
self.app.state_name = await self._get_next(choice)
Expand All @@ -114,13 +119,15 @@ def __init__(
error: str,
accept_labels: bool = True,
footer: Optional[str] = None,
error_footer: Optional[str] = None,
):
self.app = app
self.question = question
self.choices = choices
self.error = error
self.accept_labels = accept_labels
self.footer = footer
self.error_footer = error_footer

async def _next(self, choice: Choice):
return choice.value
Expand Down
33 changes: 29 additions & 4 deletions vaccine/tests/test_vaccine_reg_whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ async def test_passport_country_search(tester: AppTester):
"\n".join(
[
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"Please confirm your passport's COUNTRY of origin.",
"",
"Please confirm your passport's COUNTRY of origin. REPLY with a "
"NUMBER from the list below:",
"REPLY with a NUMBER from the list below:",
"1. Republic of Côte d'Ivoire",
"2. British Indian Ocean Territory",
"3. Plurinational State of Bolivia",
Expand Down Expand Up @@ -410,6 +410,7 @@ async def test_suburb(evds_mock, tester: AppTester):
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"",
"Please REPLY with a NUMBER to confirm your location:",
"",
"1. Table View, Blouberg",
"2. Other",
]
Expand Down Expand Up @@ -466,7 +467,8 @@ async def test_municipality(evds_mock, tester: AppTester):
[
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"",
"Please REPLY with a NUMBER to confirm your MUNICIPALITY:",
"Please confirm the MUNICIPALITY for the suburb you have given:",
"",
"1. Buffalo City",
"2. Enoch Mgijima",
"3. Great Kei",
Expand Down Expand Up @@ -503,6 +505,7 @@ async def test_municipality_plumstead(evds_mock, tester: AppTester):
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"",
"Please REPLY with a NUMBER to confirm your location:",
"",
"1. Plumstead, Cape Town",
"2. Other",
]
Expand All @@ -523,6 +526,7 @@ async def test_suburb_with_municipality(evds_mock, tester: AppTester):
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"",
"Please REPLY with a NUMBER to confirm your location:",
"",
"1. Mandela Park, Mandela Park",
"2. Other",
]
Expand Down Expand Up @@ -572,7 +576,7 @@ async def test_self_registration(evds_mock, tester: AppTester):
[
"*VACCINE REGISTRATION SECURE CHAT* 🔐",
"",
"We will use your cell phone number to send you notifications and "
"We will use your mobile phone number to send you notifications and "
"updates via WhatsApp and/or SMS about getting vaccinated.",
"",
"Can we use 082 000 1001?",
Expand Down Expand Up @@ -644,6 +648,7 @@ async def test_medical_aid_list_1(evds_mock, tester: AppTester):
"",
"Please confirm your Medical Aid Provider. REPLY with a NUMBER from "
"the list below:",
"",
"1. Discovery Health Medical Scheme",
"2. Aeci Medical Aid Society",
"3. BMW Employees Medical Aid Society",
Expand All @@ -665,6 +670,7 @@ async def test_medical_aid_list_2(evds_mock, tester: AppTester):
"",
"Please confirm your Medical Aid Provider. REPLY with a NUMBER from "
"the list below:",
"",
"1. Tsogo Sun Group Medical Scheme",
"2. Golden Arrows Employees Medical Benefit Fund",
"3. Engen Medical Benefit Fund",
Expand All @@ -686,6 +692,7 @@ async def test_medical_aid_list_3(evds_mock, tester: AppTester):
"",
"Please confirm your Medical Aid Provider. REPLY with a NUMBER from "
"the list below:",
"",
"1. De Beers Benefit Society",
"2. BMW Employees Medical Aid Society",
"3. Government Employees Medical Scheme (GEMS)",
Expand Down Expand Up @@ -831,6 +838,9 @@ async def test_state_success(evds_mock, eventstore_mock, tester: AppTester):
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down Expand Up @@ -903,6 +913,9 @@ async def test_state_success_international_phonenumber(
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down Expand Up @@ -974,6 +987,9 @@ async def test_state_success_passport(evds_mock, eventstore_mock, tester: AppTes
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down Expand Up @@ -1046,6 +1062,9 @@ async def test_state_success_asylum_seeker(
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down Expand Up @@ -1114,6 +1133,9 @@ async def test_state_success_refugee(evds_mock, eventstore_mock, tester: AppTest
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down Expand Up @@ -1185,6 +1207,9 @@ async def test_state_success_temporary_failure(evds_mock, tester: AppTester):
"Look out for messages from this number (060 012 3456) on WhatsApp OR "
"on SMS/email. We will update you with important information about "
"your appointment and what to expect.",
"",
"-----",
"📌 Reply *0* to return to the main *MENU*",
]
),
session=Message.SESSION_EVENT.CLOSE,
Expand Down
Loading

0 comments on commit 5b86384

Please sign in to comment.