Add Follower Automation Processor
Overview
The Add Follower automation adds team members as followers to deals when they enter a specific pipeline stage. Followers receive notifications and updates about deal activity.
Source File: queue-manager/queues/deals/automations/follower.js
Triggered By: queue-manager/services/deals/automations.js
Business Impact: MEDIUM - Team collaboration
Processing Logic
sequenceDiagram
participant AUTO as Automation Service
participant QUEUE as Follower Queue
participant DEAL as Deals
participant USER as Users
AUTO->>QUEUE: Add automation job
QUEUE->>USER: Validate follower exists
QUEUE->>DEAL: Find eligible deals
loop For Each Deal
QUEUE->>DEAL: Check if owner or follower
alt Not Owner & Not Follower
QUEUE->>DEAL: Add to followers[]
QUEUE->>DEAL: Mark automation triggered
end
end
Key Features
Follower Validation
const followerID = new mongoose.Types.ObjectId(automation.data.follower);
const followerData = await User.find({
_id: followerID,
account: automation.account_id,
}).lean();
if (!followerData) {
throw new Error('Follower does not exist.');
}
Duplicate Prevention
// Check if user is already owner
if (deal.owner.toString() === followerID.toString()) {
throw new Error('Already an owner.');
}
// Check if user is already a follower
if (deal.followers.find(u => u.toString() === followerID.toString())) {
throw new Error('Already a follower.');
}
// Add follower
deal.followers.push(followerID);
deal.last_updated_by = userID;
await deal.save();
Collections Used
Input: deal-automation
Validation: user
Query: deal
Update: deal (followers array)
Use Cases
Example 1: Add Manager as Follower
// Automation
{
stage_id: "negotiation",
action: "add_follower",
data: {
follower: salesManagerID
},
delay: 0
}
// Result: Manager follows all deals in negotiation for oversight
Example 2: Add Specialist for Review
// Automation
{
stage_id: "technical_review",
action: "add_follower",
data: {
follower: technicalReviewerID
},
delay: 0
}
// Result: Technical reviewer added to track evaluation progress
Example 3: Add CS Team Post-Sale
// Automation
{
stage_id: "closed_won",
action: "add_follower",
data: {
follower: customerSuccessRepID
},
delay: 0
}
// Result: CS team member added for onboarding handoff
Follower Benefits
What Followers Receive
- Activity Notifications: Updates on deal changes
- Email Notifications: Optional digest emails
- Access: Can view deal details
- Collaboration: Can add notes, tasks
- History: See all deal activity
Why Auto-Add Followers?
- Cross-Functional Visibility: Keep relevant teams informed
- Stage-Specific Oversight: Add managers at critical stages
- Handoff Management: Prepare next team for deal transition
- Compliance: Ensure stakeholders track deals
Error Handling
Common Errors
- Follower Doesn't Exist: Invalid user ID
- Already Owner: User owns the deal
- Already Follower: User already following
- Permission Error: User lacks access
Error Response
{
deal: dealID,
follower: followerID,
message: "Already a follower.",
additional_info: {...}
}
Performance
Execution Time: 150-350ms per deal
Complexity: LOW
Lines of Code: 162