farcaster-autoPostToX
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v10View latest version
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A Val Town script that automatically cross-posts Farcaster casts to Twitter/X using Neynar webhooks. It runs as a serverless HTTP endpoint on Val Town's Deno-based platform.
# Type check deno check index.ts # Run locally (for testing) deno run --allow-net --allow-env index.ts
Single-file HTTP handler (index.ts):
- Receives
cast.createdwebhooks from Neynar - Filters out replies (only cross-posts original casts)
- Downloads images from
imagedelivery.netand uploads natively to Twitter - Appends video/other URLs to tweet text (relies on Twitter unfurling)
- Posts to Twitter using
twitter-api-v2npm package
Key flow:
- Webhook POST → parse
CastCreatedWebhookpayload - Skip if reply (
parent_hash !== null) - Separate embeds: images → upload to Twitter; videos/URLs → append to text
- Validate 280 char limit
- Tweet via Twitter API v2
- Uses
Deno.env.get()for environment variables - Imports npm packages via
npm:prefix (e.g.,npm:twitter-api-v2) - HTTP trigger pattern:
export default async function(req: Request): Promise<Response> - TypeScript with strict mode enabled
TWITTER_API_KEYTWITTER_API_SECRETTWITTER_ACCESS_TOKENTWITTER_ACCESS_TOKEN_SECRET
Twitter API keys must have OAuth 1.0a with Read/Write permissions configured.