From bcd58e1f96f2b1ae3ca139b16f3468678d7370b6 Mon Sep 17 00:00:00 2001 From: Ting Chien Meng Date: Sun, 1 Dec 2024 10:52:45 -0500 Subject: [PATCH 1/2] correct roomID and add missing timestamp property for tweet --- packages/client-twitter/src/post.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/client-twitter/src/post.ts b/packages/client-twitter/src/post.ts index b8355610f97..ac4f18c921a 100644 --- a/packages/client-twitter/src/post.ts +++ b/packages/client-twitter/src/post.ts @@ -83,9 +83,9 @@ export class TwitterPostClient { const lastPostTimestamp = lastPost?.timestamp ?? 0; const minMinutes = - parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 90; + parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 1; const maxMinutes = - parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 180; + parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 1; const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes; @@ -125,6 +125,9 @@ export class TwitterPostClient { elizaLogger.log("Generating new tweet"); try { + const roomId = stringToUuid( + "twitter_generate_room-" + this.client.profile.username + ); await this.runtime.ensureUserExists( this.runtime.agentId, this.client.profile.username, @@ -157,7 +160,7 @@ export class TwitterPostClient { const state = await this.runtime.composeState( { userId: this.runtime.agentId, - roomId: stringToUuid("twitter_generate_room"), + roomId: roomId, agentId: this.runtime.agentId, content: { text: topics, @@ -177,7 +180,7 @@ export class TwitterPostClient { twitterPostTemplate, }); - elizaLogger.debug("generate post prompt:\n" + context); + console.log("generate post prompt:\n" + context); const newTweetContent = await generateText({ runtime: this.runtime, @@ -221,6 +224,9 @@ export class TwitterPostClient { text: tweetResult.legacy.full_text, conversationId: tweetResult.legacy.conversation_id_str, createdAt: tweetResult.legacy.created_at, + timestamp: new Date( + tweetResult.legacy.created_at + ).getTime(), userId: this.client.profile.id, inReplyToStatusId: tweetResult.legacy.in_reply_to_status_id_str, @@ -247,10 +253,6 @@ export class TwitterPostClient { await this.client.cacheTimeline(homeTimeline); elizaLogger.log(`Tweet posted:\n ${tweet.permanentUrl}`); - const roomId = stringToUuid( - tweet.conversationId + "-" + this.runtime.agentId - ); - await this.runtime.ensureRoomExists(roomId); await this.runtime.ensureParticipantInRoom( this.runtime.agentId, @@ -268,7 +270,7 @@ export class TwitterPostClient { }, roomId, embedding: getEmbeddingZeroVector(), - createdAt: tweet.timestamp * 1000, + createdAt: tweet.timestamp, }); } catch (error) { elizaLogger.error("Error sending tweet:", error); From 07aabf13b6efd008fb2f23b98b7cb1a561c922cf Mon Sep 17 00:00:00 2001 From: Ting Chien Meng Date: Sun, 1 Dec 2024 10:54:01 -0500 Subject: [PATCH 2/2] revert testing code --- packages/client-twitter/src/post.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client-twitter/src/post.ts b/packages/client-twitter/src/post.ts index ac4f18c921a..5176ebff7dc 100644 --- a/packages/client-twitter/src/post.ts +++ b/packages/client-twitter/src/post.ts @@ -83,9 +83,9 @@ export class TwitterPostClient { const lastPostTimestamp = lastPost?.timestamp ?? 0; const minMinutes = - parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 1; + parseInt(this.runtime.getSetting("POST_INTERVAL_MIN")) || 90; const maxMinutes = - parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 1; + parseInt(this.runtime.getSetting("POST_INTERVAL_MAX")) || 180; const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes; @@ -180,7 +180,7 @@ export class TwitterPostClient { twitterPostTemplate, }); - console.log("generate post prompt:\n" + context); + elizaLogger.debug("generate post prompt:\n" + context); const newTweetContent = await generateText({ runtime: this.runtime,