How to clone a $10B SMS AI assistant with Claude Code and modern AI tooling
Most people building AI assistants today ship yet another web app. The more interesting products, though, are starting to look like this: you text a phone number on Telegram, WhatsApp, or iMessage, and a powerful AI agent quietly handles everything in the background—finding restaurants, editing PDFs, even using a virtual computer for you.
This guide walks through how to build that kind of production-grade, messaging-first AI assistant from scratch. You’ll see how to wire up messaging channels, durable agents, web search, computer use, authentication, billing, and observability—using Claude Code as your main coding assistant.
What you’re building: a messaging-first AI assistant
The end result is a startup-ready personal assistant that users can text from multiple channels:
• Telegram bot as the primary development and testing surface
• iMessage support via Link as an aggregator
• Optional WhatsApp or other channels later
From the user’s perspective, it’s simple: they text a bot to ask for things like “Find me a 7:30pm dinner in East Village with 4.7+ rating” or “Sign this rental agreement and send it back.” Behind the scenes, a fairly sophisticated architecture kicks in to handle auth, billing, long-running tasks, web search, and more.
High-level architecture: channel gate → trigger agent → tools
The system is split into two main environments:
1. HTTP front door (Hono on Railway)
• Exposes webhooks for Telegram and Link (iMessage)
• Performs authentication and billing checks
• Acts as a channel gate: only forwards valid, paying users to the agent
• Keeps logic light to avoid long-running work in HTTP requests
2. Durable agent environment (Trigger.dev)
• Runs the actual AI agent logic using AI SDK
• Handles long-running tasks without HTTP timeouts
• Provides memory via transcripts
• Calls tools: web search (Firecrawl), computer use (Daytona), messaging send APIs, etc.
The basic flow:
1) User sends a message on Telegram or iMessage.
2) Messaging platform hits your Hono webhook.
3) Hono checks: is this user authenticated and on a paid plan?
4) If not, it initiates login or upgrade flows and replies with a link.
5) If yes, Hono forwards the request to a Trigger.dev inbound webhook.
6) Trigger.dev runs a chat agent that calls tools, talks to the LLM, and sends the reply back via the right channel.
Scaffolding the backend with Hono and Railway
The backend starts with Hono, a lightweight Node.js framework:
• Scaffold a Node.js Hono project (e.g. via the official CLI).
• Run npm run dev and confirm you see a simple “hello hono” response at localhost:3000.
From there, you:
• Initialize a Git repo and push to GitHub.
• Connect the repo to Railway so every push triggers a new deployment.
• Use the Railway CLI and its Claude skill to auto-create a project and deployment.
• Confirm your production URL returns the updated response (e.g. “hello railway”).
This gives you a fast CI/CD pipeline for your Hono app.
Teaching Claude Code to understand your stack
To get reliable agentic coding, you don’t want to rely solely on an LLM’s training data. You explicitly teach it your stack:
Hono skills
• Install npx skills for Hono.
• Choose project scope so skills live in the repo (easier for collaborators).
• Add agents.md with instructions on using the Hono CLI for route validation.
• Optionally add claude.md that just points to agents.md so Claude always reads it.
This lets your coding agent:
• Add and modify Hono routes.
• Use Hono CLI to test routes without starting the dev server.
• Avoid hallucinating APIs or breaking structure repeatedly.
You also add a .dockerignore with agents and claude so infra tools don’t try to bundle skill templates as part of your app.
Hardening your code with AI security reviews
Modern attackers are using LLMs to mass-scan for vulnerabilities. To avoid shipping obvious issues, you plug in Grappile (an AI code reviewer):
• Connect your GitHub repo to Grappile.
• Configure what you want in reviews (security focus, frequency, etc.).
• Let it auto-review every pull request and highlight vulnerabilities with explanations and “fix with AI” shortcuts.
This becomes a continuous AI-assisted security layer as your project grows.
Upgrading web search with Firecrawl
Default “web search” tools in coding agents are often slow, expensive, and noisy. To fix that, you integrate Firecrawl:
• Install Firecrawl skills so your coding agent can use its Alexandria features during development.
• Later, install Firecrawl SDK as a runtime dependency for your production agent.
With Firecrawl, the assistant can:
• Answer complex queries like “Find me a table for 2 at 7:30pm in East Village, rating 4.7+” with structured tables of restaurants, ratings, hours, and booking links.
• Perform focused, structured scraping instead of returning entire docs.
• Be faster and cheaper than generic web tools.
Firecrawl is open source and free for many use cases, with extra credits available if you need more intensive usage.
Adding the first channel: Telegram bot
Telegram is the ideal development channel because its Bot API is open and easy to work with. The flow:
1) Use BotFather in Telegram to create a bot and get a bot token.
2) Store TELEGRAM_BOT_TOKEN and a TELEGRAM_WEBHOOK_SECRET in your env files.
3) Implement a Hono POST route for the Telegram webhook that validates the secret header.
4) Start with an echo bot: read the incoming message and send it back via Telegram Bot API.
You then:
• Sync env vars to Railway via the Claude + Railway skill.
• Register the webhook with Telegram, pointing at your production URL.
• Confirm that sending “hello world” to the bot gives you “hello world” back.
Giving the bot a brain with AI SDK and an AI gateway
Next, you swap the echo logic for an AI-generated response using AI SDK:
• Install AI SDK skills so Claude knows how to use it.
• Choose a provider: directly (OpenAI, Anthropic, Gemini, Grok, etc.) or via an AI gateway like Neon’s AI Gateway.
• Add the relevant API keys to your environment (e.g. NEON_AI_GATEWAY_TOKEN and base URL).
Then you:
• Update the Telegram webhook handler to call AI SDK with a cheap chat model (e.g. GPT 5.4 Nano via Neon).
• Reply with the model’s output instead of echoing the text.
At this stage, your Telegram bot is a basic chat assistant—but it still has major problems: no memory, no durability, and no separation between HTTP and agent runtime.
Why you need a durable agent runtime (Trigger.dev)
Running the agent directly inside Hono’s HTTP request has several issues:
• Any crash or redeploy kills the in-flight AI response.
• No conversation memory: each message is treated as a brand-new chat.
• No visibility into what ran, where it failed, or how long it took.
• Long-running tasks (like complex web search or computer use) hit HTTP timeouts.
• Provider errors (rate limits, credit exhaustion) break the flow without automatic retries.
To fix this, you move the agent to Trigger.dev, a durable, stateless task runner built for agents:
• Trigger.dev runs tasks on Linux workers independent of your Hono server.
• It provides an inbound webhook, chat agents, transcripts (memory), and automatic retries.
• It’s free for development and much cheaper than holding long-lived HTTP requests open.
Wiring Hono to Trigger.dev with a test route
You start by:
• Initializing Trigger.dev in your project with its CLI and API key.
• Creating a simple helloWorld task in a trigger/ folder.
• Running npx trigger.dev dev locally to register and test the task.
Then you add a Hono GET route like /test-ai that:
• Accepts a prompt query parameter.
• Calls a Trigger task (e.g. generateText) that uses AI SDK to generate a response.
• Returns the result once the task finishes.
This lets you verify a crucial property: if you kill your Hono dev server while the Trigger task is running, the task still completes in Trigger.dev. That’s the durability you want for your agent.
Promoting Trigger.dev to production
To run Trigger.dev in production alongside Railway:
• Add all relevant environment variables (DB URLs, AI keys, Telegram tokens, etc.) to Trigger.dev’s development and production environments.
• Create a separate TRIGGER_SECRET_KEY for production and store it in Railway.
• Deploy your Trigger project (via GitHub integration or npx trigger.dev latest deploy).
Now when you hit the production /test-ai route, it:
• Invokes the Trigger task in production.
• Continues running even if your Railway instance crashes or is redeployed.
Migrating the Telegram bot to a Trigger chat agent
Once Trigger.dev is running, you move the Telegram bot logic into a Trigger inbound webhook + chat agent:
• Replace the old Hono-based AI logic with a Trigger inbound webhook handler.
• The webhook uses chat agent with AI SDK and transcripts, so the assistant has memory.
• The agent sends replies back via Telegram tools.
After deploying and updating the Telegram webhook to the Trigger URL, you get:
• Durable runs with retry and visibility in the Trigger dashboard.
• Conversation memory (e.g. “What did I just ask you?” now works).
• Freedom to run long tasks, web tools, and computer tools without HTTP timeouts.
Adding Firecrawl web tools to the production agent
Earlier you added Firecrawl as a dev skill; now you wire it into the Telegram chat agent as a tool:
• Install Firecrawl SDK and add FIRECRAWL_API_KEY to your envs.
• Register Firecrawl tools in the Trigger chat agent configuration.
• Write instructions that tell the agent when to use Firecrawl (e.g. live prices, restaurant searches, contractor checks) without exposing Firecrawl’s name to end users.
Note: because Trigger uses transcripts, you should clear old runs after adding tools so new conversations load the updated toolset. Otherwise, the agent might reuse an old run that doesn’t know about Firecrawl yet.
Giving the agent a computer with Daytona
Some tasks require a real filesystem and tooling—like filling and signing PDFs. To support that, you integrate Daytona as a sandboxed “computer” for your agent:
• Sign up for Daytona and create an API key.
• Install the Daytona SDK and skills.
• Add DAYTONA_API_KEY to your environment.
Then you extend the Telegram agent to:
• Accept and parse file uploads (documents, images, etc.) from Telegram.
• Spin up a Daytona sandbox, download the file into it, and run code to modify it (e.g. add mock signatures and dates to a PDF).
• Upload the edited file back to the user over Telegram.
Under the hood, you may need to tweak Trigger bundling (e.g. marking form-data, busboy, or certain compression libraries as externals) so the Daytona SDK can handle uploads and downloads correctly.
Adding a database with Neon and Drizzle
To support user identity across channels and sessions, you introduce a database via Neon (Postgres) and Drizzle ORM:
• Use Neon skills to set up a database for your project.
• Add DATABASE_URL and DATABASE_URL_UNPOOLED env vars to Railway and Trigger.
• Define a channel_identifiers table via Drizzle with fields:
– id
– platform enum (initially just telegram)
– externalUserId (Telegram user ID, WhatsApp number, iMessage number, etc.)
– clerkUserId (ID from your auth provider)
– linkedAt timestamp
– Unique index on [platform, externalUserId]
Instead of migrations, you can use DB push for faster iteration in a solo dev setup, and note that preference in agents.md so your coding agent doesn’t auto-generate migrations.
Adding authentication with Clerk and device flow
Right now, anyone who finds your Telegram bot can burn your credits. To fix that, you:
• Sign up for Clerk and create an application (e.g. with Google and email sign-in).
• Install Clerk CLI and skills, and link your repo to the Clerk app.
• Add Clerk keys to your env: publishable key, secret key, and OAuth issuer/client credentials.
You then implement a device flow suitable for headless agents:
1) Hono Telegram webhook becomes the front door again (instead of Trigger’s inbound webhook).
2) On each message, Hono looks up the Telegram user ID in channel_identifiers.
3) If found, it forwards the update to Trigger’s inbound webhook with the clerkUserId attached.
4) If not found, it starts a Clerk device flow:
– Generates a login link and short code.
– Sends these to the user in Telegram.
– A Trigger task polls Clerk, waits for the user to sign in and approve.
– Once approved, it stores {platform, externalUserId, clerkUserId} in the DB.
– Replies “You are connected as <email>” and clears the temporary key.
From that point on, every message from that Telegram user is scoped to their Clerk identity, and the agent’s memory and sandbox are tied to that user—not to the raw channel ID.
Monetizing with Clerk billing and subscription gating
With auth in place, you can add a billing layer so only paying users can use the assistant:
• Enable billing in Clerk and ensure email collection is turned on.
• Create a B2C subscription plan with slug pro at $20/month.
• Update the Hono Telegram webhook to:
• Keep the login flow as-is for unauthenticated users.
• For authenticated users, check their subscription status via Clerk.
• If they don’t have the pro plan, send a link to the hosted account portal with the billing tab focused so they can upgrade.
• If they are on pro, forward the message to Trigger’s inbound webhook as usual.
This pattern gives you a clean separation:
• Hono: auth + billing gate, no heavy AI work.
• Trigger: actual agent runs, tools, and LLM calls.
Adding iMessage support with Link
WhatsApp and Apple’s native APIs can be bureaucratic and restrictive. Instead, you use Link as an aggregator that provides a phone number and handles the platform headaches for you:
• Install Link CLI and create a developer account.
• Add your own phone number as a contact for testing.
• Run link webhooks listen and text the Link phone number to confirm events arrive.
Then you:
• Install Link plugins and MCP server for your coding agent.
• Extend your schema’s platform enum to include link (for iMessage).
• Implement a Link webhook handler in Hono that mirrors the Telegram flow:
– Validate Link’s signing secret.
– Look up the sender’s phone number in channel_identifiers.
– If unknown, start the same device flow with Clerk and store the mapping.
– If known but unsubscribed, send the billing portal link.
– If known and subscribed, forward to Trigger’s Link agent inbound webhook.
In Trigger, you add a second chat agent for Link that uses the same tools and models as Telegram, but communicates via Link’s send APIs. The result: the same assistant is now reachable over iMessage, with shared identity, memory, and billing.
Observability and AI monitoring with Sentry
Once real users start using your assistant, you need visibility into errors, performance, and AI costs. That’s where Sentry comes in:
• Use Sentry’s AI wizard to set up projects for both your Hono server and your Trigger infrastructure.
• Add DSNs for each environment and adjust your start scripts to preload Sentry.
• Configure source maps so stack traces point to your original code.
Next, you:
• Add structured logs across webhooks, agent flows, sandbox creation, and channel gating.
• Enable AI/LLM monitoring to track:
– Model names and providers used
– Token usage and cost per run
– Latency and tool call performance
– Errors in tool calls and provider responses
To protect privacy, you can configure Sentry to not record message content or tool payloads—only metadata like costs and timings.
Once deployed, Sentry’s dashboard lets you:
• See every agent turn, grouped by channel (Telegram vs Link).
• Spot failing tools or repeated errors early.
• Understand which models and tools are driving your costs.
• Use SER (Sentry’s AI) later to propose and even implement fixes as pull requests.
Putting it all together: a clone-level AI assistant
By the end of this build, you have a system that looks a lot like the top SMS-based AI assistant startups:
• Channels: Telegram and iMessage (via Link), with a pattern ready for WhatsApp and more.
• Core runtime: Hono on Railway as the HTTP front door; Trigger.dev as the durable agent runtime.
• AI layer: AI SDK with Neon AI Gateway (or your provider of choice) for flexible model selection.
• Web tools: Firecrawl for fast, structured, and cheap web search.
• Computer tools: Daytona sandboxes for real file and environment manipulation (e.g. filling PDFs).
• Auth & billing: Clerk for device flow login, user identity, and subscription gating.
• Data: Neon Postgres + Drizzle ORM to map channels to users.
• Security & QA: Grappile reviewing every PR for vulnerabilities.
• Observability: Sentry tracking errors, logs, and AI metrics across the whole system.
If you’re interested in more ways to use Claude Code for ambitious projects, you might also like this deep-dive on cloning a YouTube channel’s style with Claude Code, or this comparison of how different models handle building complex apps in ChatGPT vs Gemini vs Claude: which AI builds the best Among Us clone?
From here, the roadmap is wide open: add more channels, specialize tools for verticals (travel, legal, real estate), or wrap this into a white-label product for other teams. The hard part—building a robust, multi-channel, production-ready AI assistant—is now in place.
Comments
No comments yet. Be the first to share your thoughts!