Skip to content

Commit

Permalink
Merge pull request #55 from praekeltfoundation/fix-edd-reminders
Browse files Browse the repository at this point in the history
Send a template first due to WA rules
  • Loading branch information
HawkiesZA authored Oct 3, 2024
2 parents 6269387 + b4119f7 commit 1481ccf
Show file tree
Hide file tree
Showing 6 changed files with 859 additions and 9,431 deletions.
121 changes: 73 additions & 48 deletions Onboarding/Prod/flows/edd-reminders.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,55 @@
# EDD Reminder
## EDD Reminder

This is the EDD Reminder flow that gets triggered if the user selects that the EDD month is unknown.

This flow is scheduled to be run 5 days later, so it must start with a template message as per WA requirements.

## Contact fields

* `edd`, saves the EDD if the user chooses to update it

## Flow results

* `edd`, saves the EDD if the user chooses to update it

## Connections to other stacks

The user can navigate to either of these options at the end of this flow. (Currently both of these are placeholders that navigate the user to the Profile Pregnancy Health Flow)

* Main Menu
* Health Guide

## Auth

The token for ContentRepo is stored in a global dictionary.

## Content dependancies

Content is stored in the content repo, and referenced in the stack by slug. This means that we require the following slugs to be present in the contentrepo, and we're making the following assumptions:

* `mnch_onboarding_edd_reminder`, The EDD reminder message. The message isn't actually used as it's part of the template, but we need the button text saved as part of the message.
* `mnch_onboarding_edd_got_it`, The message the user sees if they tap on the Got it button in the EDD reminder
* `mnch_onboarding_edd_month`, A message asking the user for the EDD month
* `mnch_onboarding_edd_unknown`, A message stressing the importance of knowing the EDD
* `mnch_onboarding_edd_day`, A message asking the user for the EDD day
* `mnch_onboarding_edd_confirmed`, A message confirming the EDD
* `mnch_onboarding_edd_do_it_later`, A message that gets displayed if the user says they'll fill in the EDD later

## Error messages

* `mnch_onboarding_error_handling_button`, for when a user sends in a message when we're expecting them to press one of the buttons
* `mnch_onboarding_error_handling_list_message`, for when a user sends in a message when we're expecting them to press one of the list options
* `mnch_onboarding_unrecognised_number`, for when a user sends in a message that contains a number that doesn't match our validation

```stack
trigger(on: "MESSAGE RECEIVED") when has_only_phrase(event.message.text.body, "eddreminder")
```

## Setup

Here we do any setup and fetching of values before we start the flow.

```stack
card FetchError, then: EDDReminder do
# Fetch and store the error message, so that we don't need to do it for every error card
Expand Down Expand Up @@ -78,6 +123,8 @@ end
```

## EDD Reminder

<!-- { section: "6053de2e-cff0-4e46-9682-b623e3b3e36e", x: 0, y: 0} -->

```stack
Expand All @@ -103,20 +150,19 @@ card EDDReminder, then: DisplayEDDReminder do
)
message = content_data.body.body.text.value
loading_message = substitute(message.message, "{@username}", "@contact.name")
whatsapp_template_name = content_data.body.body.whatsapp_template_name
button_labels = map(message.buttons, & &1.value.title)
end
# Text only
card DisplayEDDReminder when contact.data_preference == "text only",
then: DisplayEDDReminderError do
buttons(
EDDGotIt: "@button_labels[0]",
EDDMonth: "@button_labels[1]",
EDDRUnknown: "@button_labels[2]"
) do
text("@loading_message")
end
send_message_template(
"@whatsapp_template_name",
"en",
["@contact.name"],
buttons: [EDDGotIt, EDDMonth, EDDRUnknown]
)
end
# Display with image
Expand All @@ -131,14 +177,13 @@ card DisplayEDDReminder, then: DisplayEDDReminderError do
]
)
buttons(
EDDGotIt: "@button_labels[0]",
EDDMonth: "@button_labels[1]",
EDDRUnknown: "@button_labels[2]"
) do
image("@image_data.body.meta.download_url")
text("@loading_message")
end
send_message_template(
"@whatsapp_template_name",
"en",
["@contact.name"],
image: "@image_data.body.meta.download_url",
buttons: [EDDGotIt, EDDMonth, EDDRUnknown]
)
end
card DisplayEDDReminderError, then: DisplayEDDReminderError do
Expand All @@ -153,10 +198,10 @@ end
```

# EDD Got It
## EDD Got It

```stack
card EDDGotIt, then: DisplayEDDGotIt do
card EDDGotIt, "@button_labels[0]", then: DisplayEDDGotIt do
search =
get(
"https://platform-mnch-contentrepo.prk-k8s.prd-p6t.org/api/v2/pages/",
Expand Down Expand Up @@ -195,10 +240,10 @@ end
```

# EDD Month
## EDD Month

```stack
card EDDMonth, then: EDDMonthError do
card EDDMonth, "@button_labels[1]", then: EDDMonthError do
search =
get(
"https://platform-mnch-contentrepo.prk-k8s.prd-p6t.org/api/v2/pages/",
Expand Down Expand Up @@ -248,26 +293,6 @@ card EDDMonth, then: EDDMonthError do
end
card EDDMonthError, then: EDDMonthError do
search =
get(
"https://platform-mnch-contentrepo.prk-k8s.prd-p6t.org/api/v2/pages/",
query: [
["slug", "edd-month-error"]
],
headers: [["Authorization", "Token @global.config.contentrepo_token"]]
)
page_id = search.body.results[0].id
page =
get(
"https://platform-mnch-contentrepo.prk-k8s.prd-p6t.org/api/v2/pages/@page_id/",
headers: [
["Authorization", "Token @global.config.contentrepo_token"]
],
query: [["whatsapp", "true"]]
)
list("Month", [
ThisMonth,
ThisMonthPlusOne,
Expand Down Expand Up @@ -372,7 +397,7 @@ end
```

# EDD Day
## EDD Day

```stack
card EDDDay, then: ValidateEDDDay do
Expand Down Expand Up @@ -438,15 +463,15 @@ end
card SaveEDDAndContinue, then: EDDConfirm do
edd_date_full = date(edd_date_year, edd_date_month, edd_day)
edd_date_full_str = datevalue(edd_date_full, "%Y/%m/%d")
edd_date_full_str = datevalue(edd_date_full, "%Y-%m-%d")
log("EDD Saved as @edd_date_full_str")
update_contact(edd: "@edd_date_full_str")
write_result("edd", "@edd_date_full_str")
end
```

# EDD Confirm
## EDD Confirm

```stack
card EDDConfirm, then: DisplayEDDConfirm do
Expand Down Expand Up @@ -489,10 +514,10 @@ end
```

# EDD Unknown
## EDD Unknown

```stack
card EDDRUnknown, then: DisplayEDDUnknown do
card EDDRUnknown, "@button_labels[2]", then: DisplayEDDUnknown do
search =
get(
"https://platform-mnch-contentrepo.prk-k8s.prd-p6t.org/api/v2/pages/",
Expand Down Expand Up @@ -560,7 +585,7 @@ end
```

# EDD Do It Later
## EDD Do It Later

```stack
card EDDLater, then: DisplayEDDLater do
Expand Down Expand Up @@ -602,7 +627,7 @@ card DisplayEDDLaterError, then: DisplayEDDLaterError do
MainMenu: "@button_labels[0]",
HealthGuide: "@button_labels[1]"
) do
text("@message.message")
text("@button_error_text")
end
end
Expand Down
Loading

0 comments on commit 1481ccf

Please sign in to comment.