Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add Tweet Response Deduplication Check #622

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export class TwitterInteractionClient {
!this.client.lastCheckedTweetId ||
BigInt(tweet.id) > this.client.lastCheckedTweetId
) {
// Generate the tweetId UUID the same way it's done in handleTweet
const tweetId = stringToUuid(tweet.id + "-" + this.runtime.agentId);

// Check if we've already processed this tweet
const existingResponse = await this.runtime.messageManager.getMemoryById(tweetId);

if (existingResponse) {
elizaLogger.log(`Already responded to tweet ${tweet.id}, skipping`);
continue;
}
elizaLogger.log("New Tweet found", tweet.permanentUrl);

const roomId = stringToUuid(
Expand Down Expand Up @@ -270,10 +280,10 @@ export class TwitterInteractionClient {
url: tweet.permanentUrl,
inReplyTo: tweet.inReplyToStatusId
? stringToUuid(
tweet.inReplyToStatusId +
"-" +
this.runtime.agentId
)
tweet.inReplyToStatusId +
"-" +
this.runtime.agentId
)
: undefined,
},
userId: userIdUUID,
Expand Down Expand Up @@ -437,10 +447,10 @@ export class TwitterInteractionClient {
url: currentTweet.permanentUrl,
inReplyTo: currentTweet.inReplyToStatusId
? stringToUuid(
currentTweet.inReplyToStatusId +
"-" +
this.runtime.agentId
)
currentTweet.inReplyToStatusId +
"-" +
this.runtime.agentId
)
: undefined,
},
createdAt: currentTweet.timestamp * 1000,
Expand Down