npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chat-adapter-twitter

v0.1.0

Published

Twitter / X adapter for chat

Readme

chat-adapter-twitter

npm version npm downloads

Twitter / X Webhooks adapter for Chat SDK.

This adapter uses the X Account Activity API (Enterprise/Pro tier required) to receive Direct Messages in real-time and the X API v2 to send responses.

Installation

npm install chat chat-adapter-twitter

Usage

import { Chat } from "chat";
import { createTwitterAdapter } from "chat-adapter-twitter";
import { createMemoryState } from "@chat-adapter/state-memory";

const bot = new Chat({
  userName: "my_twitter_bot",
  adapters: {
    twitter: createTwitterAdapter({
      consumerKey: process.env.TWITTER_CONSUMER_KEY!,
      consumerSecret: process.env.TWITTER_CONSUMER_SECRET!,
      accessToken: process.env.TWITTER_ACCESS_TOKEN!,
      accessTokenSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET!,
      bearerToken: process.env.TWITTER_BEARER_TOKEN!,
    }),
  },
  state: createMemoryState(), // Required for deduping
});

// Twitter DMs are treated as standard messages (not mentions)
bot.onNewMessage(async (thread, message) => {
  await thread.post(`Echo: ${message.text}`);
});

Environment variables

If you don't pass options into createTwitterAdapter(), it will automatically read from these environment variables:

| Variable | Required | Description | |----------|----------|-------------| | TWITTER_CONSUMER_KEY | Yes | App API Key | | TWITTER_CONSUMER_SECRET | Yes | App API Secret | | TWITTER_ACCESS_TOKEN | Yes | Bot account access token | | TWITTER_ACCESS_TOKEN_SECRET | Yes | Bot account access token secret | | TWITTER_BEARER_TOKEN | Yes | App Bearer token (for v2 read endpoints) | | TWITTER_BOT_USERNAME | No | Override the bot display name | | TWITTER_WEBHOOK_ENV | No | Account Activity environment name (default: "production") |

Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | consumerKey | string | process.env.TWITTER_CONSUMER_KEY | App API Key | | consumerSecret | string | process.env.TWITTER_CONSUMER_SECRET | App API Secret for CRC hashing | | accessToken | string | process.env.TWITTER_ACCESS_TOKEN | Bot account access token | | accessTokenSecret | string | process.env.TWITTER_ACCESS_TOKEN_SECRET | Bot account access token secret | | bearerToken | string | process.env.TWITTER_BEARER_TOKEN | App Bearer token | | userName | string | process.env.TWITTER_BOT_USERNAME | Bot display name | | apiBaseUrl | string | "https://api.twitter.com" | Override domain for testing |

Platform setup

  1. Create a project in the X Developer Portal.
  2. Generate your Consumer Key, Consumer Secret, and Bearer Token.
  3. Set up OAuth 1.0a User Authentication in your app settings with Read/Write/Direct Messages permissions.
  4. Generate the Access Token and Access Token Secret for your bot account.
  5. Apply for the Account Activity API (requires Pro or Enterprise access).
  6. Start your server so the webhook endpoint is active.
  7. Register your webhook URL and subscribe your bot account using the Account Activity API.

Features

  • Direct Messages: Receive and reply to 1-1 DMs
  • CRC Hashing: Automatically responds to Twitter's Challenge-Response Checks
  • Media Attachments: Extracts image and video URLs from incoming DMs
  • Plain Text Rendering: Automatically converts markdown AST to plain text (with ASCII tables) since Twitter DMs don't support rich formatting

Limitations

  • No Message Editing: The Twitter API does not support editing DMs. editMessage throws NotImplementedError.
  • Typing Indicators: The X API doesn't support bot typing indicators.
  • Rate Limits: The DM API is subject to X's strict rate limits.
  • Premium Tier Requirement: Requires Account Activity API access, which is not available on free or basic tiers.

License

MIT