Skip to content

Add front-to-admin-chat: Front context → admin chat with prefilled query#2

Open
jorrit-stack wants to merge 2 commits into
mainfrom
front-to-admin-chat-script
Open

Add front-to-admin-chat: Front context → admin chat with prefilled query#2
jorrit-stack wants to merge 2 commits into
mainfrom
front-to-admin-chat-script

Conversation

@jorrit-stack
Copy link
Copy Markdown
Collaborator

Summary

New Raycast script front-to-admin-chat/ that takes a Front conversation, pulls customer context (email, UserID via stackblitz admin, recent project slugs, orgs), and opens the bolt admin chat with a pre-filled question via the ?q= URL param.

Discovered the admin chat accepts a query-param prompt that auto-submits on load — so this script just builds a URL, no DOM injection or React-input juggling needed. Will keep working when the chat moves from hackday-admin-chat.bolt-cnr.pages.dev to bolt.new/admin since the URL pattern is the same; flip BOLT_ADMIN_CHAT_URL in .env when it lands.

Flow

  1. Resolve cnv_id — from positional arg, Front URL arg, or the active Chromium tab (AppleScript reads URL of active tab of front window).
  2. Front API — fetch conversation + earliest inbound message → email, subject, body. HTML stripped, Front template placeholders ({text}, {{customer.name}}) removed.
  3. stackblitz.com/admin lookup — same two-stage navigation pattern as customer-360/ and bolt-admin.sh: open search → find profile link → navigate tab → parse profile innerText for UserID, recent project slugs (last 10), org memberships.
  4. ProjectID regex on message body — sb1-*, github-*, webcontainer-*, bolt.new/~/*.
  5. Question template:
    Customer {email} (user id: {userId}) sent this in Front (subject: "..."):
    
    {message body, capped at 3000 chars}
    
    Projects (mentioned in message | recent from admin): slug-a, slug-b
    Orgs: org-name
    
    {trailing ask — default "What were their recent chats and any errors in the last 24h?"}
    
    Prefers projects mentioned in the body; falls back to recent ones from admin so the chat still has useful context even when the customer didn't quote a slug.
  6. Open {BOLT_ADMIN_CHAT_URL}/admin/chat?q={encoded}.

Config

Reuses cx-briefing/.env:

  • FRONT_API_KEY (required)
  • BOLT_ADMIN_CHAT_URL (optional, default https://hackday-admin-chat.bolt-cnr.pages.dev)

Flags

  • --ask "<custom question>" — override the trailing ask, keep the customer context
  • --print — dump the prepared question and URL, don't open the browser

Smoke test (real conversation)

→ Front conversation: cnv_17xisntd (from arg)
→ Looking up admin profile for joritos@gmail.com…
  ✓ UserID: 6938482 · 5 recent project(s) · orgs: kevmc
→ Opening admin chat (820 chars in URL)…

Known limitation

The two-stage browser automation has a small race window — if the search-results page hasn't finished rendering when the AppleScript reads it, the profile-link finder returns empty. Manifested once during testing; immediately succeeded on retry. A bounded retry can land in a follow-up; for now it's "rerun if it whiffs."

Test plan

  • node front-to-admin-chat/index.js <cnv_id> --print — exits cleanly, URL is < 2000 chars
  • Same with --ask "<custom>" — replaces only the trailing question
  • Run on a Front tab in the active browser without args — pulls cnv_id from URL
  • Full run (no --print) opens the admin chat with the prompt visible and the chat auto-submits
  • Run on a conversation where customer mentions a project slug — projects section says "mentioned in message"
  • Run on a conversation with no slug — projects section falls back to "recent from admin"

🤖 Generated with Claude Code

joyict and others added 2 commits May 12, 2026 17:49
…led query

New Raycast script for chaining Front context into the bolt admin chat
(currently hosted at hackday-admin-chat.bolt-cnr.pages.dev, will move to
bolt.new/admin). The admin chat accepts a `?q=` URL param that prompts
on load, so no DOM injection is needed.

Flow:
1. Resolve cnv_id from arg or active Front browser tab
2. Front API: fetch conversation + first inbound message → customer email,
   subject, body (HTML stripped, Front template placeholders like {text}
   and {{customer.name}} removed)
3. stackblitz.com/admin lookup (same two-stage AppleScript pattern as
   customer-360 + bolt-admin.sh): resolve UserID, recent project slugs,
   and org memberships from the profile page
4. Regex-extract any ProjectIDs mentioned in the message body
   (sb1-*, github-*, webcontainer-*, bolt.new/~/* URLs)
5. Build a natural-language question with all context
6. Open the admin chat with the question pre-filled via ?q=

Defaults:
- BOLT_ADMIN_CHAT_URL env var (default hackday URL) — easy switch when
  bolt.new/admin lands
- --ask "..." flag to override the trailing question, keeping the
  customer context
- --print to dump the URL without opening
- Message body capped at 3000 chars to keep URL length safe

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The stackblitz admin search-results table sometimes renders after
document.readyState becomes 'complete', so the first profile-link find
returns empty. Add up to 4 retries on the same active tab with an 800ms
gap between attempts before giving up. Avoids re-navigating — just
re-executes the find JS — so it's cheap.

In practice: failed twice in a row on the same email under stale browser
state, then succeeded on the second retry. Eliminates the "lookup failed
→ chat opens without UserID" failure mode the user hit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants