diff --git a/packages/core/src/clients/twitter/base.ts b/packages/core/src/clients/twitter/base.ts index 8617df324ec..ee0dbb6db65 100644 --- a/packages/core/src/clients/twitter/base.ts +++ b/packages/core/src/clients/twitter/base.ts @@ -206,6 +206,7 @@ export class ClientBase extends EventEmitter { await this.setCookiesFromArray(cookiesArray); } else { console.log("Cookies file path:", cookiesFilePath); + console.log("username is", this.runtime.getSetting("TWITTER_USERNAME")); if (fs.existsSync(cookiesFilePath)) { const cookiesArray = JSON.parse( fs.readFileSync(cookiesFilePath, "utf-8") @@ -269,6 +270,23 @@ export class ClientBase extends EventEmitter { console.log("Twitter user ID:", userId); this.twitterUserId = userId; + // Initialize Twitter profile + const profile = await this.initializeProfile(); + if (profile) { + console.log("Twitter profile initialized:", profile); + + // Store profile info for use in responses + this.runtime.character = { + ...this.runtime.character, + twitterProfile: { + username: profile.username, + screenName: profile.screenName, + bio: profile.bio, + nicknames: profile.nicknames + } + }; + } + await this.populateTimeline(); this.onReady(); @@ -598,4 +616,34 @@ export class ClientBase extends EventEmitter { }); } } + + async initializeProfile() { + const username = this.runtime.getSetting("TWITTER_USERNAME"); + if (!username) { + console.error("Twitter username not configured"); + return; + } + + try { + const profile = await this.requestQueue.add(async () => { + const profile = await this.twitterClient.getProfile(username); + return { + username, + screenName: profile.name || this.runtime.character.name, + bio: profile.biography || typeof this.runtime.character.bio === 'string' ? this.runtime.character.bio as string : this.runtime.character.bio.length > 0 ? this.runtime.character.bio[0] : "", + nicknames: this.runtime.character.twitterProfile?.nicknames || [] + }; + }); + + return profile; + } catch (error) { + console.error("Error fetching Twitter profile:", error); + return { + username: this.runtime.character.name, + screenName: username, + bio: typeof this.runtime.character.bio === 'string' ? this.runtime.character.bio as string : this.runtime.character.bio.length > 0 ? this.runtime.character.bio[0] : "", + nicknames: this.runtime.character.twitterProfile?.nicknames || [] + }; + } + } } diff --git a/packages/core/src/core/types.ts b/packages/core/src/core/types.ts index b12c2901a3c..a0346daf091 100644 --- a/packages/core/src/core/types.ts +++ b/packages/core/src/core/types.ts @@ -349,6 +349,12 @@ export type Character = { chat: string[]; post: string[]; }; + twitterProfile?: { + username: string; + screenName: string; + bio: string; + nicknames?: string[]; + }; }; export interface IDatabaseAdapter {