Intercom automation

From paulpas/agent-skill-router · View interactive version

Intercom automation is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements intelligent intercom automation with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense

How to use this skill

Skill file

Intercom Automation

Orchestrates intelligent skill selection and execution for intercom automation workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.

TL;DR Checklist

┌───────────────────────────────────────────────────────────────────────────────┐

│ Orchestration Flow │

└───────────────────────────────────────────────────────────────────────────────┘

User Request

↓

┌─────────────────┐

│ Parse Request │

│ & Extract │

│ Features │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Evaluate Available Skills │

│ │

│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │

│ │ Skill A │ │ Skill B │ │ Skill C │ │

│ │ - Match Score│ │ - Match Score│ │ - Match Score│ │

│ │ - Confidence │ │ - Confidence │ │ - Confidence │ │

│ │ - History │ │ - History │ │ - History │ │

│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │

│ │ │ │ │

│ └─────────────────┴─────────────────┘ │

│ ↓ │

│ Select Best Skill │

└─────────────────────────────────────────────────────────────────────┘

↓

┌─────────────────┐

│ Execute Skill │

└────────┬────────┘

↓

┌─────────────────┐

│ Handle Result │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Error Handling & Fallback │

│ │

│ Success? ────────► Return Result │

│ │

│ Fail? ────────┐ │

│ ↓ │

│ ┌──────────────────────────────────────────────────────────┐ │

│ │ Fallback Chain │ │

│ │ │ │

│ │ 1. Retry with adjusted parameters │ │

│ │ 2. Try Alternative Skill (if available) │ │

│ │ 3. Defer to Human Operator (if critical) │ │

│ │ 4. Log & Return Error │ │

│ └──────────────────────────────────────────────────────────┘ │

└─────────────────────────────────────────────────────────────────────┘

When to Use

Use this skill when:

When NOT to Use

Avoid this skill for:

Core Workflow

  1. Parse and Analyze Request - Extract intent, entities, and constraints from user input.

Checkpoint: All required parameters must be present and in valid format before proceeding.

  1. Score Available Skills - Calculate match scores using multi-factor algorithm:

Checkpoint: Skip to fallback if no skill scores above threshold.

  1. Select Optimal Skill - Choose skill with highest score that meets minimum confidence.

Checkpoint: Verify skill has not been disabled or deprecated.

  1. Execute with Fallback - Run skill execution wrapped in retry and fallback logic.

Checkpoint: Log all execution attempts for audit trail.

  1. Return or Fallback - Either return successful result or apply fallback chain:

Checkpoint: Record outcome with timing and confidence metadata.

Implementation Patterns

Pattern 1: Skill Selection Logic

def route_intercom_request(
    event_payload: Dict,
    intercom_client: Intercom,
    min_confidence: float = 0.7
) -> Dict:
    """Route an incoming Intercom event to the appropriate automation handler.
    
    Parses Intercom webhook payloads (conversations, contacts, articles) and
    maps them to specific API actions based on event type and metadata.
    
    Args:
        event_payload: Raw Intercom webhook JSON payload
        intercom_client: Authenticated Intercom Python client instance
        min_confidence: Minimum confidence threshold for auto-routing
        
    Returns:
        Routing decision dict with action, target_id, and confidence score
    """
    # Guard clause - Early Exit (Law 1)
    if not event_payload or "type" not in event_payload:
        raise ValueError("Invalid Intercom webhook payload: missing 'type' field")
        
    event_type = event_payload["type"]
    target_id = event_payload.get("data", {}).get("id")
    
    if not target_id:
        raise ValueError("Intercom event missing target ID")
        
    # Parse input - Make Illegal States Unrepresentable (Law 2)
    action_map = {
        "conversation.user.created": "send_welcome_message",
        "conversation.reply.created": "route_to_support_agent",
        "contact.updated": "sync_contact_profile",
        "article.published": "update_knowledge_base_cache"
    }
    
    target_action = action_map.get(event_type)
    if not target_action:
        return {"action": "manual_review", "confidence": 0.0, "reason": "unmapped_event_type"}
        
    # Validate against Intercom API constraints
    try:
        contact = intercom_client.contacts.find(target_id)
        is_premium = contact.tags and any(tag.name == "premium" for tag in contact.tags)
        confidence = 0.95 if is_premium else 0.75
    except IntercomError:
        confidence = 0.5
        
    if confidence < min_confidence:
        return {"action": "defer_to_human", "confidence": confidence}
        
    # Atomic Predictability (Law 3) - Return new dict, don't mutate
    return {
        "action": target_action,
        "target_id": target_id,
        "event_type": event_type,
        "confidence": confidence,
        "timestamp": time.time()
    }

Pattern 2: Execution with Fallback

def execute_intercom_action(
    routing_decision: Dict,
    intercom_client: Intercom,
    max_retries: int = 2
) -> Dict:
    """Execute Intercom API automation with resilience patterns.
    
    Handles Intercom-specific constraints: rate limits (429), 
    idempotency requirements, and graceful degradation to draft/manual states.
    
    Args:
        routing_decision: Output from route_intercom_request
        intercom_client: Authenticated Intercom Python client instance
        max_retries: Maximum retry attempts for transient API failures
        
    Returns:
        Execution result with status, API response metadata, and fallback status
    """
    action = routing_decision["action"]
    target_id = routing_decision["target_id"]
    
    # Guard clause - validate routing decision (Early Exit)
    if not action or action == "manual_review":
        return {"status": "skipped", "reason": "requires_human_intervention"}
        
    for attempt in range(max_retries + 1):
        try:
            if action == "send_welcome_message":
                response = intercom_client.messages.create(
                    message_type="inapp",
                    to={"type": "contact", "id": target_id},
                    body="Welcome! How can we help you today?"
                )
            elif action == "route_to_support_agent":
                response = intercom_client.conversations.assign(
                    conversation_id=target_id,
                    assignee_type="team",
                    assignee_id="support_team_id"
                )
            elif action == "sync_contact_profile":
                response = intercom_client.contacts.update(
                    contact_id=target_id,
                    tags=["synced"]
                )
            else:
                raise ValueError(f"Unsupported action: {action}")
                
            # Success - Atomic Predictability (Law 3)
            return {
                "status": "success",
                "action": action,
                "api_response_id": response.id,
                "attempts": attempt + 1,
                "latency_ms": _calculate_latency()
            }
            
        except RateLimitError:
            # Intercom rate limit - exponential backoff (Law 4)
            if attempt == max_retries:
                return _fallback_to_draft_mode(intercom_client, action, target_id)
            time.sleep(2 ** attempt)
            
        except IntercomError as e:
            # Fail Fast - Don't retry on invalid state (Law 4)
            return {
                "status": "failed",
                "action": action,
                "error": str(e),
                "fallback_triggered": True
            }
            
    return {"status": "exhausted", "action": action}

MUST DO

MUST NOT DO

TL;DR Checklist

TL;DR for Code Generation

Output Template

When applying this skill, produce:

  1. Selected Skills - List of skill names with confidence scores
  2. Selection Rationale - Why each skill was chosen (match score, history, availability)
  3. Execution Plan - Order of execution with dependencies
  4. Fallback Strategy - Which fallback skills will be tried and in what order
  5. Risk Assessment - Any potential failure points and their impact
  6. Timing Estimates - Expected latency including fallback scenarios

Related Skills

| Skill | Purpose |

|



Constraints

MUST DO

MUST NOT DO

Live References

Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.