-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
endline validation #649
Merged
Merged
endline validation #649
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import asyncio | ||
import logging | ||
import random | ||
|
||
from vaccine.models import Message | ||
from vaccine.states import Choice, EndState, WhatsAppButtonState | ||
from vaccine.states import Choice, EndState, FreeText, WhatsAppButtonState | ||
from vaccine.utils import get_display_choices, random_id | ||
from yal import rapidpro, utils | ||
from yal.askaquestion import Application as AaqApplication | ||
|
@@ -202,6 +203,7 @@ async def process_message(self, message): | |
) | ||
|
||
endline_survey_started = self.user.metadata.get("endline_survey_started") | ||
endline_reminder = self.user.metadata.get("endline_reminder") | ||
|
||
if ( | ||
keyword in EJAF_ENDLINE_SURVEY_KEYWORDS | ||
|
@@ -215,7 +217,7 @@ async def process_message(self, message): | |
self.user.session_id = None | ||
self.state_name = AssessmentApplication.REMINDER_STATE | ||
elif keyword == "i m not interested": | ||
if endline_survey_started: | ||
if endline_reminder: | ||
self.user.session_id = None | ||
self.state_name = ( | ||
AssessmentApplication.REMINDER_NOT_INTERESTED_STATE | ||
|
@@ -227,6 +229,10 @@ async def process_message(self, message): | |
self.user.session_id = None | ||
self.state_name = EndlineTermsApplication.START_STATE | ||
|
||
if endline_survey_started and not self.state_name: | ||
self.user.session_id = None | ||
self.state_name = "state_survey_validation" | ||
|
||
# Fields that RapidPro sets after a feedback push message | ||
feedback_state = await self.get_feedback_state() | ||
if feedback_state: | ||
|
@@ -855,3 +861,24 @@ 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 | ||
""" | ||
|
||
GENERIC_ERRORS = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we import these from the other place they are defined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wording is different |
||
"Oh oh 👀, I don't understand your reply. But don't worry, we can " | ||
"try again. This time, please reply with the option that matches " | ||
"your choice.👍🏾", | ||
"Oops, looks like I don't have that option available.🤔 Please " | ||
"try again - I'll get it if you use the option that matches your " | ||
"choice, promise.👍🏾", | ||
"Umm...I'm sorry but I'm not sure what that means " | ||
"[persona_emoji]👩🏾. You can help me by trying again. This time, " | ||
"look for the option matching your choice and send that👍🏾", | ||
) | ||
|
||
random_error = random.choice(GENERIC_ERRORS) | ||
|
||
return FreeText(self, question=random_error, next=None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
main.py
the right place for this state? It's very survey specific so maybe it should live there?