Skip to content

Commit

Permalink
create WhatsAppTextOnlyFreetext
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Aug 22, 2023
1 parent 966fae6 commit fc94976
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions vaccine/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def __init__(
override_answer_name: Optional[str] = None,
footer: Optional[str] = None,
header: Optional[str] = None,
text_only_error: Optional[str] = None,
):
self.app = app
self.question = question
Expand All @@ -226,12 +225,8 @@ def __init__(
self.override_answer_name = override_answer_name
self.footer = footer
self.header = header
self.text_only_error = text_only_error

async def process_message(self, message: Message):
if self.text_only_error is not None and message.transport_metadata:
if message.transport_metadata.get("message", {}).get("type") != "text":
return self.app.send_message(self.text_only_error)
if self.check is not None:
if not isinstance(self.check, list):
self.check = [self.check]
Expand Down Expand Up @@ -259,6 +254,23 @@ async def display(self, message: Message):
return self.app.send_message(text, helper_metadata=helper_metadata)


class WhatsAppTextOnlyFreetext(FreeText):
def __init__(
self,
*args,
text_only_error: Optional[str] = None,
**kwargs,
):
super().__init__(*args, **kwargs)
self.text_only_error = text_only_error

async def process_message(self, message: Message):
if self.text_only_error is not None and message.transport_metadata:
if message.transport_metadata.get("message", {}).get("type") != "text":
return self.app.send_message(self.text_only_error)
return await super().process_message(message)


class BaseWhatsAppChoiceState(ChoiceState):
"""
Base class for all whatsapp choice states.
Expand Down
4 changes: 2 additions & 2 deletions yal/surveys/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from vaccine.states import (
Choice,
EndState,
FreeText,
WhatsAppButtonState,
WhatsAppListState,
WhatsAppTextOnlyFreetext,
)
from vaccine.validators import nonempty_validator
from yal import config, contentrepo, rapidpro
Expand Down Expand Up @@ -258,7 +258,7 @@ async def state_location_name_city(self):
]
)
)
return FreeText(
return WhatsAppTextOnlyFreetext(
self,
question=question,
next="state_location_area_type",
Expand Down

0 comments on commit fc94976

Please sign in to comment.