Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove TWITTER_COOKIES env var #1288

Merged
merged 5 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_2FA_SECRET=

TWITTER_COOKIES= # Account cookies
TWITTER_POLL_INTERVAL=120 # How often (in seconds) the bot should check for interactions
TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly increases your chance of getting banned
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
Expand Down
1 change: 0 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nombre de usuario de la cuenta
TWITTER_PASSWORD= # Contraseña de la cuenta
TWITTER_EMAIL= # Correo electrónico de la cuenta
TWITTER_COOKIES= # Cookies de la cuenta

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_PTBR.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nome de usuário da conta
TWITTER_PASSWORD= # Senha da conta
TWITTER_EMAIL= # Email da conta
TWITTER_COOKIES= # Cookies da conta

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Имя пользователя аккаунта
TWITTER_PASSWORD= # Пароль аккаунта
TWITTER_EMAIL= # Email аккаунта
TWITTER_COOKIES= # Cookies аккаунта

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_TH.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # ชื่อผู้ใช้บัญชี
TWITTER_PASSWORD= # รหัสผ่าน
TWITTER_EMAIL= # อีเมล
TWITTER_COOKIES= # คุกกี้
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_KOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies

X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DISCORD_API_TOKEN= # Discord bot token
TWITTER_USERNAME= # Bot Twitter username
TWITTER_PASSWORD= # Bot Twitter password
TWITTER_EMAIL= # Twitter account email
TWITTER_COOKIES= # Twitter auth cookies
TWITTER_DRY_RUN=false # Test mode without posting
```

Expand Down
1 change: 0 additions & 1 deletion docs/docs/packages/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const client = await TwitterClientInterface.start(runtime);
TWITTER_USERNAME = your_username;
TWITTER_PASSWORD = your_password;
TWITTER_EMAIL = your_email;
TWITTER_COOKIES = your_cookies;
```

### Components
Expand Down
11 changes: 0 additions & 11 deletions docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,10 @@ Add to your `.env`:
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies (auth_token and CT0)
```

**Important:** Log in to the [Twitter Developer Portal](https://developer.twitter.com) and enable the "Automated" label for your account to avoid being flagged as inauthentic.

Example for TWITTER_COOKIES

The TWITTER_COOKIES variable should be a JSON string containing the necessary cookies. You can find these cookies in your web browser's developer tools. Here is an example format:

```bash
TWITTER_COOKIES='[{"key":"auth_token","value":"your token","domain":".twitter.com"},
{"key":"ct0","value":"your ct0","domain":".twitter.com"},
{"key":"guest_id","value":"your guest_id","domain":".twitter.com"}]'
```

### Telegram Bot

1. Create a bot
Expand Down
38 changes: 16 additions & 22 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class ClientBase extends EventEmitter {
}

async init() {
//test
const username = this.runtime.getSetting("TWITTER_USERNAME");
const password = this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.runtime.getSetting("TWITTER_EMAIL");
Expand All @@ -163,43 +162,38 @@ export class ClientBase extends EventEmitter {
);
const twitter2faSecret =
this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.runtime.getSetting("TWITTER_COOKIES");

if (!username) {
throw new Error("Twitter username not configured");
}
// Check for Twitter cookies
if (cookies) {
elizaLogger.debug("Using cookies from settings");
const cookiesArray = JSON.parse(cookies);

await this.setCookiesFromArray(cookiesArray);
} else {
elizaLogger.debug("No cookies found in settings");
elizaLogger.debug("Checking for cached cookies");
const cachedCookies = await this.getCachedCookies(username);
if (cachedCookies) {
await this.setCookiesFromArray(cachedCookies);
}
const cachedCookies = await this.getCachedCookies(username);

if (cachedCookies) {
elizaLogger.info("Using cached cookies");
await this.setCookiesFromArray(cachedCookies);
}

elizaLogger.log("Waiting for Twitter login");
while (retries > 0) {
const cookies = await this.twitterClient.getCookies();
if ((await this.twitterClient.isLoggedIn()) && !!cookies) {
elizaLogger.info("Already logged in.");
await this.cacheCookies(username, cookies);
elizaLogger.info("Successfully logged in and cookies cached.");
break;
}

try {
await this.twitterClient.login(
username,
password,
email,
twitter2faSecret
);
if (await this.twitterClient.isLoggedIn()) {
elizaLogger.info("Successfully logged in.");
if (!cachedCookies) {
elizaLogger.info("Caching cookies");
await this.cacheCookies(
username,
await this.twitterClient.getCookies()
);
}
break;
}
} catch (error) {
elizaLogger.error(`Login attempt failed: ${error.message}`);
}
Expand Down
4 changes: 0 additions & 4 deletions packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const twitterEnvSchema = z.object({
TWITTER_USERNAME: z.string().min(1, "Twitter username is required"),
TWITTER_PASSWORD: z.string().min(1, "Twitter password is required"),
TWITTER_EMAIL: z.string().email("Valid Twitter email is required"),
TWITTER_COOKIES: z.string().optional(),
MAX_TWEET_LENGTH: z
.string()
.pipe(z.coerce.number().min(0).int())
Expand All @@ -37,9 +36,6 @@ export async function validateTwitterConfig(
TWITTER_EMAIL:
runtime.getSetting("TWITTER_EMAIL") ||
process.env.TWITTER_EMAIL,
TWITTER_COOKIES:
runtime.getSetting("TWITTER_COOKIES") ||
process.env.TWITTER_COOKIES,
MAX_TWEET_LENGTH:
runtime.getSetting("MAX_TWEET_LENGTH") ||
process.env.MAX_TWEET_LENGTH ||
Expand Down
Loading