LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
feat: Add HubSpot integration plugin hooks for user journey tracking (#1806)
Hari John Kuriakose0f37b406bb26
diff --git a/backend/account_v2/authentication_service.py b/backend/account_v2/authentication_service.pyindex eaef0dde7..591742821 100644--- a/backend/account_v2/authentication_service.py+++ b/backend/account_v2/authentication_service.py@@ -266,9 +266,6 @@ class AuthenticationService:def frictionless_onboarding(self, organization: Organization, user: User) -> None:raise MethodNotImplemented()- def hubspot_signup_api(self, request: Request) -> None:- raise MethodNotImplemented()-def delete_invitation(self, organization_id: str, invitation_id: str) -> bool:raise MethodNotImplemented()diff --git a/backend/api_v2/api_deployment_views.py b/backend/api_v2/api_deployment_views.pyindex 7462864f0..47d0aac34 100644--- a/backend/api_v2/api_deployment_views.py+++ b/backend/api_v2/api_deployment_views.py@@ -16,6 +16,7 @@ from rest_framework.response import Responsefrom rest_framework.serializers import Serializerfrom tool_instance_v2.models import ToolInstancefrom utils.enums import CeleryTaskState+from utils.hubspot_notify import notify_hubspot_eventfrom utils.pagination import CustomPaginationfrom workflow_manager.workflow_v2.dto import ExecutionResponsefrom workflow_manager.workflow_v2.models.execution import WorkflowExecution@@ -293,6 +294,9 @@ class APIDeploymentViewSet(viewsets.ModelViewSet):def create(self, request: Request, *args: tuple[Any], **kwargs: dict[str, Any]) -> Response:+ # Check deployment count before create for HubSpot notification+ deployment_count_before = APIDeployment.objects.count()+serializer: Serializer = self.get_serializer(data=request.data)serializer.is_valid(raise_exception=True)self.perform_create(serializer)@@ -301,6 +305,14 @@ class APIDeploymentViewSet(viewsets.ModelViewSet):{"api_key": api_key.api_key, **serializer.data})+ # Notify HubSpot about first API deployment+ notify_hubspot_event(+ user=request.user,+ event_name="API_DEPLOY",+ is_first_for_org=deployment_count_before == 0,+ action_label="API deployment",+ )+headers = self.get_success_headers(serializer.data)return Response(response_serializer.data,diff --git a/backend/prompt_studio/prompt_studio_core_v2/views.py b/backend/prompt_studio/prompt_studio_core_v2/views.pyindex 6f447b51e..f9f2e7ec7 100644--- a/backend/prompt_studio/prompt_studio_core_v2/views.py+++ b/backend/prompt_studio/prompt_studio_core_v2/views.py@@ -22,6 +22,7 @@ from rest_framework.response import Responsefrom rest_framework.versioning import URLPathVersioningfrom tool_instance_v2.models import ToolInstancefrom utils.file_storage.helpers.prompt_studio_file_helper import PromptStudioFileHelper+from utils.hubspot_notify import notify_hubspot_eventfrom utils.user_context import UserContextfrom utils.user_session import UserSessionUtilsfrom workflow_manager.endpoint_v2.models import WorkflowEndpoint@@ -57,6 +58,8 @@ from prompt_studio.prompt_studio_document_manager_v2.prompt_studio_document_helpPromptStudioDocumentHelper,)from prompt_studio.prompt_studio_index_manager_v2.models import IndexManager+from prompt_studio.prompt_studio_output_manager_v2.models import PromptStudioOutputManager+from prompt_studio.prompt_studio_registry_v2.models import PromptStudioRegistryfrom prompt_studio.prompt_studio_registry_v2.prompt_studio_registry_helper import (PromptStudioRegistryHelper,)@@ -119,6 +122,16 @@ class PromptStudioCoreView(viewsets.ModelViewSet):PromptStudioHelper.create_default_profile_manager(request.user, serializer.data["tool_id"])++ # Notify HubSpot if this is the first Prompt Studio project for the org+ # (count == 1 means the one we just created is the first)+ notify_hubspot_event(+ user=request.user,+ event_name="PROMPT_STUDIO_PROJECT_CREATE",+ is_first_for_org=CustomTool.objects.count() == 1,+ action_label="project creation",+ )+return Response(serializer.data, status=status.HTTP_201_CREATED)def perform_destroy(self, instance: CustomTool) -> None:@@ -409,6 +422,14 @@ class PromptStudioCoreView(viewsets.ModelViewSet):if not run_id:# Generate a run_idrun_id = CommonUtils.generate_uuid()++ # Check output count before prompt run for HubSpot notification+ # Filter through tool FK to scope by organization (PromptStudioOutputManager+ # lacks DefaultOrganizationManagerMixin)+ output_count_before = PromptStudioOutputManager.objects.filter(+ tool_id__in=CustomTool.objects.values_list("tool_id", flat=True)+ ).count()+response: dict[str, Any] = PromptStudioHelper.prompt_responder(id=id,tool_id=tool_id,@@ -418,6 +439,15 @@ class PromptStudioCoreView(viewsets.ModelViewSet):run_id=run_id,profile_manager_id=profile_manager,)++ # Notify HubSpot about first prompt run+ notify_hubspot_event(+ user=request.user,+ event_name="PROMPT_RUN",+ is_first_for_org=output_count_before == 0,+ action_label="prompt run",+ )+return Response(response, status=status.HTTP_200_OK)@action(detail=True, methods=["post"])@@ -574,6 +604,13 @@ class PromptStudioCoreView(viewsets.ModelViewSet):uploaded_files: Any = serializer.validated_data.get("file")file_converter_plugin = get_plugin("file_converter")+ # Check document count before upload for HubSpot notification+ # Filter through tool FK to scope by organization (DocumentManager+ # lacks DefaultOrganizationManagerMixin)+ doc_count_before = DocumentManager.objects.filter(+ tool__in=CustomTool.objects.all()+ ).count()+documents = []for uploaded_file in uploaded_files:# Store file@@ -624,6 +661,15 @@ class PromptStudioCoreView(viewsets.ModelViewSet):"tool": document.tool.tool_id,}documents.append(doc)++ # Notify HubSpot about first document upload+ notify_hubspot_event(+ user=request.user,+ event_name="DOCUMENT_UPLOAD",+ is_first_for_org=doc_count_before == 0,+ action_label="document upload",+ )+return Response({"data": documents})@action(detail=True, methods=["delete"])@@ -675,6 +721,9 @@ class PromptStudioCoreView(viewsets.ModelViewSet):user_ids = set(serializer.validated_data.get("user_id"))force_export = serializer.validated_data.get("force_export")+ # Check registry count before export for HubSpot notification+ registry_count_before = PromptStudioRegistry.objects.count()+PromptStudioRegistryHelper.update_or_create_psr_tool(custom_tool=custom_tool,shared_with_org=is_shared_with_org,@@ -682,6 +731,14 @@ class PromptStudioCoreView(viewsets.ModelViewSet):force_export=force_export,)+ # Notify HubSpot about first tool export+ notify_hubspot_event(+ user=request.user,+ event_name="TOOL_EXPORT",+ is_first_for_org=registry_count_before == 0,+ action_label="tool export",+ )+return Response({"message": "Custom tool exported sucessfully."},status=status.HTTP_200_OK,diff --git a/backend/utils/hubspot_notify.py b/backend/utils/hubspot_notify.pynew file mode 100644index 000000000..e25ee29bc--- /dev/null+++ b/backend/utils/hubspot_notify.py@@ -0,0 +1,37 @@+import logging++from plugins import get_plugin++logger = logging.getLogger(__name__)+++def notify_hubspot_event(+ user,+ event_name: str,+ is_first_for_org: bool,+ action_label: str,+) -> None:+ """Send a HubSpot event notification if the plugin is available.++ Args:+ user: The user performing the action.+ event_name: The HubSpotEvent attribute name (e.g. "PROMPT_RUN").+ is_first_for_org: Whether this is the first such action for the org.+ action_label: Human-readable label for logging (e.g. "prompt run").+ """+ hubspot_plugin = get_plugin("hubspot")+ if not hubspot_plugin:+ return++ try:+ from plugins.integrations.hubspot import HubSpotEvent++ event = getattr(HubSpotEvent, event_name)+ service = hubspot_plugin["service_class"]()+ service.update_contact(+ user=user,+ events=[event],+ is_first_for_org=is_first_for_org,+ )+ except Exception as e:+ logger.warning(f"Failed to notify HubSpot for {action_label}: {e}")