Skip to content

Commit 833ed1b

Browse files
authored
Merge branch 'elizaOS:develop' into develop
2 parents faaa373 + c0529a0 commit 833ed1b

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

packages/client-twitter/src/plugins/SttTtsSpacesPlugin.ts

+30-19
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class SttTtsPlugin implements Plugin {
260260
/**
261261
* On speaker silence => flush STT => GPT => TTS => push to Janus
262262
*/
263-
private async processAudio(userId: UUID): Promise<void> {
263+
private async processAudio(userId: string): Promise<void> {
264264
if (this.isProcessingAudio) {
265265
return;
266266
}
@@ -396,21 +396,32 @@ export class SttTtsPlugin implements Plugin {
396396
*/
397397
private async handleUserMessage(
398398
userText: string,
399-
userId: UUID
399+
userId: string // This is the raw Twitter user ID like 'tw-1865462035586142208'
400400
): 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
401409
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}`,
405413
"twitter"
406414
);
407415

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+
409420
let state = await this.runtime.composeState(
410421
{
411422
agentId: this.runtime.agentId,
412423
content: { text: userText, source: "twitter" },
413-
userId,
424+
userId: userUuid,
414425
roomId,
415426
},
416427
{
@@ -420,13 +431,13 @@ export class SttTtsPlugin implements Plugin {
420431
);
421432

422433
const memory = {
423-
id: stringToUuid(roomId + "-voice-message-" + Date.now()),
434+
id: stringToUuid(`${roomId}-voice-message-${Date.now()}`),
424435
agentId: this.runtime.agentId,
425436
content: {
426437
text: userText,
427438
source: "twitter",
428439
},
429-
userId,
440+
userId: userUuid,
430441
roomId,
431442
embedding: getEmbeddingZeroVector(),
432443
createdAt: Date.now(),
@@ -459,7 +470,7 @@ export class SttTtsPlugin implements Plugin {
459470
const responseContent = await this._generateResponse(memory, context);
460471

461472
const responseMemory: Memory = {
462-
id: stringToUuid(memory.id + "-voice-response-" + Date.now()),
473+
id: stringToUuid(`${memory.id}-voice-response-${Date.now()}`),
463474
agentId: this.runtime.agentId,
464475
userId: this.runtime.agentId,
465476
content: {
@@ -591,17 +602,17 @@ export class SttTtsPlugin implements Plugin {
591602

592603
if (response === "RESPOND") {
593604
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") {
603608
return false;
604609
}
610+
611+
elizaLogger.error(
612+
"Invalid response from response generateText:",
613+
response
614+
);
615+
return false;
605616
}
606617

607618
/**

0 commit comments

Comments
 (0)