diff --git a/.env.example b/.env.example index b2aebf1b64..b1f05998b7 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/README_CN.md b/README_CN.md index 6c9618447c..146ce690cf 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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= diff --git a/README_ES.md b/README_ES.md index e009f73ffb..17156e094c 100644 --- a/README_ES.md +++ b/README_ES.md @@ -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= diff --git a/README_JA.md b/README_JA.md index f17f9ba604..dea9a32e27 100644 --- a/README_JA.md +++ b/README_JA.md @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false TWITTER_USERNAME= # アカウントのユーザー名 TWITTER_PASSWORD= # アカウントのパスワード TWITTER_EMAIL= # アカウントのメール -TWITTER_COOKIES= # アカウントのクッキー X_SERVER_URL= XAI_API_KEY= diff --git a/README_PTBR.md b/README_PTBR.md index 8bdac6d84e..e81258ff3a 100644 --- a/README_PTBR.md +++ b/README_PTBR.md @@ -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= diff --git a/README_RU.md b/README_RU.md index 0715359602..a1f1b93b87 100644 --- a/README_RU.md +++ b/README_RU.md @@ -114,7 +114,6 @@ TWITTER_DRY_RUN=false TWITTER_USERNAME= # Имя пользователя аккаунта TWITTER_PASSWORD= # Пароль аккаунта TWITTER_EMAIL= # Email аккаунта -TWITTER_COOKIES= # Cookies аккаунта X_SERVER_URL= XAI_API_KEY= diff --git a/docs/README.md b/docs/README.md index 0f18629003..27dc784eaf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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= diff --git a/docs/README_CN.md b/docs/README_CN.md index 64ed07eaf3..61e5efe0a7 100644 --- a/docs/README_CN.md +++ b/docs/README_CN.md @@ -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= diff --git a/docs/README_FR.md b/docs/README_FR.md index a337222ff2..db7f8bfacd 100644 --- a/docs/README_FR.md +++ b/docs/README_FR.md @@ -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= diff --git a/docs/README_TH.md b/docs/README_TH.md index d50c69af0c..d89c854cf0 100644 --- a/docs/README_TH.md +++ b/docs/README_TH.md @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false TWITTER_USERNAME= # ชื่อผู้ใช้บัญชี TWITTER_PASSWORD= # รหัสผ่าน TWITTER_EMAIL= # อีเมล -TWITTER_COOKIES= # คุกกี้ X_SERVER_URL= XAI_API_KEY= diff --git a/docs/docs/api/_media/README_CN.md b/docs/docs/api/_media/README_CN.md index 9b1f922a6f..3d101ddbff 100644 --- a/docs/docs/api/_media/README_CN.md +++ b/docs/docs/api/_media/README_CN.md @@ -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= diff --git a/docs/docs/api/_media/README_FR.md b/docs/docs/api/_media/README_FR.md index 456641cce4..41b92f055f 100644 --- a/docs/docs/api/_media/README_FR.md +++ b/docs/docs/api/_media/README_FR.md @@ -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= diff --git a/docs/docs/api/_media/README_JA.md b/docs/docs/api/_media/README_JA.md index 447be875a5..3bd9302ccb 100644 --- a/docs/docs/api/_media/README_JA.md +++ b/docs/docs/api/_media/README_JA.md @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false TWITTER_USERNAME= # アカウントのユーザー名 TWITTER_PASSWORD= # アカウントのパスワード TWITTER_EMAIL= # アカウントのメール -TWITTER_COOKIES= # アカウントのクッキー X_SERVER_URL= XAI_API_KEY= diff --git a/docs/docs/api/_media/README_KOR.md b/docs/docs/api/_media/README_KOR.md index 1d541f87f9..555d037d9f 100644 --- a/docs/docs/api/_media/README_KOR.md +++ b/docs/docs/api/_media/README_KOR.md @@ -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= diff --git a/docs/docs/api/index.md b/docs/docs/api/index.md index 0408a5cd35..4f3c232dcd 100644 --- a/docs/docs/api/index.md +++ b/docs/docs/api/index.md @@ -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= diff --git a/docs/docs/guides/configuration.md b/docs/docs/guides/configuration.md index bc51efda0b..e5de0a0b96 100644 --- a/docs/docs/guides/configuration.md +++ b/docs/docs/guides/configuration.md @@ -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 ``` diff --git a/docs/docs/packages/clients.md b/docs/docs/packages/clients.md index d586112a9b..b96d2b46b0 100644 --- a/docs/docs/packages/clients.md +++ b/docs/docs/packages/clients.md @@ -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 diff --git a/docs/docs/quickstart.md b/docs/docs/quickstart.md index ba4143abf4..7a12d76f55 100644 --- a/docs/docs/quickstart.md +++ b/docs/docs/quickstart.md @@ -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 diff --git a/packages/client-twitter/src/base.ts b/packages/client-twitter/src/base.ts index 861821170d..feedf94c4f 100644 --- a/packages/client-twitter/src/base.ts +++ b/packages/client-twitter/src/base.ts @@ -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"); @@ -163,36 +162,20 @@ 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, @@ -200,6 +183,17 @@ export class ClientBase extends EventEmitter { 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}`); } diff --git a/packages/client-twitter/src/environment.ts b/packages/client-twitter/src/environment.ts index 3340fc9674..8adabce3b8 100644 --- a/packages/client-twitter/src/environment.ts +++ b/packages/client-twitter/src/environment.ts @@ -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()) @@ -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 ||