V4 - saveMicroactionTool¶
A utility workflow that records micro-action outcomes and updates entrepreneur profiles in the Sifa V4 system. This workflow handles both credit-related and profit-related micro-actions, storing detailed outcome data while updating the entrepreneur's current micro-action status.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Receives Input: The workflow is triggered by another workflow with micro-action outcome data including phone number, action type, completion details, and next action assignment
- Builds SQL Query: Processes the input data and constructs appropriate SQL statements based on whether it's a credit or profit micro-action
- Executes Database Operations: Inserts the outcome record into the appropriate history table and updates the entrepreneur's current micro-action
- Returns Confirmation: Provides success status and the created history record ID
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Build SQL]
B --> C[Execute SQL]
C --> D[Return Result]
Trigger¶
Execute Workflow Trigger: This workflow is called by other workflows in the system and expects the following input parameters:
- phoneNumber: Entrepreneur's phone number
- type: Either "credit" or "profit"
- outcome_step: Description of the completed step
- outcome_data: JSON object containing detailed outcome information
- new_micro_action: Next micro-action to assign
- new_micro_action_type: Type of the next micro-action
Nodes Used¶
| Node | Type | Purpose |
|---|---|---|
| When Executed by Another Workflow | Execute Workflow Trigger | Receives input parameters from calling workflows |
| Build SQL | Code (JavaScript) | Constructs SQL statements based on micro-action type and outcome data |
| Execute SQL | Postgres | Executes the database operations to save history and update current action |
| Return Result | Code (JavaScript) | Formats the response with success status and history ID |
External Services & Credentials Required¶
- PostgreSQL Database: Requires
sifaV4Devcredential for database access- Tables used:
v4_creditmicroactionhistory,v4_profitmicroactionhistory,v4_youthEntrepreneurs
- Tables used:
Environment Variables¶
No environment variables are used in this workflow.
Data Flow¶
Input¶
1 2 3 4 5 6 7 8 | |
Output¶
1 2 3 4 5 6 7 | |
Credit Micro-Action Data Fields¶
- Debtor information (name, relationship, amount)
- Commitment details (date, partial payments, new balance)
- Outcome flags (commitment captured, refusal received, barriers)
- Follow-up information (reminders, safety concerns)
- Points awarded
Profit Micro-Action Data Fields¶
- Sale completion status
- Micro-action completion status
- Experiment assignments
- Add-on tips delivered
- Barrier information
- Points awarded
Error Handling¶
The workflow includes basic error handling: - SQL injection prevention through string escaping - JSON parsing with fallback to empty object - Numeric parsing with fallback to zero - NULL handling for optional date fields
Known Limitations¶
No specific limitations documented in the provided context.
Related Workflows¶
This workflow is designed to be called by other workflows in the Sifa V4 system that handle micro-action completion and outcome collection.
Setup Instructions¶
- Import the Workflow: Import the JSON into your n8n instance
- Configure Database Credential:
- Create a PostgreSQL credential named
sifaV4Dev - Configure connection to your Sifa V4 database
- Ensure the credential has read/write access to the required tables
- Create a PostgreSQL credential named
- Verify Database Schema: Ensure these tables exist with the expected columns:
v4_creditmicroactionhistoryv4_profitmicroactionhistoryv4_youthEntrepreneurs
- Test the Workflow: Execute with sample data to verify database operations work correctly
- Integration: Configure other workflows to call this workflow using the Execute Workflow node
The workflow is currently inactive and should be activated once properly configured and tested.