@chat-adapter/x weekly downloads statistics
By chat-adapter (14 listings) · npm · AI SDKs
X (Twitter) adapter for Chat SDK: reply to mentions, send direct messages, and post from your bot account with the X API v2, plus encrypted XChat conversations from the @chat-adapter/x/chat subpath
@chat-adapter/x has 131,808 recorded weekly downloads on npm, a decrease of 9.2% over the past 30 days, ranking #600 of 3,247 tracked listings.
About @chat-adapter/x
@chat-adapter/x
npm package:
@chat-adapter/x
X (Twitter) adapter for Chat SDK, using the X API v2 and the X Activity API. Reply to public mentions, hold DM conversations, post from the bot account, and like posts.
Documentation: chat-sdk.dev/adapters/official/x · Guides: vercel.com/kb/chat-sdk
Installation
pnpm add @chat-adapter/x
Scaffold with the CLI
To scaffold a new X bot with this adapter preselected:
npx create-chat-sdk@latest my-bot --adapter x memory
Visit the adapters directory to see other available official and vendor-official adapters.
Usage
import { Chat } from "chat";
import { createXAdapter } from "@chat-adapter/x";
const bot = new Chat({
userName: "mybot",
adapters: {
x: createXAdapter(),
},
});
bot.onNewMention(async (thread, message) => {
await thread.post(`Hi @${message.author.userName}!`);
});
bot.onDirectMessage(async (thread, message) => {
await thread.post("Hello from X!");
});
When using createXAdapter() without arguments, credentials are auto-detected from environment variables.
X setup
1. Create an X app
- Go to the X developer portal and create a Project and App
- Under Keys and tokens, copy the API Key Secret (consumer secret): this becomes
X_CONSUMER_SECRET - Enable OAuth 2.0 user authentication with the scopes
tweet.read,tweet.write,users.read,dm.read,dm.write,like.write, andoffline.access - Complete the OAuth 2.0 flow for the bot account. Either store the access token as
X_USER_ACCESS_TOKEN, or storeX_CLIENT_IDplusX_REFRESH_TOKENto let the adapter manage token refresh
2. Register a webhook
X delivers events through the X Activity API. Set this up once in the X developer console, which handles the auth for you:
- Register your webhook URL (
https://your-domain.com/api/webhooks/x). It must be public HTTPS without a port. X immediately sends a CRC challenge, which the adapter answers automatically - Create subscriptions for the events the adapter consumes:
post.mention.create,dm.received, anddm.sent(private events, so the bot user must have authorized your app first)
Subscription and webhook management is one-time setup, not adapter runtime. If you script it instead of using the console, the Activity API endpoints are auth-picky and operation-specific and do not fully match the published spec (creating a private-event subscription needed OAuth 1.0a user context in testing, while list and delete used the app-only bearer token), so the console is the simpler path.
3. Environment variables
X_CONSUMER_SECRET=... # App API key secret, used for webhook CRC and signature verification
# Auth option A: static access token
X_USER_ACCESS_TOKEN=... # OAuth 2.0 user-context access token for outbound calls
# Auth option B: managed OAuth refresh (recommended for long-running bots)
X_CLIENT_ID=... # OAuth 2.0 client ID
X_REFRESH_TOKEN=... # OAuth 2.0 refresh token (requires the offline.access scope)
X_CLIENT_SECRET=... # Optional, only for confidential clients
X_ENCRYPTION_KEY=... # Optional, base64 32-byte key to encrypt persisted tokens
X_USER_ID=... # Bot account user ID. Optional if omitted it is fetched from /2/users/me; the adapter requires a resolvable bot id and fails init otherwise
X_USERNAME=... # Optional, bot @handle for mention detection (fetched when omitted)
X_API_BASE_URL=... # Optional, override the X API base URL
Token refresh
X OAuth 2.0 user tokens are short-lived (about two hours). With X_CLIENT_ID and X_REFRESH_TOKEN set, the adapter refreshes the access token before expiry and persists the rotated refresh token in your state adapter, so the bot survives restarts. Set X_ENCRYPTION_KEY to store those tokens AES-256-GCM encrypted.
Alternatively, pass a token provider and plug in your own refresh logic:
import { createXAdapter } from "@chat-adapter/x";
const adapter = createXAdapter({
userAccessToken: async () => refreshTokenFromMyStore(),
});
Webhook setup
X uses two webhook mechanisms, both handled by the adapter:
- CRC challenge (GET): X sends a
crc_tokenthat the adapter answers with an HMAC-SHA256 response keyed by your consumer secret. X re-validates hourly - Event delivery (POST): activity events signed via the
x-twitter-webhooks-signatureheader, verified against the raw request body
// Next.js App Router example
import { bot } from "@/lib/bot";
export async function GET(request: Request) {
return bot.webhooks.x(request);
}
export async function POST(request: Request) {
return bot.webhooks.x(request);
}
Features
Messaging
| Feature | Supported |
|---|---|
| Post message | Yes (mention replies and DMs) |
| Top-level posts | Yes (channel.post on x:public) |
| Edit message | Posts only (X edit eligibility rules apply) |
| Delete message | Posts and own DM events |
| Streaming | Buffered (accumulates then posts once) |
| Typing indicator | No |
Rich content…
Description from the npm listing.
- chat
- chat-sdk
- chatbot
- x
- x-api
- bot
- adapter
- messaging
- ai-agent
- ai-sdk
- vercel
- xchat
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm AI SDKs plugins
All 20 @chat-adapter/x alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@chat-adapter/x. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.