diff --git a/packages/client-twitter/src/base.ts b/packages/client-twitter/src/base.ts index 12adf70eda..925c64f3cf 100644 --- a/packages/client-twitter/src/base.ts +++ b/packages/client-twitter/src/base.ts @@ -274,6 +274,24 @@ 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(); @@ -603,4 +621,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/types.ts b/packages/core/src/types.ts index 040b743a68..0cde3d6972 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -357,6 +357,12 @@ export type Character = { chat: string[]; post: string[]; }; + twitterProfile?: { + username: string; + screenName: string; + bio: string; + nicknames?: string[]; + }; }; export interface IDatabaseAdapter {