Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
"required": false,
"default": 120,
"sensitive": false
},
"TWITTER_MAX_ACTIONS_BATCH_SIZE": {
"type": "number",
"description": "Maximum number of tweets to process and possibly interact with in a single batch.",
"required": false,
"default": 20,
"sensitive": false
}
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,32 @@ export class TwitterTimelineClient {
}

async handleTimeline() {
console.log("Start Hanldeling Twitter Timeline");
console.log("Start Handling Twitter Timeline");

const tweets = await this.getTimeline(20);
const maxActionsPerCycle = 20;
const maxActionsPerCycle = this.state?.TWITTER_MAX_ACTIONS_BATCH_SIZE
|| this.runtime.getSetting("TWITTER_MAX_ACTIONS_BATCH_SIZE")
|| 20;
const tweetDecisions = [];
let count = 0;

for (const tweet of tweets) {
try {
const tweetId = this.createTweetId(this.runtime, tweet);
// Skip if we've already processed this tweet
const memory = await this.runtime.getMemoryById(tweetId);
if (memory) {
console.log(`Already processed tweet ID: ${tweet.id}`);
logger.log(`Already processed tweet ID: ${tweet.id}`);
continue;
}

const roomId = createUniqueUuid(this.runtime, tweet.conversationId);

count++;
if (count > maxActionsPerCycle) {
// Count in getTimeline(#) sometimes doesn't seem to have an effect and it might retrieve more than we want.
// Stop processing if we've reached the max number of tweets to process.
break;
}
logger.debug(`Processing tweet #${count} of ${Math.min(tweets.length, maxActionsPerCycle)})`);

const message = this.formMessage(this.runtime, tweet);

let state = await this.runtime.composeState(message);
Expand Down Expand Up @@ -179,7 +188,7 @@ Choose any combination of [LIKE], [RETWEET], [QUOTE], and [REPLY] that are appro
tweet: tweet,
actionResponse: actions,
tweetState: state,
roomId: roomId,
roomId: message.roomId,
});
} catch (error) {
logger.error(`Error processing tweet ${tweet.id}:`, error);
Expand Down