# Social Channels — Inbound Lead Capture from DMs / Comments / Mentions

_Lead Generation_

Every inbound DM, comment, mention, or story reply on Facebook / Instagram / WhatsApp / X / LinkedIn / YouTube becomes part of the unified inbox AND auto-creates a tracked SocialProfile (per platform per person) with engagement counts, referral attribution, and platform-specific identity fields. The Social Channels card on the Website Capture hub shows which platforms are connected; AI scoring + intent signals consume the SocialProfile data downstream.

## Steps
1. Connect each platform under Settings > Integrations > Social Integrations (OAuth flows for FB/IG/WA/X/LI; YouTube uses a polling cron with an API key).
2. Once connected, every inbound message hitting that platform's webhook lands in the unified inbox AND upserts a SocialProfile row keyed by (orgId, platform, platformUserId). On the FIRST inbound message a Contact is auto-created (toggleable — see below) and linked to the profile.
3. View the platform mix on the Website Capture hub > Social Channels card: green dot for each connected platform with account name + last-message timestamp. The card is intentionally connection-focused — runtime stats (profiles tracked, leads-this-month) appear in the footer hint, not the headline. Replies and auto-routing live in Conversations.
4. Open any contact at /dashboard/contacts/{id} — the new "Social Profiles" section in the right rail shows every linked SocialProfile with platform emoji, displayName, headline, follower count, business badge, follower badge, msg count, "Open →" link to the public profile.

## Tips
- Auto-create Contact toggle: org.socialAutoCreateContacts (default ON). When ON, the first DM from a never-seen person creates a Contact with source=<platform>, tags=[<platform>], and links the SocialProfile. When OFF, the SocialProfile is still created but no Contact (you'll see the profile in Social Profile lookups but no contact row).
- Per-message socialContext: the Message.socialContext JSONB stores structured per-message data — referralSource (ad/story_reply/post_comment/direct), adId, messageType, isFollower, follower count, etc. AI features (predictive scoring, intent signals, contact summary) consume this directly.
- Bio + parsed fields: when the platform exposes a bio (X, LinkedIn) we kick a fire-and-forget Haiku parse to extract jobTitle / company / location. Failure mode: empty fields, never hallucination.
- enrichContactFromSocial fills empty Contact fields ONLY (firstName, company, jobTitle, city, platform-specific URL fields). Existing data is never overwritten.
- Five social-specific intent signals fire automatically: ad_referral (strength 9), story_reply (7), social_multi_platform (6), social_business_account (4), social_follower_dm (5). They show up on /dashboard/leadgen/intent alongside other intent signals.
- Predictive scoring picks up 8 social features (hasSocialProfile, socialPlatformCount, cameFromAd, cameFromStoryReply, isFollower, isBusinessAccount, totalSocialMessages, hasLinkedIn) so the model can learn how social-acquired leads convert vs others.
- Contact AI summary now mentions linked social profiles when present — the prompt gets a "Social profiles" block listing platform/headline/followers/follows-us/first-referral/msg-count.
- Limitations: bio-link click tracking is not yet wired (Phase 5); cross-platform sentiment/conversation intelligence enrichment is a follow-up; some platform-specific signals (Instagram isFollower, YouTube isSubscriber) require additional API calls we don't make in v1.
- Facebook and Instagram post comments: comments on your recent posts published from CRMown are checked every 30 minutes and land in Conversations (and in the post's Comments drawer on the Social board). CRMown can also take them the moment they are posted, through the Page's comment notifications from Facebook/Instagram — when those are switched on for your connection, comments arrive within seconds, including comments on posts you made directly on Facebook or Instagram. Your Page's own comments and replies are never imported as inbound messages. A comment deleted or hidden on Facebook disappears from the post's Comments drawer (it stays in the Conversations thread), and an edited comment updates in place. Likes are not imported as messages; the like/comment counts on a post come from the 30-minute check.
- Each connected platform pill on the Social Channels card is a deep-link to its filtered inbox view (e.g. clicking the Instagram tile opens /dashboard/conversations?channel=instagram). The card itself surfaces a "View messages →" link to the unified inbox.

## Example
A real-estate agent has FB Messenger + Instagram + WhatsApp connected. A buyer sends a DM via Instagram in response to a story about a new listing → SocialProfile row created with firstReferralSource=story_reply, Contact auto-created with source=instagram, tag instagram, and the story_reply intent signal fires (strength 7). Predictive scoring boosts the lead because cameFromStoryReply=true. The contact detail page now shows the Social Profiles section with the IG profile + msg count + "follows us" badge. Two days later they DM on WhatsApp too — same SocialProfile pattern, NEW row, social_multi_platform intent signal fires (2 platforms), AND the same Contact is matched on phone if WhatsApp number resolves. The agent sees an enriched contact with cross-platform context that wouldn't exist without Phase 1.

## Troubleshooting
- **Inbound DM created a duplicate Contact instead of linking to existing one** — Existing matching by name is approximate (fuzzy on displayName); platforms don't always expose the email or phone, so we can't merge by those. Fix: Manually merge contacts via /dashboard/contacts > select both > Merge. Future SocialProfiles will link to the surviving contact.
- **A Contact was auto-created but I don't want that** — org.socialAutoCreateContacts is ON (default). Fix: Toggle it OFF in Settings > Communications. From that point forward SocialProfile rows still capture identity but no Contact is created until you manually promote.
- **Social Channels card shows "0 of 6 connected" even though I see active DMs** — The SocialIntegration row may have isActive=false (token expired, OAuth revoked). Fix: Settings > Integrations > Social Integrations — reconnect any platform showing an error badge.
- **Social Profile section empty on a contact I know has DMs** — The Contact might have been created BEFORE Phase 1 shipped (2026-04-30) so no SocialProfile was upserted at the time, OR the contact is linked under a different name and the inbound DM went to a different Contact. Fix: For pre-Phase-1 data: future inbound messages from the same platformUserId will auto-link going forward. For mismatched contacts: merge them in /dashboard/contacts.

## Plans
Inbound capture is Core — no suite gate. Each connected social platform is one OAuth integration. Outbound publishing requires the Marketing suite (separate feature).
