Skip to content

Commit

Permalink
add support for Twitter cookies from environment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 committed Feb 5, 2025
1 parent 2eb94ab commit 0b5d5e3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,20 @@ export class ClientBase extends EventEmitter {
throw new Error("Twitter username not configured");
}

const cachedCookies = await this.getCachedCookies(username);
const authToken = this.runtime.getSetting("TWITTER_AUTH_TOKEN");
const ct0 = this.runtime.getSetting("TWITTER_CT0");
const guestId = this.runtime.getSetting("TWITTER_GUEST_ID");

const createTwitterCookies = (authToken: string, ct0: string, guestId: string) =>
authToken && ct0 && guestId
? [
{ key: 'auth_token', value: authToken, domain: '.twitter.com' },
{ key: 'ct0', value: ct0, domain: '.twitter.com' },
{ key: 'guest_id', value: guestId, domain: '.twitter.com' },
]
: null;

const cachedCookies = await this.getCachedCookies(username) || createTwitterCookies(authToken, ct0, guestId);

if (cachedCookies) {
elizaLogger.info("Using cached cookies");
Expand Down

0 comments on commit 0b5d5e3

Please sign in to comment.