-
Notifications
You must be signed in to change notification settings - Fork 2
Add WhatsApp message title field to export and import processes #472
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,6 +290,12 @@ class WhatsappBlock(blocks.StructBlock): | |
| image = ImageChooserBlock(required=False) | ||
| document = DocumentChooserBlock(icon="document", required=False) | ||
| media = MediaBlock(icon="media", required=False) | ||
| title = blocks.CharBlock( | ||
| required=False, | ||
| help_text="Short heading shown above the message body, up to 60 characters.", | ||
| max_length=60, | ||
| default="", | ||
| ) | ||
| message = blocks.TextBlock( | ||
| help_text="each text message cannot exceed 4096 characters, messages with " | ||
| "media cannot exceed 1024 characters.", | ||
|
|
@@ -1625,6 +1631,12 @@ def __str__(self) -> str: | |
| """String repr of this snippet.""" | ||
| return self.slug | ||
|
|
||
| # Provide a minimal snippet_viewset interface for chooser widgets when the | ||
| # snippet isn't registered in the admin (feature-flagged). Wagtail's | ||
| # SnippetChooserBlock accesses `target_model.snippet_viewset.icon`. | ||
| class snippet_viewset: | ||
| icon = "order" | ||
|
|
||
|
Comment on lines
+1634
to
+1639
Member
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. Is this related to the WA title?
Contributor
Author
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. no idea why it added this |
||
| def clean(self) -> None: | ||
| result = super().clean() | ||
| errors: dict[str, list[ValidationError]] = {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ def format_whatsapp_template_message(message_index, content_page) -> dict[str, A | |
| # to retain the v2 api behaviour. We also return some fields as null or empty values, for the same reason | ||
| "type": "Whatsapp_Message", | ||
| "value": { | ||
| "title": "", | ||
|
Contributor
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. We don't need to add this to the v2 API, especially just a hardcoded empty string, since we can keep the v2 API the same and just add this to the v3 API. |
||
| "image": wa_template.image.id if wa_template.image else "", | ||
| "media": None, | ||
| "footer": "", | ||
|
|
@@ -145,6 +146,8 @@ def format_whatsapp_message(message_index, content_page, platform): | |
| text = content_page.whatsapp_body._raw_data[message_index] | ||
|
|
||
| if str(text["type"]) == "Whatsapp_Message": | ||
| # Ensure the new title field always exists in API output | ||
| text["value"].setdefault("title", "") | ||
|
Contributor
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. Same here, we don't need this in the v2 API. What we do need, however, is for this to be present in the new v3 API, in |
||
| # Flattens the variation_messages field in the whatsapp message | ||
| variation_messages = text["value"].get("variation_messages", []) | ||
| new_var_messages = [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -655,6 +655,7 @@ def test_detail_view_whatsapp_message(self, uclient: Any) -> None: | |
| assert body["total_messages"] == 1 | ||
| assert body["text"]["type"] == "Whatsapp_Message" | ||
| assert body["text"]["value"]["message"] == "*Default whatsapp Content 1* 🏥" | ||
| assert body["text"]["value"].get("title", "") == "" | ||
|
Member
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. If we expect this field to always be in the response, we should index it directly like we do with the other fields. |
||
|
|
||
| @pytest.mark.parametrize("platform", ALL_PLATFORMS) | ||
| def test_detail_view_platform_enabled_no_message(self, uclient, platform): | ||
|
|
@@ -1221,6 +1222,7 @@ def test_empty_whatsapp(self, uclient: Any) -> None: | |
| whatsapp_value = content["body"]["text"]["value"] | ||
|
|
||
| assert whatsapp_value == { | ||
| "title": "", | ||
| "image": None, | ||
| "media": None, | ||
| "footer": "", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,7 @@ def add_new_fields(entry: ExpDict) -> ExpDict: | |||||
| return { | ||||||
| "whatsapp_template_slug": "", | ||||||
| **entry, | ||||||
| "whatsapp_message_title": entry.get("whatsapp_message_title") or "", | ||||||
|
Member
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.
Suggested change
|
||||||
| "whatsapp_template_category": entry.get("whatsapp_template_category") | ||||||
| or "UTILITY", | ||||||
| "example_values": entry.get("example_values") or "[]", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ def test_build_simple_pages() -> None: | |
| ( | ||
| "Whatsapp_Message", | ||
| { | ||
| "title": "", | ||
|
Member
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. Do we need a test with a non-empty |
||
| "document": None, | ||
| "image": None, | ||
| "list_title": "", | ||
|
|
@@ -289,6 +290,7 @@ def test_build_variations() -> None: | |
| ( | ||
| "Whatsapp_Message", | ||
| { | ||
| "title": "", | ||
| "document": None, | ||
| "image": None, | ||
| "list_title": "", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -468,6 +468,7 @@ def test_happy_case_single_variation_message(self) -> None: | |
| expected_result = { | ||
| "type": "Whatsapp_Message", | ||
| "value": { | ||
| "title": "", | ||
|
Member
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. Do we need a test with a non-empty |
||
| "image": None, | ||
| "document": None, | ||
| "media": None, | ||
|
|
@@ -499,6 +500,7 @@ def test_happy_case_no_variation_messages(self) -> None: | |
| expected_result = { | ||
| "type": "Whatsapp_Message", | ||
| "value": { | ||
| "title": "", | ||
| "image": None, | ||
| "document": None, | ||
| "media": None, | ||
|
|
||
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.
Since
titleshould always exist, I think we wantvalue["title"]here.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.
Since we've done a django migration, but not a streamfield migration, that field might not exist on messages that haven't been updated. I don't think adding a field requires us to add a streamfield migration, although we might have to deal with the field being missing on old messages: https://docs.wagtail.org/en/v4.2/advanced_topics/streamfield_migrations.html#streamfield-data-migrations