Skip to content

Commit b9b4954

Browse files
committed
twitter-profile-remake
1 parent 9d9c30d commit b9b4954

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/client-twitter/src/base.ts

+48
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,24 @@ export class ClientBase extends EventEmitter {
272272
console.log("Twitter user ID:", userId);
273273
this.twitterUserId = userId;
274274

275+
// Initialize Twitter profile
276+
const profile = await this.initializeProfile();
277+
if (profile) {
278+
console.log("Twitter profile initialized:", profile);
279+
280+
// Store profile info for use in responses
281+
this.runtime.character = {
282+
...this.runtime.character,
283+
twitterProfile: {
284+
username: profile.username,
285+
screenName: profile.screenName,
286+
bio: profile.bio,
287+
nicknames: profile.nicknames
288+
}
289+
};
290+
}
291+
292+
275293
await this.populateTimeline();
276294

277295
this.onReady();
@@ -601,4 +619,34 @@ export class ClientBase extends EventEmitter {
601619
});
602620
}
603621
}
622+
623+
async initializeProfile() {
624+
const username = this.runtime.getSetting("TWITTER_USERNAME");
625+
if (!username) {
626+
console.error("Twitter username not configured");
627+
return;
628+
}
629+
630+
try {
631+
const profile = await this.requestQueue.add(async () => {
632+
const profile = await this.twitterClient.getProfile(username);
633+
return {
634+
username,
635+
screenName: profile.name || this.runtime.character.name,
636+
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] : "",
637+
nicknames: this.runtime.character.twitterProfile?.nicknames || []
638+
};
639+
});
640+
641+
return profile;
642+
} catch (error) {
643+
console.error("Error fetching Twitter profile:", error);
644+
return {
645+
username: this.runtime.character.name,
646+
screenName: username,
647+
bio: typeof this.runtime.character.bio === 'string' ? this.runtime.character.bio as string : this.runtime.character.bio.length > 0 ? this.runtime.character.bio[0] : "",
648+
nicknames: this.runtime.character.twitterProfile?.nicknames || []
649+
};
650+
}
651+
}
604652
}

packages/core/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ export type Character = {
357357
chat: string[];
358358
post: string[];
359359
};
360+
twitterProfile?: {
361+
username: string;
362+
screenName: string;
363+
bio: string;
364+
nicknames?: string[];
365+
};
360366
};
361367

362368
export interface IDatabaseAdapter {

0 commit comments

Comments
 (0)