Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
feat: Docuseal member agreement webhook#69
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8939631c72215616d9b2a99660250dc58c7a41457e269b277File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """Docuseal member agreement processing workflow.""" | ||
| import logging | ||
| from typing import Any | ||
| from five08.clients.espo import EspoAPI, EspoAPIError | ||
| from five08.worker.config import settings | ||
| from five08.worker.masking import mask_email | ||
| logger = logging.getLogger(__name__) | ||
| class DocusealAgreementProcessor: | ||
| """Look up a CRM contact by email and mark their member agreement as signed.""" | ||
| def __init__(self) -> None: | ||
| api_url = settings.espo_base_url.rstrip("/") + "/api/v1" | ||
| self.api = EspoAPI(api_url, settings.espo_api_key) | ||
| def process_agreement( | ||
| self, | ||
| email: str, | ||
| completed_at: str, | ||
| submission_id: int, | ||
| ) -> dict[str, Any]: | ||
| """Search for the signer by email and update cMemberAgreementSignedAt.""" | ||
| masked_email = mask_email(email) | ||
| try: | ||
| result = self.api.request( | ||
| "GET", | ||
| "Contact", | ||
| { | ||
| "where": [ | ||
| { | ||
| "type": "equals", | ||
| "attribute": "emailAddress", | ||
| "value": email, | ||
| } | ||
| ], | ||
| "maxSize": 1, | ||
| "select": "id,name,emailAddress", | ||
| }, | ||
| ) | ||
| except EspoAPIError as exc: | ||
| logger.error("CRM search failed for masked_email=%s: %s", masked_email, exc) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "error": f"CRM search failed: {exc}", | ||
| } | ||
| contacts = result.get("list", []) | ||
| if not contacts: | ||
| logger.warning( | ||
| "No CRM contact found for masked_email=%s submission_id=%s", | ||
| masked_email, | ||
| submission_id, | ||
| ) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "error": "contact_not_found", | ||
| } | ||
| contact = contacts[0] | ||
| contact_id = contact["id"] | ||
| try: | ||
| self.api.request( | ||
| "PUT", | ||
| f"Contact/{contact_id}", | ||
| { | ||
| "cMemberAgreementSignedAt": completed_at, | ||
| }, | ||
| ) | ||
| except EspoAPIError as exc: | ||
| logger.error("CRM update failed for contact_id=%s: %s", contact_id, exc) | ||
| return { | ||
| "success": False, | ||
| "masked_email": masked_email, | ||
| "submission_id": submission_id, | ||
| "contact_id": contact_id, | ||
| "error": f"CRM update failed: {exc}", | ||
| } | ||
| logger.info( | ||
| "Marked member agreement signed contact_id=%s masked_email=%s", | ||
| contact_id, | ||
| masked_email, | ||
| ) | ||
| return { | ||
| "success": True, | ||
| "masked_email": masked_email, | ||
| "contact_id": contact_id, | ||
| "submission_id": submission_id, | ||
| "completed_at": completed_at, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,9 +4,11 @@ | ||
| from datetime import datetime, timezone | ||
| from typing import Any | ||
| from five08.worker.crm.docuseal_processor import DocusealAgreementProcessor | ||
| from five08.worker.crm.people_sync import PeopleSyncProcessor | ||
| from five08.worker.crm.processor import ContactSkillsProcessor | ||
| from five08.worker.crm.resume_profile_processor import ResumeProfileProcessor | ||
| from five08.worker.masking import mask_email | ||
| logger = logging.getLogger(__name__) | ||
| @@ -68,6 +70,21 @@ def apply_resume_profile_job( | ||
| return result.model_dump() | ||
| def process_docuseal_agreement_job( | ||
| email: str, | ||
| completed_at: str, | ||
| submission_id: int, | ||
| ) -> dict[str, Any]: | ||
| """Mark a CRM contact as having signed the member agreement via Docuseal.""" | ||
| logger.info( | ||
| "Processing Docuseal agreement job masked_email=%s submission_id=%s", | ||
| mask_email(email), | ||
| submission_id, | ||
| ) | ||
| processor = DocusealAgreementProcessor() | ||
| return processor.process_agreement(email, completed_at, submission_id) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def sync_people_from_crm_job() -> dict[str, Any]: | ||
| """Sync a full contacts page-set from CRM into the local people cache.""" | ||
| logger.info("Processing CRM people full-sync job") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """PII masking helpers used across worker modules.""" | ||
| def mask_email(email: str) -> str: | ||
| """Return a deterministic redacted email representation for logs and responses.""" | ||
| local, at, domain = email.partition("@") | ||
| if not at: | ||
| return "***" | ||
| masked_local = (local[:1] if local else "*") + "***" | ||
| if not domain: | ||
| return f"{masked_local}@****..." | ||
| return f"{masked_local}@{domain[:1]}****..." | ||
Comment on lines
+10
to
+15
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. Use hash-based masking instead of partial-character exposure. This currently reveals email initials ( 🔧 Proposed fix+import hashlib+
def mask_email(email: str) -> str:
- """Return a deterministic redacted email representation for logs and responses."""- local, at, domain = email.partition("@")- if not at:- return "***"-- masked_local = (local[:1] if local else "*") + "***"-- if not domain:- return f"{masked_local}@****..."-- return f"{masked_local}@{domain[:1]}****..."+ """Return deterministic non-reversible email token for logs/responses."""+ normalized = email.strip().lower()+ if "@" not in normalized:+ return "email#invalid"+ digest = hashlib.sha256(normalized.encode("utf-8")).hexdigest()[:12]+ return f"email#{digest}"🤖 Prompt for AI Agents | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.