How It Works
- The bot polls the Twitter v2 search endpoint every 30 seconds for new mentions.
- Each mention is stripped of the bot username and forwarded to
POST /agent/prompt. - The bot polls the job status until completion.
- The agent’s response is formatted for tweet length and posted as a reply thread.
Authentication
The bot uses OAuth 1.0a (user context) for posting tweets and a Bearer token for searching mentions. Both are configured via the twitter-api-v2 library.Environment Variables
| Variable | Required | Description |
|---|---|---|
TWITTER_BEARER_TOKEN | Yes | Bearer token for search/read endpoints |
TWITTER_API_KEY | Yes | OAuth 1.0a consumer key |
TWITTER_API_SECRET | Yes | OAuth 1.0a consumer secret |
TWITTER_ACCESS_TOKEN | Yes | OAuth 1.0a access token |
TWITTER_ACCESS_SECRET | Yes | OAuth 1.0a access token secret |
TWITTER_BOT_USERNAME | No | Bot username without @ (default: ouroborai_bot) |
ARB_API_URL | No | API server URL (default: http://localhost:3000) |
ARB_API_KEY | No | API key for authenticated requests |
Response Formatting
Responses are split into a tweet thread if they exceed the 280-character limit:Short responses (under 280 chars)
Short responses (under 280 chars)
Posted as a single reply tweet. Markdown is stripped (bold, italic, code,
headers, links) to produce clean plain text.
Long responses (over 280 chars)
Long responses (over 280 chars)
Split on sentence boundaries, with each tweet suffixed with a counter
(e.g.
(1/3), (2/3), (3/3)). Each tweet in the thread replies to the
previous one, creating a readable reply chain.The suffix length (6 chars for (X/N)) is accounted for when splitting.Rate Limiting
The bot enforces a per-user rate limit of one reply per 5 minutes. This prevents abuse from users who mention the bot repeatedly and protects against Twitter API rate limits. Rate limit state is held in-memory via aMap<authorId, timestamp>.
Mention Search
The search query filters out retweets to avoid processing the same content multiple times:since_id parameter tracks the newest processed tweet ID, ensuring each
mention is handled exactly once across polling cycles.
The bot requests
author_id, created_at, and conversation_id tweet
fields, plus author_id expansions, to support threading and user
attribution.Setup
1. Create a Twitter Developer App
1. Create a Twitter Developer App
Go to the Twitter Developer Portal and
create a project with read and write permissions. Generate all four OAuth
1.0a tokens plus a Bearer token.
2. Set environment variables
2. Set environment variables
Export all six authentication tokens plus the bot username.
3. Start the bot
3. Start the bot