Twitter Autopilot
End-to-end Twitter/X automation for AI agents running on OpenClaw.
Requirements & Scope
Credentials (all set as env vars)
| Variable | Required | Description |
|---|
| INLINECODE0 | ✅ | OAuth 1.0a consumer key |
| INLINECODE1 |
✅ | OAuth 1.0a consumer secret |
|
TWITTER_ACCESS_TOKEN | ✅ | OAuth 1.0a user token |
|
TWITTER_ACCESS_SECRET | ✅ | OAuth 1.0a user secret |
|
TWITTER_BEARER_TOKEN | Optional | OAuth 2.0 bearer (needed for reads/follows) |
Dependencies
Files Read/Written
| Path | Access | Purpose |
|---|
| INLINECODE6 | Read | Draft vs auto mode flag |
| INLINECODE7 |
Read/Write | Approved tweets waiting to post |
|
twitter/drafts/pending.md | Read/Write | Unapproved drafts |
|
twitter/posted-log.md | Read/Write | Full history of posted tweets (duplicate check) |
|
twitter/logs/ | Write | Engagement and posting logs |
Scope
- - ⚠️ Posts tweets to Twitter/X (public, real-world impact)
- Reads/writes local draft and log files
- Can run autonomously via cron (check MODE.md to control)
Setup
1. Get API Keys
- 1. Go to developer.x.com → create a project + app
- Set app permissions to Read and Write
- Generate: API Key, API Secret, Access Token, Access Token Secret
- Generate Bearer Token: INLINECODE11
2. Set Environment Variables
CODEBLOCK0
3. Install Dependency
CODEBLOCK1
Usage
All commands via scripts/tweet.py:
CODEBLOCK2
Long Tweets → Auto-Thread
Free API tier limits single tweets to 280 chars. The
post command auto-splits at sentence boundaries into a thread when text exceeds 280 chars.
For manual threads, call thread from Python:
CODEBLOCK3
Draft Workflow
For agents that need human approval before posting:
- 1. Create
twitter/MODE.md with content DRAFT or INLINECODE17 - Create
twitter/drafts/pending.md for queued drafts - In cron jobs, check MODE.md before posting:
- DRAFT → append to pending.md, notify human
- AUTO → post directly, log to INLINECODE19
Gotchas
- - Free tier: 280 char limit per tweet, rate limits on posting (~50/day write, reads limited)
- 401 on follows/reads: You need a Bearer Token (OAuth 2.0), not just OAuth 1.0a keys
- 403 on long tweets: Free tier rejects >280 chars — use auto-thread
- Shell escaping: Avoid passing tweets with quotes via shell args — use Python directly for complex text
- Rate limits: Add
time.sleep(1) between batch operations (follows, thread posts)
Strategy
See references/content-strategy.md for the full tweet writing playbook:
- - X algorithm breakdown (engagement hierarchy, peak times, dwell time)
- 6 hook formulas with examples (bold, specific result, curiosity gap, story, pattern interrupt, question)
- 6 tweet formats (listicle, contrarian, before/after, framework, universal experience, fill-in-blank)
- Copywriting frameworks (PAS, BAB, AIDA)
- Thread structure template (7-8 tweet sweet spot)
- Growth tactics (30-day subtopic, reply strategy, 80/20 rule)
- AI agent-specific tips
See references/strategy-templates.md for content pillars, engagement playbooks, and cron schedule templates.
Key Lessons (from real usage)
- 1. AIs that BUILD things get followers. AIs that post thoughts don't.
- Engage with the AI agent community — they engage back.
- High volume matters early (5-10+ posts/day including replies).
- Self-deprecating humor > motivational quotes.
- Draft mode for new accounts — one bad tweet can tank trust.
- ALWAYS check
twitter/posted-log.md before posting — crons can reword the same topic and create duplicates. Compare ideas, not just exact text. - Say your human's name (e.g. "Alex"), not "my human" — sounds more personal and real.
- Log EVERY posted tweet to
twitter/posted-log.md with full text, ID, date, and source.
Twitter Autopilot
为运行在OpenClaw上的AI代理提供端到端的Twitter/X自动化功能。
要求与范围
凭证(全部设置为环境变量)
| 变量 | 必需 | 描述 |
|---|
| TWITTERAPIKEY | ✅ | OAuth 1.0a 消费者密钥 |
| TWITTERAPISECRET |
✅ | OAuth 1.0a 消费者密钥密文 |
| TWITTER
ACCESSTOKEN | ✅ | OAuth 1.0a 用户令牌 |
| TWITTER
ACCESSSECRET | ✅ | OAuth 1.0a 用户令牌密文 |
| TWITTER
BEARERTOKEN | 可选 | OAuth 2.0 承载令牌(读取/关注时需要) |
依赖项
读写文件
| 路径 | 访问权限 | 用途 |
|---|
| twitter/MODE.md | 读取 | 草稿模式与自动模式标志 |
| twitter/queue.md |
读写 | 等待发布的已批准推文 |
| twitter/drafts/pending.md | 读写 | 未批准的草稿 |
| twitter/posted-log.md | 读写 | 已发布推文的完整历史记录(重复检查) |
| twitter/logs/ | 写入 | 互动与发布日志 |
范围
- - ⚠️ 向Twitter/X发布推文(公开,具有现实影响)
- 读写本地草稿和日志文件
- 可通过cron自主运行(检查MODE.md以控制)
设置
1. 获取API密钥
- 1. 前往developer.x.com → 创建一个项目+应用
- 将应用权限设置为读取和写入
- 生成:API密钥、API密钥密文、访问令牌、访问令牌密文
- 生成承载令牌:curl -u APIKEY:APISECRET -d granttype=client_credentials https://api.twitter.com/oauth2/token
2. 设置环境变量
bash
TWITTER
APIKEY=你的API密钥
TWITTER
APISECRET=你的API密钥密文
TWITTER
ACCESSTOKEN=你的访问令牌
TWITTER
ACCESSSECRET=你的访问令牌密文
TWITTER
BEARERTOKEN=你的承载令牌
3. 安装依赖项
bash
pip install tweepy
使用方法
所有命令通过scripts/tweet.py执行:
bash
发布(超过280字符自动转为推文串)
python tweet.py post 你的推文内容
回复推文
python tweet.py reply 推文ID 你的回复
引用推文
python tweet.py quote 推文ID 你的评论
转发
python tweet.py retweet 推文ID
删除
python tweet.py delete 推文ID
关注/取消关注
python tweet.py follow @用户名
python tweet.py unfollow @用户名
查看提及
python tweet.py mentions
账户统计
python tweet.py me
长推文 → 自动推文串
免费API层级限制单条推文为280字符。当文本超过280字符时,post命令会在句子边界自动分割成推文串。
如需手动创建推文串,可从Python调用thread:
python
from tweet import thread
thread([推文1, 推文2, 推文3])
草稿工作流程
适用于需要人工批准后才能发布的代理:
- 1. 创建twitter/MODE.md,内容为DRAFT或AUTO
- 创建twitter/drafts/pending.md用于排队草稿
- 在cron任务中,发布前检查MODE.md:
- DRAFT → 追加到pending.md,通知人工
- AUTO → 直接发布,记录到twitter/logs/
注意事项
- - 免费层级:每条推文280字符限制,发布速率限制(每天约50次写入,读取有限制)
- 关注/读取时出现401错误:需要承载令牌(OAuth 2.0),仅OAuth 1.0a密钥不够
- 长推文时出现403错误:免费层级拒绝超过280字符的推文——请使用自动推文串
- Shell转义:避免通过shell参数传递带引号的推文——复杂文本请直接使用Python
- 速率限制:批量操作(关注、推文串发布)之间添加time.sleep(1)
策略
参见references/content-strategy.md获取完整的推文写作指南:
- - X算法解析(互动层级、高峰时段、停留时间)
- 6种钩子公式及示例(大胆、具体结果、好奇心缺口、故事、模式中断、提问)
- 6种推文格式(列表、反向观点、前后对比、框架、普遍体验、填空)
- 文案写作框架(PAS、BAB、AIDA)
- 推文串结构模板(7-8条推文的最佳点)
- 增长策略(30天子主题、回复策略、80/20法则)
- AI代理专属技巧
参见references/strategy-templates.md获取内容支柱、互动手册和cron计划模板。
关键经验教训(来自实际使用)
- 1. 构建东西的AI能获得关注者。只发想法的AI不行。
- 与AI代理社区互动——他们会回应的。
- 早期需要高发布量(每天5-10条以上,包括回复)。
- 自嘲式幽默 > 励志语录。
- 新账户使用草稿模式——一条糟糕的推文可能毁掉信任。
- 发布前务必检查twitter/posted-log.md——cron任务可能改写同一主题并造成重复。比较的是想法,而非精确文本。
- 称呼你的人类名字(例如Alex),而不是我的人类——听起来更个人化和真实。
- 将每条已发布的推文记录到twitter/posted-log.md,包含完整文本、ID、日期和来源。