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 footer to wa message #245

Merged
merged 22 commits into from
Feb 6, 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
4 changes: 4 additions & 0 deletions home/export_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ExportRow:
doc_link: str = ""
media_link: str = ""
related_pages: str = ""
footer: str = ""

@classmethod
def headings(cls) -> list[str]:
Expand Down Expand Up @@ -133,6 +134,8 @@ def add_message_fields(self, msg_blocks: MsgBlocks) -> None:
self.buttons = self.serialise_buttons(whatsapp.value["buttons"])
if "example_values" in whatsapp.value:
self.example_values = ", ".join(whatsapp.value["example_values"])
if "footer" in whatsapp.value:
self.footer = whatsapp.value["footer"]
if "list_items" in whatsapp.value:
self.list_items = ", ".join(whatsapp.value["list_items"])

Expand Down Expand Up @@ -344,6 +347,7 @@ def _set_xlsx_styles(wb: Workbook, sheet: Worksheet) -> None:
"doc_link": 118,
"media_link": 118,
"related": 118,
"footer": 118,
}

for index, column_width in enumerate(column_widths_in_pts.values(), 2):
Expand Down
5 changes: 5 additions & 0 deletions home/import_content_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ def add_message_to_shadow_content_page_from_row(
next_prompt=row.next_prompt,
example_values=row.example_values,
buttons=buttons,
footer=row.footer,
list_items=row.list_items,
)
)
Expand Down Expand Up @@ -530,6 +531,7 @@ class ShadowWhatsappBlock:
example_values: list[str] = field(default_factory=list)
variation_messages: list["ShadowVariationBlock"] = field(default_factory=list)
list_items: list[str] = field(default_factory=list)
footer: str = ""

@property
def wagtail_format(
Expand All @@ -542,6 +544,7 @@ def wagtail_format(
"buttons": self.buttons,
"variation_messages": [m.wagtail_format for m in self.variation_messages],
"list_items": self.list_items,
"footer": self.footer,
}


Expand Down Expand Up @@ -631,6 +634,7 @@ class ContentRow:
doc_link: str = ""
media_link: str = ""
related_pages: list[str] = field(default_factory=list)
footer: str = ""

@classmethod
def from_flat(cls, row: dict[str, str]) -> "ContentRow":
Expand All @@ -651,6 +655,7 @@ def from_flat(cls, row: dict[str, str]) -> "ContentRow":
example_values=deserialise_list(row.pop("example_values", "")),
buttons=json.loads(row.pop("buttons", "")) if row.get("buttons") else [],
list_items=deserialise_list(row.pop("list_items", "")),
footer=row.pop("footer") if row.get("footer") else "",
**row,
)

Expand Down
15 changes: 14 additions & 1 deletion home/migrations/0048_alter_contentpage_whatsapp_body.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.13 on 2024-01-30 15:25
# Generated by Django 4.1.10 on 2024-02-01 13:02

import django.core.validators
import wagtail.blocks
Expand Down Expand Up @@ -190,6 +190,18 @@ class Migration(migrations.Migration):
),
),
),
(
"footer",
wagtail.blocks.CharBlock(
help_text="Footer cannot exceed 60 characters.",
required=False,
validators=(
django.core.validators.MaxLengthValidator(
60
),
),
),
),
],
help_text="Each message will be sent with the text and media",
),
Expand All @@ -201,3 +213,4 @@ class Migration(migrations.Migration):
),
),
]

8 changes: 7 additions & 1 deletion home/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re

from django.conf import settings
Expand Down Expand Up @@ -40,7 +41,6 @@
TabbedInterface,
TitleFieldPanel,
)
import logging

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -265,6 +265,12 @@ class WhatsappBlock(blocks.StructBlock):
validators=(MaxLengthValidator(24)),
)

footer = blocks.CharBlock(
help_text="Footer cannot exceed 60 characters.",
required=False,
validators=(MaxLengthValidator(60),),
)

class Meta:
icon = "user"
form_classname = "whatsapp-message-block struct-block"
Expand Down
10 changes: 5 additions & 5 deletions home/tests/content2.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values
Menu 1,0,,main-menu,,Main Menu,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,[]
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values,footer
Menu 1,0,,main-menu,,Main Menu,,,,,,,,,,,,,,,,a0b85075-d01b-46bf-8997-8591e87ba171,,,,English,,,,,,,[],
Sub 1.1,1,,main-menu-first-time-user,Main Menu,main menu first time user,,,main menu first time user," *Welcome to HealthAlert* 🌍

This is a messaging service created by the _*World Health Organization*_ *(WHO)* that provides information on COVID-19 as well as emergency resources for disease outbreaks, natural, and man-made disasters.
Expand All @@ -12,12 +12,12 @@ This is a messaging service created by the World Health Organization (WHO) that

You can return to this main menu at any time by replying 🏠

Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,[]
Choose what you'd like to know more about by tapping a button below ⬇️",,,5892bccd-8025-419d-9a8e-a6a37b755dbf,menu,"Self-help🌬️, Settings⚙️, Health Info🏥",Main menu🏠,English,,[],,,,,[],
Sub 1.1.1,1,,health-info,main menu first time user,health info,,,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,,,Health Info SMS Title,*Health Info SMS Body*,Health Info USSD Title,*Health Info USSD Body*,health info,"*Health information* 🏥

Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,[]
Get information and advice from WHO by tapping on a button below ⬇️",,,c9d6309e-173f-4c1d-bbaf-440b1fd4415f,health_info,,,English,,[],,,,,[],
Sub 1.1.2,1,,self-help,main menu first time user,self-help,,,self-help,"*Self-help programs* 🌬️

Reply with a number to take part in a *free* self-help program created by WHO.
Expand All @@ -32,4 +32,4 @@ Reply with a number to take part in a *free* self-help program created by WHO.
1. Quit tobacco 🚭
_Stop smoking with the help of a guided, 42-day program._
2. Manage your stress 🧘🏽‍♀️
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,[]
_Learn how to cope with stress and improve your wellbeing._",,,3e5d77f7-4d34-430d-aad7-d9ca01f79732,self_help,,,English,,[],,,,,[],
24 changes: 12 additions & 12 deletions home/tests/exported_content_20230911-variations-linked-page.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values
Menu 1,0,5,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,,
Menu 2,0,6,stage-based-messages,,Stage-based messages,,,,,,,,,,,,,,,,,5f2d9e63-f047-41ab-921a-c5ca7c04d643,,,,English,,,,,,,
Menu 3,0,7,health-info-messages,,Health info messages,,,,,,,,,,,,,,,,,3db069a4-7112-4e66-a9a2-f35c6c18055a,,,,English,,,,,,,
Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,,,5f7221f4-146a-48c2-b2e3-c8491aaead9d,,,,English,,,,,,,
Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,
Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,
,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,
,2,165,cp-import-export,,,,,,"Message2 has a document attached, lets add some variable placeholders as well {{0}}",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,
,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,
,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,
Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,example_values,footer
Menu 1,0,5,appointment-reminders,,Appointment reminders,,,,,,,,,,,,,,,,,8cff04aa-cf08-4120-88b4-e2269b7d5d80,,,,English,,,,,,,,
Menu 2,0,6,stage-based-messages,,Stage-based messages,,,,,,,,,,,,,,,,,5f2d9e63-f047-41ab-921a-c5ca7c04d643,,,,English,,,,,,,,
Menu 3,0,7,health-info-messages,,Health info messages,,,,,,,,,,,,,,,,,3db069a4-7112-4e66-a9a2-f35c6c18055a,,,,English,,,,,,,,
Menu 4,0,17,whatsapp-template-testing,,whatsapp template testing,,,,,,,,,,,,,,,,,5f7221f4-146a-48c2-b2e3-c8491aaead9d,,,,English,,,,,,,,
Menu 5,0,164,import-export,,Import Export,,,,,,,,,,,,,,,,,497bdc1f-43fc-4925-80a1-e68cb942faa4,,,,English,,,,,,,,
Sub 5.1,1,165,cp-import-export,Import Export,CP-Import/export,,,WA import export data,Message 1 contains an image,,,,,,,,,,,,,8ac50daf-de21-4d05-b697-6d983b7ed3d5,"Tag2, Tag1",Quick reply1,"Trigger2, Trigger1",English,,[],/admin/images/usage/4/,,,ma_qa_temp,,
,1,165,cp-import-export,,,,,,,,gender: male,Variation message one for Gender Male,,,,,,,,,,,,,,,,,,,,,,
,2,165,cp-import-export,,,,,,"Message2 has a document attached, lets add some variable placeholders as well {{0}}",,,,,,,,,,,,,,,,,,,[],,/admin/documents/usage/1/,,,,
,2,165,cp-import-export,,,,,,,,gender: empty,Variation message one for Gender Rather not say,,,,,,,,,,,,,,,,,,,,,,
,3,165,cp-import-export,,,,,,Message 3 with no variation but has an audio clip,,,,,,,,,,,,,,,,,,,[],,,/admin/media/usage/1/,,,
Sub 5.2,1,166,ma_qa_temp,Import Export,MA QA Temp,,,,,,,,,,,,,,,,,e9793b5f-f8c7-46c5-8a5e-bd9b8f00fee9,,,,English,,,,,,,,
6 changes: 3 additions & 3 deletions home/tests/list_items.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,"['Item 1', 'Item 2']",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,"['Item 1', 'Item 2']",,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,
16 changes: 8 additions & 8 deletions home/tests/multiple_messages.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,,,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,
Sub 1.1.1,1,602,health-info,HealthAlert menu,health info,,,health info,wa1,,UTILITY,,,,,,,,health info,m1,health info,v1,117e862d-57dd-4be6-a802-cdc075a725b2,,,,English,,[],,,,
,2,602,health-info,,,,,,wa2,,,,,,,,,,,m2,,v2,,,,,,,[],,,,
,3,602,health-info,,,,,,wa3,,,,,,,,,,,m3,,v3,,,,,,,[],,,,
,4,602,health-info,,,,,,wa4,,,,,,,,,,,m4,,,,,,,,,[],,,,
,5,602,health-info,,,,,,wa5,,,,,,,,,,,,,,,,,,,,[],,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,600,main-menu,,Main Menu,,,,,,,,,,,,,,,,,,35a7f12c-7373-42a6-9ca6-a1caedea5822,,,,English,,,,,,,
Sub 1.1,1,601,ha-menu,Main Menu,HealthAlert menu,,,HealthAlert menu,*Welcome to HealthAlert* WA,,UTILITY,,,,,,,,HealthAlert menu,Welcome to HealthAlert M,HealthAlert menu,Welcome to HealthAlert V,5ab08854-228b-4f83-ae54-ec2dc6ebaf69,,,,English,,[],,,,,
Sub 1.1.1,1,602,health-info,HealthAlert menu,health info,,,health info,wa1,,UTILITY,,,,,,,,health info,m1,health info,v1,117e862d-57dd-4be6-a802-cdc075a725b2,,,,English,,[],,,,,
,2,602,health-info,,,,,,wa2,,,,,,,,,,,m2,,v2,,,,,,,[],,,,,
,3,602,health-info,,,,,,wa3,,,,,,,,,,,m3,,v3,,,,,,,[],,,,,
,4,602,health-info,,,,,,wa4,,,,,,,,,,,m4,,,,,,,,,[],,,,,
,5,602,health-info,,,,,,wa5,,,,,,,,,,,,,,,,,,,,[],,,,,
6 changes: 3 additions & 3 deletions home/tests/no-translation-key-default.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages
Menu 1,0,659,ma_import-export,,MA_import export,,,,,,,,,,,,,,,,,,,,,,,English,,,,,,
Sub 1.1,1,660,locale-import,MA_import export,Locale import,,,import per locale,this is the english message..edit,,UTILITY,,,,,,,,,,,,,,,,,English,,[],,,,
structure,message,page_id,slug,parent,web_title,web_subtitle,web_body,whatsapp_title,whatsapp_body,whatsapp_template_name,whatsapp_template_category,example_values,variation_title,variation_body,list_items,sms_title,sms_body,ussd_title,ussd_body,messenger_title,messenger_body,viber_title,viber_body,translation_tag,tags,quick_replies,triggers,locale,next_prompt,buttons,image_link,doc_link,media_link,related_pages,footer
Menu 1,0,659,ma_import-export,,MA_import export,,,,,,,,,,,,,,,,,,,,,,,English,,,,,,,
Sub 1.1,1,660,locale-import,MA_import export,Locale import,,,import per locale,this is the english message..edit,,UTILITY,,,,,,,,,,,,,,,,,English,,[],,,,,
1 change: 1 addition & 0 deletions home/tests/page_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class WABlk(ContentBlock):
example_values: list[str] = field(default_factory=list)
buttons: list[Btn] = field(default_factory=list)
list_items: list[str] = field(default_factory=list)
footer: str = ""

def to_dict(self) -> dict[str, Any]:
varmsgs = [vm.to_dict() for vm in self.variation_messages]
Expand Down
34 changes: 34 additions & 0 deletions home/tests/test_content_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,40 @@ def test_translations_en(self, impexp: ImportExport) -> None:
imported = impexp.get_page_json()
assert imported == orig_en

def test_footer(self, impexp: ImportExport) -> None:
"""
ContentPages with footer in whatsapp messages are preserved
across export/import.
"""
home_page = HomePage.objects.first()
main_menu = PageBuilder.build_cpi(home_page, "main-menu", "Main Menu")

ha_menu = PageBuilder.build_cp(
parent=main_menu,
slug="ha-menu",
title="HealthAlert menu",
bodies=[WABody("HealthAlert menu", [WABlk("*Welcome to HealthAlert* WA")])],
)

footer = "Test footer"
_health_info = PageBuilder.build_cp(
parent=ha_menu,
slug="health-info",
title="health info",
bodies=[
WABody(
"health info",
[WABlk("*Health information* WA", footer=footer)],
)
],
whatsapp_template_name="template-health-info",
)

orig = impexp.get_page_json()
impexp.export_reimport()
imported = impexp.get_page_json()
assert imported == orig

def test_example_values(self, impexp: ImportExport) -> None:
"""
ContentPages with example values in whatsapp messages are preserved
Expand Down
2 changes: 2 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def create_message_value(
next_prompt="",
buttons=None,
list_items=None,
footer="",
):
return {
"image": image,
Expand All @@ -357,6 +358,7 @@ def create_message_value(
"next_prompt": next_prompt,
"buttons": buttons or [],
"list_items": list_items or [],
"footer": footer,
}

def create_image(self, width=0, height=0):
Expand Down
4 changes: 4 additions & 0 deletions home/tests/test_page_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def test_build_simple_pages() -> None:
"buttons": [],
"example_values": [],
"variation_messages": [],
"footer": "",
},
),
]
Expand Down Expand Up @@ -261,6 +262,7 @@ def test_build_variations() -> None:
{"message": "Single male", "variation_restrictions": v_single_male},
{"message": "Comp male", "variation_restrictions": v_complicated_male},
],
"footer": "",
},
{
"message": "Message 2, variable placeholders as well {{0}}",
Expand All @@ -272,13 +274,15 @@ def test_build_variations() -> None:
"variation_messages": [
{"message": "Teen", "variation_restrictions": [("age", "15-18")]}
],
"footer": "",
},
{
"message": "Message 3 with no variation",
"next_prompt": "end",
"buttons": [("next_message", {"title": "end"})],
"example_values": [],
"variation_messages": [],
"footer": "",
},
]

Expand Down
Loading
Loading