diff --git a/README.md b/README.md index ab983b7..1d0db17 100755 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ brew services list ``` #### Environment and Dependencies + Install Pipenv (if needed) ```bash @@ -161,6 +162,38 @@ You can provide attachments either inline (with the base64-encoded `content` fie } ``` +### Filter: clicktrack + +[docs.sendgrid.com](https://docs.sendgrid.com/for-developers/sending-email/smtp-filters#filter-clicktrack) + +```json +{ + "subject": "Hi Diddly Ho", + "to": [{ + "email": "homer@springfield.com", + "name": "Homer Simpson" + }], + "from": { + "email": "ned@flandersfamily.com", + "name": "Ned Flanders" + }, + "content": [ + { + "type": "text/plain", + "value": "Try search with https://google.com" + } + ], + "filters" : { + "clicktrack" : { + "settings" : { + "enable" : 0, + "enable_text" : false + } + } + } +} +``` + ## Testing Code coverage command with missing statement line numbers diff --git a/tasks.py b/tasks.py index 1d92cbb..f053a39 100644 --- a/tasks.py +++ b/tasks.py @@ -12,7 +12,7 @@ import celery from python_http_client.exceptions import HTTPError import sendgrid -from sendgrid.helpers.mail import (Mail, From, To, Cc, Bcc, Personalization, Subject, Asm, GroupId, GroupsToDisplay) +from sendgrid.helpers.mail import (Mail, From, To, Cc, Bcc, Personalization, Subject, Asm, GroupId, GroupsToDisplay, TrackingSettings, ClickTracking) from jinja2 import Environment, BaseLoader from jinja2.filters import FILTERS, pass_environment from jinja2.exceptions import TemplateNotFound @@ -155,6 +155,19 @@ def generate_message(data): message.asm = Asm(GroupId(data['asm']['group_id']), GroupsToDisplay(data['asm']['groups_to_display'])) + # https://docs.sendgrid.com/for-developers/sending-email/smtp-filters#filter-clicktrack + if 'filters' in data \ + and 'clicktrack' in data['filters'] \ + and 'settings' in data['filters']['clicktrack']: + + clicktrack_settings = data['filters']['clicktrack']['settings'] + clicktrack_enable = bool(clicktrack_settings.get('enable', False)) + clicktrack_enable_text = bool(clicktrack_settings.get('enable_text', False)) + + tracking_settings = TrackingSettings() + tracking_settings.click_tracking = ClickTracking(clicktrack_enable, clicktrack_enable_text) + message.tracking_settings = tracking_settings + func_switcher = { "content": HelperService.get_content, "attachments": HelperService.get_attachments, diff --git a/tests/mocks.py b/tests/mocks.py index a7081f7..fbfe1b1 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -41,6 +41,14 @@ "asm": { "group_id": 1, "groups_to_display": [1, 2] + }, + "filters" : { + "clicktrack" : { + "settings" : { + "enable" : 0, + "enable_text" : False + } + } } }