Skip to content

Commit

Permalink
Merge pull request #263 from ai16z/twitter-profile-remake
Browse files Browse the repository at this point in the history
twitter-profile-remake
  • Loading branch information
ponderingdemocritus authored Nov 17, 2024
2 parents 30587cd + d041897 commit c5992d3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 || []
};
}
}
}
6 changes: 6 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ export type Character = {
chat: string[];
post: string[];
};
twitterProfile?: {
username: string;
screenName: string;
bio: string;
nicknames?: string[];
};
};

export interface IDatabaseAdapter {
Expand Down

0 comments on commit c5992d3

Please sign in to comment.