Skip to content

Commit

Permalink
add followinf option for timeline action
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 committed Jan 6, 2025
1 parent 2c227ba commit 857673f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ POST_IMMEDIATELY=
# Twitter action processing configuration
ACTION_INTERVAL= # Interval in minutes between action processing runs (default: 5 minutes)
ENABLE_ACTION_PROCESSING=false # Set to true to enable the action processing loop
MAX_ACTIONS_PROCESSING= # Maximum number of actions (e.g., retweets, likes) to process in a single cycle. Helps prevent excessive or uncontrolled actions.
MAX_ACTIONS_PROCESSING=1 # Maximum number of actions (e.g., retweets, likes) to process in a single cycle. Helps prevent excessive or uncontrolled actions.
ACTION_TIMELINE_TYPE=foryou # Type of timeline to interact with. Options: "foryou" or "following". Default: "foryou"

# Feature Flags
IMAGE_GEN= # Set to TRUE to enable image generation
Expand Down
7 changes: 6 additions & 1 deletion packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getEmbeddingZeroVector,
elizaLogger,
stringToUuid,
ActionTimelineType,
} from "@elizaos/core";
import {
QueryTweetsResponse,
Expand Down Expand Up @@ -321,7 +322,11 @@ export class ClientBase extends EventEmitter {
elizaLogger.debug("fetching timeline for actions");

const agentUsername = this.twitterConfig.TWITTER_USERNAME;
const homeTimeline = await this.twitterClient.fetchHomeTimeline(20, []);
const homeTimeline =
this.twitterConfig.ACTION_TIMELINE_TYPE ===
ActionTimelineType.Following
? await this.twitterClient.fetchFollowingTimeline(20, [])
: await this.twitterClient.fetchHomeTimeline(20, []);

return homeTimeline
.map((tweet) => ({
Expand Down
13 changes: 12 additions & 1 deletion packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { parseBooleanFromText, IAgentRuntime } from "@elizaos/core";
import {
parseBooleanFromText,
IAgentRuntime,
ActionTimelineType,
} from "@elizaos/core";
import { z, ZodError } from "zod";

export const DEFAULT_MAX_TWEET_LENGTH = 280;
Expand Down Expand Up @@ -62,6 +66,9 @@ export const twitterEnvSchema = z.object({
POST_IMMEDIATELY: z.boolean(),
TWITTER_SPACES_ENABLE: z.boolean().default(false),
MAX_ACTIONS_PROCESSING: z.number().int(),
ACTION_TIMELINE_TYPE: z
.nativeEnum(ActionTimelineType)
.default(ActionTimelineType.ForYou),
});

export type TwitterConfig = z.infer<typeof twitterEnvSchema>;
Expand Down Expand Up @@ -206,6 +213,10 @@ export async function validateTwitterConfig(
process.env.MAX_ACTIONS_PROCESSING,
1
),

ACTION_TIMELINE_TYPE:
runtime.getSetting("ACTION_TIMELINE_TYPE") ||
process.env.ACTION_TIMELINE_TYPE,
};

return twitterEnvSchema.parse(twitterConfig);
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1328,3 +1328,8 @@ export enum TranscriptionProvider {
Deepgram = "deepgram",
Local = "local",
}

export enum ActionTimelineType {
ForYou = "foryou",
Following = "following",
}

0 comments on commit 857673f

Please sign in to comment.