Skip to content

Commit c5992d3

Browse files
Merge pull request #263 from ai16z/twitter-profile-remake
twitter-profile-remake
2 parents 30587cd + d041897 commit c5992d3

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
@@ -274,6 +274,24 @@ export class ClientBase extends EventEmitter {
274274
console.log("Twitter user ID:", userId);
275275
this.twitterUserId = userId;
276276

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

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

packages/core/src/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ export type Character = {
369369
chat: string[];
370370
post: string[];
371371
};
372+
twitterProfile?: {
373+
username: string;
374+
screenName: string;
375+
bio: string;
376+
nicknames?: string[];
377+
};
372378
};
373379

374380
export interface IDatabaseAdapter {

0 commit comments

Comments
 (0)