brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
intercom-automationImplements intelligent intercom automation with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
Independent GitHub snapshot · Automated classification · Original documentation governs
name: intercom-automation compatibility: opencode completeness: 95 content-types:
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.
┌───────────────────────────────────────────────────────────────────────────────┐ │ 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 │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
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.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
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()
}
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}
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose | |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.