-
Notifications
You must be signed in to change notification settings - Fork 0
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 postprocessing for email actions and include page_name property #3
base: master
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ class ContactsSink(ActionKitSink): | |
"""ActionKit target sink class.""" | ||
|
||
name = "Contacts" | ||
endpoint = "user" | ||
endpoint = "rest/v1/" | ||
entity = "user" | ||
|
||
def add_phone_numbers(self, user_id: str, record: dict): | ||
|
@@ -49,6 +49,9 @@ def upsert_record(self, record: dict, context: dict): | |
|
||
if existing_users: | ||
user_id = existing_users[0].get("id") | ||
# TODO:I got {"errors": {"zip": ["Data too long! Please use a smaller value, see the schema for the maximum allowed input"]}}} | ||
# I'm not sure if this is the correct way to handle this, but it's a temporary fix | ||
record.pop("zip", None) | ||
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. Doesn't this just mean you were providing an invalid 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. It was a valid one and in the schema there wasn't any valuable information on how to handle it... If I let it updating the zip it would break things. |
||
response = self.request_api( | ||
"PATCH", | ||
request_data=record, | ||
|
@@ -59,7 +62,8 @@ def upsert_record(self, record: dict, context: dict): | |
if response.ok: | ||
self.add_phone_numbers(user_id, record) | ||
state_dict["success"] = True | ||
state_dict["is_updated"] = True | ||
state_dict["is_updated"] = True | ||
self.postprocess_record(record, context) | ||
return user_id, response.ok, state_dict | ||
|
||
response = self.request_api( | ||
|
@@ -74,6 +78,7 @@ def upsert_record(self, record: dict, context: dict): | |
id = response.headers['Location'].replace(f"https://{self.config.get('hostname')}.actionkit.com/rest/v1/user/", "")[:-1] | ||
self.logger.info(id) | ||
self.add_phone_numbers(id, record) | ||
self.postprocess_record(record, context) | ||
return id, response.ok, state_dict | ||
|
||
return None, False, state_dict | ||
|
@@ -99,3 +104,28 @@ def preprocess_record(self, record: dict, context: dict) -> dict: | |
break | ||
|
||
return payload | ||
|
||
def postprocess_record(self, record: dict, context: dict) -> dict: | ||
if not self.config.get("page_name"): | ||
return record | ||
email = record.get("email") | ||
if not email: | ||
return record | ||
try: | ||
response = self.request_api( | ||
"POST", | ||
endpoint="action", | ||
request_data={ | ||
"page": self.config.get("page_name"), | ||
"email": email | ||
}, | ||
headers=self.prepare_request_headers() | ||
) | ||
if response.ok: | ||
self.logger.info(f"Action created for {response.json().get('user')} on {self.config.get('page_name')}") | ||
return record | ||
else: | ||
raise Exception(f"Failed to create action for {email} on {self.config.get('page_name')}: {response.text}") | ||
except Exception as e: | ||
self.logger.error(f"Failed to create action for {email} on {self.config.get('page_name')}: {e}") | ||
return record |
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.
Was this intentional?
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.
Yes! Without it I would not be able to add users to the action page