@@ -208,6 +208,7 @@ export class ClientBase extends EventEmitter {
208
208
await this . setCookiesFromArray ( cookiesArray ) ;
209
209
} else {
210
210
console . log ( "Cookies file path:" , cookiesFilePath ) ;
211
+ console . log ( "username is" , this . runtime . getSetting ( "TWITTER_USERNAME" ) ) ;
211
212
if ( fs . existsSync ( cookiesFilePath ) ) {
212
213
const cookiesArray = JSON . parse (
213
214
fs . readFileSync ( cookiesFilePath , "utf-8" )
@@ -271,6 +272,23 @@ export class ClientBase extends EventEmitter {
271
272
console . log ( "Twitter user ID:" , userId ) ;
272
273
this . twitterUserId = userId ;
273
274
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
+
274
292
await this . populateTimeline ( ) ;
275
293
276
294
this . onReady ( ) ;
@@ -589,4 +607,34 @@ export class ClientBase extends EventEmitter {
589
607
} ) ;
590
608
}
591
609
}
610
+
611
+ async initializeProfile ( ) {
612
+ const username = this . runtime . getSetting ( "TWITTER_USERNAME" ) ;
613
+ if ( ! username ) {
614
+ console . error ( "Twitter username not configured" ) ;
615
+ return ;
616
+ }
617
+
618
+ try {
619
+ const profile = await this . requestQueue . add ( async ( ) => {
620
+ const profile = await this . twitterClient . getProfile ( username ) ;
621
+ return {
622
+ username,
623
+ screenName : profile . name || this . runtime . character . name ,
624
+ 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 ] : "" ,
625
+ nicknames : this . runtime . character . twitterProfile ?. nicknames || [ ]
626
+ } ;
627
+ } ) ;
628
+
629
+ return profile ;
630
+ } catch ( error ) {
631
+ console . error ( "Error fetching Twitter profile:" , error ) ;
632
+ return {
633
+ username : this . runtime . character . name ,
634
+ screenName : username ,
635
+ bio : typeof this . runtime . character . bio === 'string' ? this . runtime . character . bio as string : this . runtime . character . bio . length > 0 ? this . runtime . character . bio [ 0 ] : "" ,
636
+ nicknames : this . runtime . character . twitterProfile ?. nicknames || [ ]
637
+ } ;
638
+ }
639
+ }
592
640
}
0 commit comments