From 857673f0e3ccf2b40ef6c04c783c2bd95d787ccc Mon Sep 17 00:00:00 2001 From: Ting Chien Meng Date: Mon, 6 Jan 2025 11:28:40 -0500 Subject: [PATCH] add followinf option for timeline action --- .env.example | 3 ++- packages/client-twitter/src/base.ts | 7 ++++++- packages/client-twitter/src/environment.ts | 13 ++++++++++++- packages/core/src/types.ts | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 3125b255824..a871759f4c8 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/packages/client-twitter/src/base.ts b/packages/client-twitter/src/base.ts index f6c3431ab13..d8a800636df 100644 --- a/packages/client-twitter/src/base.ts +++ b/packages/client-twitter/src/base.ts @@ -8,6 +8,7 @@ import { getEmbeddingZeroVector, elizaLogger, stringToUuid, + ActionTimelineType, } from "@elizaos/core"; import { QueryTweetsResponse, @@ -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) => ({ diff --git a/packages/client-twitter/src/environment.ts b/packages/client-twitter/src/environment.ts index 05b3fafaae2..cdb57b02c2d 100644 --- a/packages/client-twitter/src/environment.ts +++ b/packages/client-twitter/src/environment.ts @@ -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; @@ -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; @@ -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); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 3687ded5e01..2f60e8c9081 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1328,3 +1328,8 @@ export enum TranscriptionProvider { Deepgram = "deepgram", Local = "local", } + +export enum ActionTimelineType { + ForYou = "foryou", + Following = "following", +}