-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gerrit Vermeulen
committed
Oct 9, 2024
1 parent
e2cca8f
commit 02e591f
Showing
9 changed files
with
298 additions
and
188 deletions.
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
116 changes: 62 additions & 54 deletions
116
...d messaging/schedule_next_push_message.md → ...ng/QA/flows/schedule_next_push_message.md
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,55 +1,63 @@ | ||
<!-- | ||
dictionary: "config" | ||
version: "0.1.0" | ||
columns: [] | ||
--> | ||
|
||
| Key | Value | | ||
| ----------------- | ---------------------------------------- | | ||
| contentrepo_token | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | ||
|
||
This stack schedules the send message callback stack, at the correct time as specified on the current message of the ordered content set. | ||
|
||
It fetches the details from the contentrepo for the user's current content set. | ||
|
||
If there are no more messages in the content set, then it sends the user a message that they've completed the content set. | ||
|
||
It then calculates the timestamp when the next message should be sent, according to the specified contact field and time delta specified in content repo. | ||
|
||
<!-- { section: "c1af92c3-f489-4f4b-8182-865897f83ea1", x: 0, y: 0} --> | ||
|
||
```stack | ||
card GetContentSet, then: ScheduleNextMessage do | ||
contentset = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/orderedcontent/@contact.push_messaging_content_set/", | ||
headers: [ | ||
["Authorization", "Token @config.items.contentrepo_token"] | ||
] | ||
) | ||
end | ||
card ScheduleNextMessage | ||
when count(contentset.body.pages) == contact.push_messaging_content_set_position do | ||
text("Content set complete, no more messages") | ||
end | ||
card ScheduleNextMessage do | ||
page = contentset.body.pages[contact.push_messaging_content_set_position] | ||
contact_field = page.contact_field | ||
unit = | ||
find( | ||
[["minutes", "m"], ["hours", "h"], ["days", "D"], ["months", "M"]], | ||
&(&1[0] == page.unit) | ||
)[1] | ||
offset = if(page.before_or_after == "before", page.time * -1, page.time * 1) | ||
timestamp = datetime_add(contact[contact_field], offset, unit) | ||
# SBM: Schedule message callback | ||
schedule_stack("54e7fe5d-983a-4292-a768-ca2e95466a6a", at: timestamp) | ||
write_result("message_scheduled_at", "@timestamp") | ||
end | ||
# Stage Based Messaging: Schedule Next Push Message | ||
|
||
This stack schedules the send message callback stack, at the correct time as specified on the current message of the ordered content set. | ||
|
||
It fetches the details from the contentrepo for the user's current content set. | ||
|
||
If there are no more messages in the content set, then it sends the user a message that they've completed the content set. | ||
|
||
It then calculates the timestamp when the next message should be sent, according to the specified contact field and time delta specified in content repo. | ||
|
||
## Configuration | ||
|
||
This Journey requires the `config.contentrepo_token` global variable to be set. | ||
|
||
## Contact fields | ||
|
||
This Journey doesn't use or set any contact fields | ||
|
||
## Flow results | ||
|
||
* message_scheduled_at, when the message is scheduled for | ||
|
||
## Connections to other stacks | ||
|
||
* Schedules the stack to send the next push message | ||
|
||
<!-- { section: "c1af92c3-f489-4f4b-8182-865897f83ea1", x: 0, y: 0} --> | ||
|
||
```stack | ||
card GetContentSet, then: ScheduleNextMessage do | ||
contentset = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/orderedcontent/@contact.push_messaging_content_set/", | ||
headers: [ | ||
["Authorization", "Token @global.config.contentrepo_token"] | ||
] | ||
) | ||
end | ||
card ScheduleNextMessage | ||
when count(contentset.body.pages) == contact.push_messaging_content_set_position do | ||
text("Content set complete, no more messages") | ||
end | ||
card ScheduleNextMessage do | ||
page = contentset.body.pages[contact.push_messaging_content_set_position] | ||
contact_field = page.contact_field | ||
unit = | ||
find( | ||
[["minutes", "m"], ["hours", "h"], ["days", "D"], ["months", "M"]], | ||
&(&1[0] == page.unit) | ||
)[1] | ||
offset = if(page.before_or_after == "before", page.time * -1, page.time * 1) | ||
timestamp = datetime_add(contact[contact_field], offset, unit) | ||
# SBM: Schedule message callback | ||
schedule_stack("8eb4490c-dc45-4c1f-bf10-1a95158ef45f", at: timestamp) | ||
write_result("message_scheduled_at", "@timestamp") | ||
end | ||
``` |
149 changes: 78 additions & 71 deletions
149
...d messaging/send_next_message_callback.md → ...ng/QA/flows/send_next_message_callback.md
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,72 +1,79 @@ | ||
<!-- | ||
dictionary: "config" | ||
version: "0.1.0" | ||
columns: [] | ||
--> | ||
|
||
| Key | Value | | ||
| ----------------- | ---------------------------------------- | | ||
| contentrepo_token | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | | ||
|
||
This stack fetches the current message for the current message set, as defined in the contact fields. | ||
|
||
It handles the following message types: | ||
|
||
* Template messages. Assumes template message with two variables. Sets the first to the contact's whatsapp profile name, and the second to the literal "Second" | ||
* Text messages. Sends the title, followed by the body, of the whatsapp message, in a single message to the user. | ||
|
||
It then increments the content set position on the contact, and runs the stack that handles scheduling the next message in the message set. | ||
|
||
<!-- { section: "c1af92c3-f489-4f4b-8182-865897f83ea1", x: 0, y: 0} --> | ||
|
||
```stack | ||
card GetMessage, then: SendMessage do | ||
contentset = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/orderedcontent/@contact.push_messaging_content_set/", | ||
headers: [ | ||
["Authorization", "Token @config.items.contentrepo_token"] | ||
] | ||
) | ||
contentset_item = contentset.body.pages[contact.push_messaging_content_set_position] | ||
page = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/pages/@contentset_item.id/", | ||
headers: [ | ||
["Authorization", "Token @config.items.contentrepo_token"] | ||
], | ||
query: [["whatsapp", "true"]] | ||
) | ||
end | ||
card SendMessage when page.body.body.is_whatsapp_template, then: ScheduleNextMessage do | ||
write_result("template_sent", "@page.body.body.whatsapp_template_name") | ||
send_message_template("@page.body.body.whatsapp_template_name", "en_US", [ | ||
"@contact.whatsapp_profile_name", | ||
"Second" | ||
]) | ||
end | ||
card SendMessage, then: ScheduleNextMessage do | ||
write_result("message_sent", "@page.body.id") | ||
text(""" | ||
@page.body.title | ||
@page.body.body.text.value.message | ||
""") | ||
end | ||
card ScheduleNextMessage do | ||
update_contact( | ||
push_messaging_content_set_position: "@(contact.push_messaging_content_set_position + 1)" | ||
) | ||
# SBM: Schedule next push message | ||
run_stack("f7a966e0-2945-455e-a3d2-519b750e20aa") | ||
end | ||
This stack fetches the current message for the current message set, as defined in the contact fields. | ||
|
||
It handles the following message types: | ||
|
||
* Template messages. Assumes template message with two variables. Sets the first to the contact's whatsapp profile name, and the second to the literal "Second" | ||
* Text messages. Sends the title, followed by the body, of the whatsapp message, in a single message to the user. | ||
|
||
It then increments the content set position on the contact, and runs the stack that handles scheduling the next message in the message set. | ||
|
||
## Configuration | ||
|
||
This Journey requires the `config.contentrepo_token` global variable to be set. | ||
|
||
## Contact fields | ||
|
||
* push_messaging_content_set_position: Start at 0, to always start at the beginning of the message set | ||
* whatsapp_profile_name, used to personalise the template sent to the user | ||
|
||
## Flow results | ||
|
||
* message_sent, The message sent to the user | ||
|
||
## Connections to other stacks | ||
|
||
* Runs the stack to schedule the next push message at the end | ||
|
||
<!-- { section: "c1af92c3-f489-4f4b-8182-865897f83ea1", x: 0, y: 0} --> | ||
|
||
```stack | ||
card GetMessage, then: SendMessage do | ||
contentset = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/orderedcontent/@contact.push_messaging_content_set/", | ||
headers: [ | ||
["Authorization", "Token @global.config.contentrepo_token"] | ||
] | ||
) | ||
contentset_item = contentset.body.pages[contact.push_messaging_content_set_position] | ||
page = | ||
get( | ||
"https://content-repo-api-qa.prk-k8s.prd-p6t.org/api/v2/pages/@contentset_item.id/", | ||
headers: [ | ||
["Authorization", "Token @global.config.contentrepo_token"] | ||
], | ||
query: [["whatsapp", "true"]] | ||
) | ||
end | ||
card SendMessage when page.body.body.is_whatsapp_template, then: ScheduleNextMessage do | ||
write_result("template_sent", "@page.body.body.whatsapp_template_name") | ||
send_message_template("@page.body.body.whatsapp_template_name", "en_US", [ | ||
"@contact.whatsapp_profile_name", | ||
"Second" | ||
]) | ||
end | ||
card SendMessage, then: ScheduleNextMessage do | ||
write_result("message_sent", "@page.body.id") | ||
text(""" | ||
@page.body.title | ||
@page.body.body.text.value.message | ||
""") | ||
end | ||
card ScheduleNextMessage do | ||
update_contact( | ||
push_messaging_content_set_position: "@(contact.push_messaging_content_set_position + 1)" | ||
) | ||
# SBM: Schedule next push message | ||
run_stack("f291b782-72d3-49eb-8434-e47e388c2ea1") | ||
end | ||
``` |
Oops, something went wrong.