Skip to content
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

Add facebook survey invite flow #732

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions yal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@
QA_OVERRIDE_CURRENT_TIMESTAMP = environ.get("QA_OVERRIDE_CURRENT_TIMESTAMP", None)
STUDY_CONSENT_FORM_PDF = environ.get("STUDY_CONSENT_FORM_PDF", "1/sample.pdf")
LOCATION_STUDY_GROUP_LIMIT = int(environ.get("LOCATION_STUDY_GROUP_LIMIT", "430"))
FACEBOOK_SURVEY_INVITE_MEMBERS_URL = environ.get(
"FACEBOOK_SURVEY_INVITE_MEMBERS_URL",
"https://docs.google.com/forms/d/e/1FAIpQLScjbZEbIjQXMDdHbJTUCjxYnbRVP4D2p6kXQy74tXrIN6Qwww/viewform?usp=sf_link", # noqa: E501
)
FACEBOOK_SURVEY_INVITE_SEEN_FEED_URL = environ.get(
"FACEBOOK_SURVEY_INVITE_SEEN_FEED_URL",
"https://docs.google.com/forms/d/e/1FAIpQLSe_YlROLiezkGFbdcK7HBA99ABrWvUcvZ20azvAEpQKHwr6kw/viewform?usp=sf_link", # noqa: E501
)
26 changes: 26 additions & 0 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from yal.servicefinder_feedback_survey import ServiceFinderFeedbackSurveyApplication
from yal.surveys.baseline import Application as BaselineSurveyApplication
from yal.surveys.endline import Application as EndlineSurveyApplication
from yal.surveys.facebook_invite import Application as FacebookInviteApplication
from yal.surveys.location import Application as LocationSurveyApplication
from yal.terms_and_conditions import Application as TermsApplication
from yal.usertest_feedback import Application as FeedbackApplication
Expand Down Expand Up @@ -97,6 +98,10 @@
"start survey",
"i m not interested",
}
FACEBOOK_INVITE_KEYWORDS = {
"yes take part",
"no thanks",
}


class Application(
Expand All @@ -119,6 +124,7 @@ class Application(
EndlineSurveyApplication,
EndlineTermsApplication,
LocationSurveyApplication,
FacebookInviteApplication,
):
START_STATE = "state_start"

Expand Down Expand Up @@ -296,6 +302,26 @@ async def process_message(self, message):
self.state_name = LocationSurveyApplication.NOT_INTERESTED_STATE
else:
self.state_name = LocationSurveyApplication.START_STATE
elif (
keyword in FACEBOOK_INVITE_KEYWORDS
and self.user.metadata.get("facebook_survey_invite_status") == "sent"
):
self.user.session_id = None
invite_state = "responded_no"
if keyword == "no thanks":
self.state_name = FacebookInviteApplication.NOT_INTERESTED_STATE
else:
self.state_name = FacebookInviteApplication.START_STATE
invite_state = "responded_yes"

data = {
"facebook_survey_invite_status": invite_state,
}
error = await rapidpro.update_profile(
whatsapp_id, data, self.user.metadata
)
if error:
self.state_name = self.ERROR_STATE

except Exception:
logger.exception("Application error")
Expand Down
117 changes: 117 additions & 0 deletions yal/surveys/facebook_invite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from vaccine.base_application import BaseApplication
from vaccine.states import Choice, EndState, WhatsAppButtonState
from yal import config
from yal.utils import get_generic_error


class Application(BaseApplication):
START_STATE = "state_facebook_member"
NOT_INTERESTED_STATE = "state_facebook_invite_decline"

async def state_facebook_member(self):
async def _next(choice: Choice):
if choice.value == "no":
return "state_not_a_member"
return "state_was_a_member"

return WhatsAppButtonState(
self,
question=self._(
"Great! Before we get started, have you been a member of the B-Wise "
"Facebook page since before June 2023?"
),
choices=[
Choice("yes", "Yes"),
Choice("no", "No"),
],
next=_next,
error=self._(get_generic_error()),
)

async def state_was_a_member(self):
return EndState(
self,
self._(
"\n".join(
[
"Excellent! Thank you for being a valuable member of our "
"Facebook community.",
"",
"To do the survey, click on the link below, answer the "
"questions and you’re all done!",
"",
config.FACEBOOK_SURVEY_INVITE_MEMBERS_URL,
]
)
),
next=self.START_STATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next state shouldn't be start state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats the standard for EndState

)

async def state_not_a_member(self):
async def _next(choice: Choice):
if choice.value == "no":
return "state_fb_feed_not_seen"
return "state_fb_feed_seen"

return WhatsAppButtonState(
self,
question=self._("Have you seen a post by B-Wise on your Facebook feed?"),
choices=[
Choice("yes", "Yes"),
Choice("no", "No"),
],
next=_next,
error=self._(get_generic_error()),
)

async def state_fb_feed_seen(self):
return EndState(
self,
self._(
"\n".join(
[
"That’s great! The B-Wise Facebook community is a great place "
"for cheeky memes and thought-provoking posts.",
"",
"Now on to the survey! Click on the link below, answer the "
"questions and you’re all done!",
"",
config.FACEBOOK_SURVEY_INVITE_SEEN_FEED_URL,
]
)
),
next=self.START_STATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next state shouldn't be start_state

)

async def state_fb_feed_not_seen(self):
return EndState(
self,
self._(
"\n".join(
[
"No sweat! We won’t ask you to do the survey though, since we "
"are only looking for people who are members of the B-Wise "
"Facebook community or who have seen B-Wise posts on Facebook.",
"",
"Please enjoy the B-Wise tool and stay safe.",
]
)
),
next=self.START_STATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next state shouldn't be start_state

)

async def state_facebook_invite_decline(self):
return EndState(
self,
self._(
"\n".join(
[
"That's completely okay! This won’t affect your experience on "
"the B-Wise chatbot.",
"",
"Please enjoy the B-Wise tool and stay safe.",
]
)
),
next=self.START_STATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next state shouldn't be start_state

)
11 changes: 11 additions & 0 deletions yal/tests/states_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -829,3 +829,14 @@
| state_location_decline | FALSE | text | Tells users there are no consequences for not joining study
| state_location_update_invalid_province | FALSE | text | Updates the ejaf_location_survey_status contact field on rapidpro
| state_location_invalid_province | FALSE | text | Tells them they are not eligible for the survey


## Facebook Survey Invite
| state_name | accepts_user_input | data_type | added_to_flow_results_app | description |
| ----------------------------- | ------------------ | --------- | ------------------------- | ----------------------------------------------------------------|
| state_facebook_member | TRUE | Text | TRUE | Asks user if they've been a member of the bwise facebook group. |
| state_was_a_member | FALSE | | | Shows user the relavant survey link |
| state_not_a_member | TRUE | Text | TRUE | Asks user if they've seen a bwise post in their FB feed |
| state_fb_feed_seen | FALSE | | | Shows user the relavant survey link |
| state_fb_feed_not_seen | FALSE | | | Tells user they're not eligible |
| state_facebook_invite_decline | FALSE | | | Confirmation message |
Loading
Loading