Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: include a message variation id with campaign_id for enterprise e…
Browse files Browse the repository at this point in the history
…mails.

Braze requires that a message variant be present when campaign_id is specified
in a message sending request.
ENT-5285
  • Loading branch information
iloveagent57 committed Jan 5, 2022
1 parent c0eef8e commit 20d706b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ecommerce_worker/configuration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
'ENTERPRISE_CODE_UPDATE_CAMPAIGN_ID': '',
'ENTERPRISE_CODE_USAGE_CAMPAIGN_ID': '',
'ENTERPRISE_CODE_NUDGE_CAMPAIGN_ID': '',
'ENTERPRISE_CODE_ASSIGNMENT_MESSAGE_VARIATION_ID': '',
'ENTERPRISE_CODE_UPDATE_MESSAGE_VARIATION_ID': '',
'ENTERPRISE_CODE_USAGE_MESSAGE_VARIATION_ID': '',
'ENTERPRISE_CODE_NUDGE_MESSAGE_VARIATION_ID': '',
# Retry settings for Braze celery tasks
'BRAZE_RETRY_SECONDS': 3600,
'BRAZE_RETRY_ATTEMPTS': 6,
Expand Down
5 changes: 5 additions & 0 deletions ecommerce_worker/email/v1/braze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def send_message( # pylint: disable=dangerous-default-value
reply_to='',
attachments=[],
campaign_id='',
message_variation_id=None,
):
"""
Sends the message via Braze Rest API /messages/send
Expand All @@ -308,6 +309,7 @@ def send_message( # pylint: disable=dangerous-default-value
reply_to (str): Enterprise Customer reply to address for email reply
attachments (list): list of dicts with filename and url keys
campaign_id (str): The id of the campaign this email is associated with
message_variation_id (str): The id of the message variant associated with the given campaign_id
Request message format:
Content-Type: application/json
Expand All @@ -323,6 +325,7 @@ def send_message( # pylint: disable=dangerous-default-value
"from": "edX <[email protected]>",
"reply_to": "[email protected]",
"body": "<html>Test</html>",
"message_variation_id": "email-1234",
"attachments": [
{ "file_name": "filename1", "url": "url1" },
{ "file_name": "filename2", "url": "url2" }
Expand Down Expand Up @@ -366,6 +369,8 @@ def send_message( # pylint: disable=dangerous-default-value
email['attachments'] = attachments
if reply_to:
email['reply_to'] = reply_to
if message_variation_id:
email['message_variation_id'] = message_variation_id
message = {
'user_aliases': user_aliases,
'external_user_ids': external_ids,
Expand Down
4 changes: 4 additions & 0 deletions ecommerce_worker/email/v1/braze/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def send_offer_assignment_email_via_braze(self, user_email, offer_assignment_id,
reply_to=reply_to,
attachments=attachments,
campaign_id=config.get('ENTERPRISE_CODE_ASSIGNMENT_CAMPAIGN_ID'),
message_variation_id=config.get('ENTERPRISE_CODE_ASSIGNMENT_MESSAGE_VARIATION_ID'),
)
if response and response['success']:
dispatch_id = response['dispatch_id']
Expand Down Expand Up @@ -92,6 +93,7 @@ def send_offer_update_email_via_braze(self, user_email, subject, email_body, sen
reply_to=reply_to,
attachments=attachments,
campaign_id=config.get('ENTERPRISE_CODE_UPDATE_CAMPAIGN_ID'),
message_variation_id=config.get('ENTERPRISE_CODE_UPDATE_MESSAGE_VARIATION_ID'),
)
except (BrazeRateLimitError, BrazeInternalServerError) as exc:
raise self.retry(countdown=config.get('BRAZE_RETRY_SECONDS'),
Expand Down Expand Up @@ -128,6 +130,7 @@ def send_offer_usage_email_via_braze(self, emails, subject, email_body, reply_to
reply_to=reply_to,
attachments=attachments,
campaign_id=config.get('ENTERPRISE_CODE_USAGE_CAMPAIGN_ID'),
message_variation_id=config.get('ENTERPRISE_CODE_USAGE_MESSAGE_VARIATION_ID'),
)
except (BrazeRateLimitError, BrazeInternalServerError) as exc:
raise self.retry(countdown=config.get('BRAZE_RETRY_SECONDS'),
Expand Down Expand Up @@ -167,6 +170,7 @@ def send_code_assignment_nudge_email_via_braze(self, email, subject, email_body,
reply_to=reply_to,
attachments=attachments,
campaign_id=config.get('ENTERPRISE_CODE_NUDGE_CAMPAIGN_ID'),
message_variation_id=config.get('ENTERPRISE_CODE_NUDGE_MESSAGE_VARIATION_ID'),
)
except (BrazeRateLimitError, BrazeInternalServerError) as exc:
raise self.retry(countdown=config.get('BRAZE_RETRY_SECONDS'),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def is_requirement(line):

setup(
name='edx-ecommerce-worker',
version='3.1.0',
version='3.1.1',
description='Celery tasks supporting the operations of edX\'s ecommerce service',
long_description=long_description,
classifiers=[
Expand Down

0 comments on commit 20d706b

Please sign in to comment.