XBTify is an XMTP-powered agent that automates Farcaster-style interactions. It runs an Express server and an XMTP Agent that:
- Listens to DMs and group conversations on XMTP
- Welcomes new DMs/groups and sends inline action menus
- Watches for onchain USDC payments (gasless through Coinbase CDP Paymaster) and creates the XBT ai twin when the payment is finalized
- Exposes an HTTP endpoint to programmatically DM users
fid
Built on @xmtp/agent-sdk, with middleware for inline actions and reactions, and a Postgres-backed Drizzle ORM database.
- Responds to XMTP messages using AI
- Skips messages from self and reactions
- Replies to direct replies or when trigger keywords/mentions are detected
- Sends contextual help and action buttons when appropriate
- Handles DMs and Groups
- On first DM/group message, sends a welcome message and action menu
- Tracks group metadata changes and membership add/remove events
- Inline actions and reactions
- Registers action handlers and renders interactive buttons (XIP-67)
- Shows a “thinking” emoji while the agent processes a request
- Onchain payment flow
- When a payment is requested, watches for USDC transfers to the agent
- Acknowledges payment and continues the flow once detected
- HTTP API to send messages
POST /api/send/messageto DM a user by Farcasterfid
- Clone the repository:
git clone <repository-url> xbtify-xmtp-agent
cd xbtify-xmtp-agent- Install dependencies:
pnpm install- Set up environment variables, copy and fill all the variables
.env.exampleto.env
cp .env.example .env
vi .env- Generate wallet keys and encryption key:
pnpm run gen:keys- Build and run the server:
pnpm run build
pnpm run startRun the development server
pnpm run devThe agent reads configuration from environment variables (validated via Zod). Key variables:
APP_URL: Public base URL of this servicePORT(default3001)NODE_ENV(development|production, defaultproduction)API_KEY: API key for securing HTTP endpointsBACKEND_URL,BACKEND_API_KEY: Upstream backend integrationXMTP_ENV(dev|local|production, defaultproduction)XMTP_WALLET_KEY: Hex private key for the XMTP agentXMTP_DB_ENCRYPTION_KEY(optional): Encryption key for the local XMTP DBRAILWAY_VOLUME_MOUNT_PATH(default.): Base path for XMTP DB filesDATABASE_URL: Postgres connection string (Drizzle ORM)NEYNAR_API_KEY: Neynar API keyOPENAI_API_KEY: OpenAI API key used by the AI moduleCOINBASE_CDP_CLIENT_API_KEY: Coinbase CDP keyPIMLICO_API_KEY: Pimlico keyINFURA_API_KEY: Infura key for chain access
Notes:
- XMTP database files are created per inbox at
${RAILWAY_VOLUME_MOUNT_PATH}/${XMTP_ENV}-XXXXXXXX.db3. - When
NODE_ENV=development, API key auth is bypassed for convenience.
pnpm build: TypeScript build todistpnpm start: Run compiled server fromdistpnpm dev: Run with live-reload viatsxpnpm gen:keys: Build then generate a wallet and encryption key helper output- Drizzle:
pnpm db:generate,pnpm db:migrate,pnpm db:pull,pnpm db:push,pnpm db:studio
Base path: /api/send
Send a direct message to a user by Farcaster FID. Requires x-api-key header when not in development.
Request headers:
x-api-key: <API_KEY>
content-type: application/jsonRequest body:
{
"message": "hello from xbtify",
"userFid": 12345
}Response:
{ "status": "ok" }Example cURL:
curl -X POST "$APP_URL/api/send/message" \
-H "x-api-key: $API_KEY" \
-H "content-type: application/json" \
-d '{"message":"hello from xbtify","userFid":12345}'- The Express server exposes health (
GET /) and the messaging route. - On boot, the XMTP Agent is created via environment variables with codecs for replies, reactions, group updates, wallet send calls, custom actions, intents, and remote attachments.
- The agent registers inline-actions and an eyes-reaction middleware.
- On first group event, it persists the group and sends a welcome message plus action menu.
- On messages, it extracts content, checks triggers, generates an AI answer, optionally monitors USDC transfers, and replies.
- Node.js (v20 or higher)
- pnpm (as package manager)
- Postgres
- Ethereum Private Key (for XMTP agent)
- OpenAI API Key (for AI processing)
- Neynar API Key (for neynar webhook events)
- Coinbase CDP API Key (for Coinbase CDP paymaster)
- Pimlico API Key (for Pimlico paymaster)