@@ -260,7 +260,7 @@ export class SttTtsPlugin implements Plugin {
260
260
/**
261
261
* On speaker silence => flush STT => GPT => TTS => push to Janus
262
262
*/
263
- private async processAudio ( userId : UUID ) : Promise < void > {
263
+ private async processAudio ( userId : string ) : Promise < void > {
264
264
if ( this . isProcessingAudio ) {
265
265
return ;
266
266
}
@@ -396,21 +396,32 @@ export class SttTtsPlugin implements Plugin {
396
396
*/
397
397
private async handleUserMessage (
398
398
userText : string ,
399
- userId : UUID
399
+ userId : string // This is the raw Twitter user ID like 'tw-1865462035586142208'
400
400
) : Promise < string > {
401
+ // Extract the numeric ID part
402
+ const numericId = userId . replace ( "tw-" , "" ) ;
403
+ const roomId = stringToUuid ( `twitter_generate_room-${ this . spaceId } ` ) ;
404
+
405
+ // Create consistent UUID for the user
406
+ const userUuid = stringToUuid ( `twitter-user-${ numericId } ` ) ;
407
+
408
+ // Ensure the user exists in the accounts table
401
409
await this . runtime . ensureUserExists (
402
- this . runtime . agentId ,
403
- this . client . profile . username ,
404
- this . runtime . character . name ,
410
+ userUuid ,
411
+ userId , // Use full Twitter ID as username
412
+ `Twitter User ${ numericId } ` ,
405
413
"twitter"
406
414
) ;
407
415
408
- const roomId = stringToUuid ( "twitter_generate_room-" + this . spaceId ) ;
416
+ // Ensure room exists and user is in it
417
+ await this . runtime . ensureRoomExists ( roomId ) ;
418
+ await this . runtime . ensureParticipantInRoom ( userUuid , roomId ) ;
419
+
409
420
let state = await this . runtime . composeState (
410
421
{
411
422
agentId : this . runtime . agentId ,
412
423
content : { text : userText , source : "twitter" } ,
413
- userId,
424
+ userId : userUuid ,
414
425
roomId,
415
426
} ,
416
427
{
@@ -420,13 +431,13 @@ export class SttTtsPlugin implements Plugin {
420
431
) ;
421
432
422
433
const memory = {
423
- id : stringToUuid ( roomId + " -voice-message-" + Date . now ( ) ) ,
434
+ id : stringToUuid ( ` ${ roomId } -voice-message-${ Date . now ( ) } ` ) ,
424
435
agentId : this . runtime . agentId ,
425
436
content : {
426
437
text : userText ,
427
438
source : "twitter" ,
428
439
} ,
429
- userId,
440
+ userId : userUuid ,
430
441
roomId,
431
442
embedding : getEmbeddingZeroVector ( ) ,
432
443
createdAt : Date . now ( ) ,
@@ -459,7 +470,7 @@ export class SttTtsPlugin implements Plugin {
459
470
const responseContent = await this . _generateResponse ( memory , context ) ;
460
471
461
472
const responseMemory : Memory = {
462
- id : stringToUuid ( memory . id + " -voice-response-" + Date . now ( ) ) ,
473
+ id : stringToUuid ( ` ${ memory . id } -voice-response-${ Date . now ( ) } ` ) ,
463
474
agentId : this . runtime . agentId ,
464
475
userId : this . runtime . agentId ,
465
476
content : {
@@ -591,17 +602,17 @@ export class SttTtsPlugin implements Plugin {
591
602
592
603
if ( response === "RESPOND" ) {
593
604
return true ;
594
- } else if ( response === "IGNORE" ) {
595
- return false ;
596
- } else if ( response === "STOP" ) {
597
- return false ;
598
- } else {
599
- elizaLogger . error (
600
- "Invalid response from response generateText:" ,
601
- response
602
- ) ;
605
+ }
606
+
607
+ if ( response === "IGNORE" || response === "STOP" ) {
603
608
return false ;
604
609
}
610
+
611
+ elizaLogger . error (
612
+ "Invalid response from response generateText:" ,
613
+ response
614
+ ) ;
615
+ return false ;
605
616
}
606
617
607
618
/**
0 commit comments