Skip to content

Commit

Permalink
move survey validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlamallama committed Aug 1, 2023
1 parent fc76e75 commit e423368
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
13 changes: 2 additions & 11 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from vaccine.models import Message
from vaccine.states import Choice, EndState, FreeText, WhatsAppButtonState
from vaccine.states import Choice, EndState, WhatsAppButtonState
from vaccine.utils import get_display_choices, random_id
from yal import rapidpro, utils
from yal.askaquestion import Application as AaqApplication
Expand All @@ -25,7 +25,6 @@
from yal.utils import (
get_current_datetime,
get_generic_error,
get_generic_error_options,
is_integer,
normalise_phonenumber,
replace_persona_fields,
Expand Down Expand Up @@ -231,7 +230,7 @@ async def process_message(self, message):

if endline_survey_started and not self.state_name:
self.user.session_id = None
self.state_name = "state_survey_validation"
self.state_name = EndlineSurveyApplication.SURVEY_VALIDATION_STATE

# Fields that RapidPro sets after a feedback push message
feedback_state = await self.get_feedback_state()
Expand Down Expand Up @@ -861,11 +860,3 @@ async def publish_message(self, question):
"""
content = replace_persona_fields(question, self.user.metadata)
await self.worker.publish_message(self.inbound.reply(content))

async def state_survey_validation(self):
"""
Validates survey keywords from RapidPro
"""
random_error = get_generic_error_options()

return FreeText(self, question=random_error, next=None)
18 changes: 16 additions & 2 deletions yal/surveys/endline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
import logging

from vaccine.base_application import BaseApplication
from vaccine.states import Choice, WhatsAppButtonState
from vaccine.states import Choice, FreeText, WhatsAppButtonState
from yal import rapidpro
from yal.askaquestion import Application as AAQApplication
from yal.assessments import Application as AssessmentApplication
from yal.change_preferences import Application as ChangePreferencesApplication
from yal.utils import get_current_datetime, get_generic_error, normalise_phonenumber
from yal.utils import (
get_current_datetime,
get_generic_error,
get_generic_error_options,
normalise_phonenumber,
)

logger = logging.getLogger(__name__)

Expand All @@ -16,6 +21,7 @@ class Application(BaseApplication):
depression_score = 0
anxiety_score = 0
START_STATE = "state_endline_start"
SURVEY_VALIDATION_STATE = "state_survey_validation"

async def set_endline_reminder_timer(self):
msisdn = normalise_phonenumber(self.inbound.from_addr)
Expand Down Expand Up @@ -468,3 +474,11 @@ async def state_endline_end(self):
},
error=self._(get_generic_error()),
)

async def state_survey_validation(self):
"""
Validates survey keywords from RapidPro
"""
random_error = get_generic_error_options()

return FreeText(self, question=random_error, next=None)

0 comments on commit e423368

Please sign in to comment.