|
7 | 7 | ModelClass,
|
8 | 8 | stringToUuid,
|
9 | 9 | TemplateType,
|
10 |
| - UUID |
| 10 | + UUID, |
11 | 11 | } from "@elizaos/core";
|
12 | 12 | import { elizaLogger } from "@elizaos/core";
|
13 | 13 | import { ClientBase } from "./base.ts";
|
@@ -215,33 +215,16 @@ export class TwitterPostClient {
|
215 | 215 | }
|
216 | 216 |
|
217 | 217 | // Only start tweet generation loop if not in dry run mode
|
218 |
| - if (!this.isDryRun) { |
219 |
| - generateNewTweetLoop(); |
220 |
| - elizaLogger.log("Tweet generation loop started"); |
221 |
| - } else { |
222 |
| - elizaLogger.log("Tweet generation loop disabled (dry run mode)"); |
223 |
| - } |
| 218 | + generateNewTweetLoop(); |
| 219 | + elizaLogger.log("Tweet generation loop started"); |
224 | 220 |
|
225 |
| - if ( |
226 |
| - this.client.twitterConfig.ENABLE_ACTION_PROCESSING && |
227 |
| - !this.isDryRun |
228 |
| - ) { |
| 221 | + if (this.client.twitterConfig.ENABLE_ACTION_PROCESSING) { |
229 | 222 | processActionsLoop().catch((error) => {
|
230 | 223 | elizaLogger.error(
|
231 | 224 | "Fatal error in process actions loop:",
|
232 | 225 | error
|
233 | 226 | );
|
234 | 227 | });
|
235 |
| - } else { |
236 |
| - if (this.isDryRun) { |
237 |
| - elizaLogger.log( |
238 |
| - "Action processing loop disabled (dry run mode)" |
239 |
| - ); |
240 |
| - } else { |
241 |
| - elizaLogger.log( |
242 |
| - "Action processing loop disabled by configuration" |
243 |
| - ); |
244 |
| - } |
245 | 228 | }
|
246 | 229 | }
|
247 | 230 |
|
@@ -618,26 +601,21 @@ export class TwitterPostClient {
|
618 | 601 |
|
619 | 602 | elizaLogger.log("Processing tweet actions");
|
620 | 603 |
|
621 |
| - if (this.isDryRun) { |
622 |
| - elizaLogger.log("Dry run mode: simulating tweet actions"); |
623 |
| - return []; |
624 |
| - } |
625 |
| - |
626 | 604 | await this.runtime.ensureUserExists(
|
627 | 605 | this.runtime.agentId,
|
628 | 606 | this.twitterUsername,
|
629 | 607 | this.runtime.character.name,
|
630 | 608 | "twitter"
|
631 | 609 | );
|
632 | 610 |
|
633 |
| - const homeTimeline = await this.client.fetchTimelineForActions( |
| 611 | + const timelines = await this.client.fetchTimelineForActions( |
634 | 612 | MAX_TIMELINES_TO_FETCH
|
635 | 613 | );
|
636 | 614 | const maxActionsProcessing =
|
637 | 615 | this.client.twitterConfig.MAX_ACTIONS_PROCESSING;
|
638 | 616 | const processedTimelines = [];
|
639 | 617 |
|
640 |
| - for (const tweet of homeTimeline) { |
| 618 | + for (const tweet of timelines) { |
641 | 619 | try {
|
642 | 620 | // Skip if we've already processed this tweet
|
643 | 621 | const memory =
|
@@ -770,56 +748,47 @@ export class TwitterPostClient {
|
770 | 748 | const executedActions: string[] = [];
|
771 | 749 | // Execute actions
|
772 | 750 | if (actionResponse.like) {
|
773 |
| - try { |
774 |
| - if (this.isDryRun) { |
775 |
| - elizaLogger.info( |
776 |
| - `Dry run: would have liked tweet ${tweet.id}` |
777 |
| - ); |
778 |
| - executedActions.push("like (dry run)"); |
779 |
| - } else { |
| 751 | + if (this.isDryRun) { |
| 752 | + elizaLogger.info( |
| 753 | + `Dry run: would have liked tweet ${tweet.id}` |
| 754 | + ); |
| 755 | + executedActions.push("like (dry run)"); |
| 756 | + } else { |
| 757 | + try { |
780 | 758 | await this.client.twitterClient.likeTweet(tweet.id);
|
781 | 759 | executedActions.push("like");
|
782 | 760 | elizaLogger.log(`Liked tweet ${tweet.id}`);
|
| 761 | + } catch (error) { |
| 762 | + elizaLogger.error( |
| 763 | + `Error liking tweet ${tweet.id}:`, |
| 764 | + error |
| 765 | + ); |
783 | 766 | }
|
784 |
| - } catch (error) { |
785 |
| - elizaLogger.error( |
786 |
| - `Error liking tweet ${tweet.id}:`, |
787 |
| - error |
788 |
| - ); |
789 | 767 | }
|
790 | 768 | }
|
791 | 769 |
|
792 | 770 | if (actionResponse.retweet) {
|
793 |
| - try { |
794 |
| - if (this.isDryRun) { |
795 |
| - elizaLogger.info( |
796 |
| - `Dry run: would have retweeted tweet ${tweet.id}` |
797 |
| - ); |
798 |
| - executedActions.push("retweet (dry run)"); |
799 |
| - } else { |
| 771 | + if (this.isDryRun) { |
| 772 | + elizaLogger.info( |
| 773 | + `Dry run: would have retweeted tweet ${tweet.id}` |
| 774 | + ); |
| 775 | + executedActions.push("retweet (dry run)"); |
| 776 | + } else { |
| 777 | + try { |
800 | 778 | await this.client.twitterClient.retweet(tweet.id);
|
801 | 779 | executedActions.push("retweet");
|
802 | 780 | elizaLogger.log(`Retweeted tweet ${tweet.id}`);
|
| 781 | + } catch (error) { |
| 782 | + elizaLogger.error( |
| 783 | + `Error retweeting tweet ${tweet.id}:`, |
| 784 | + error |
| 785 | + ); |
803 | 786 | }
|
804 |
| - } catch (error) { |
805 |
| - elizaLogger.error( |
806 |
| - `Error retweeting tweet ${tweet.id}:`, |
807 |
| - error |
808 |
| - ); |
809 | 787 | }
|
810 | 788 | }
|
811 | 789 |
|
812 | 790 | if (actionResponse.quote) {
|
813 | 791 | try {
|
814 |
| - // Check for dry run mode |
815 |
| - if (this.isDryRun) { |
816 |
| - elizaLogger.info( |
817 |
| - `Dry run: would have posted quote tweet for ${tweet.id}` |
818 |
| - ); |
819 |
| - executedActions.push("quote (dry run)"); |
820 |
| - continue; |
821 |
| - } |
822 |
| - |
823 | 792 | // Build conversation thread for context
|
824 | 793 | const thread = await buildConversationThread(
|
825 | 794 | tweet,
|
@@ -915,32 +884,43 @@ export class TwitterPostClient {
|
915 | 884 | "Generated quote tweet content:",
|
916 | 885 | quoteContent
|
917 | 886 | );
|
918 |
| - |
919 |
| - // Send the tweet through request queue |
920 |
| - const result = await this.client.requestQueue.add( |
921 |
| - async () => |
922 |
| - await this.client.twitterClient.sendQuoteTweet( |
923 |
| - quoteContent, |
924 |
| - tweet.id |
925 |
| - ) |
926 |
| - ); |
927 |
| - |
928 |
| - const body = await result.json(); |
929 |
| - |
930 |
| - if (body?.data?.create_tweet?.tweet_results?.result) { |
931 |
| - elizaLogger.log("Successfully posted quote tweet"); |
932 |
| - executedActions.push("quote"); |
933 |
| - |
934 |
| - // Cache generation context for debugging |
935 |
| - await this.runtime.cacheManager.set( |
936 |
| - `twitter/quote_generation_${tweet.id}.txt`, |
937 |
| - `Context:\n${enrichedState}\n\nGenerated Quote:\n${quoteContent}` |
| 887 | + // Check for dry run mode |
| 888 | + if (this.isDryRun) { |
| 889 | + elizaLogger.info( |
| 890 | + `Dry run: A quote tweet for tweet ID ${tweet.id} would have been posted with the following content: "${quoteContent}".` |
938 | 891 | );
|
| 892 | + executedActions.push("quote (dry run)"); |
939 | 893 | } else {
|
940 |
| - elizaLogger.error( |
941 |
| - "Quote tweet creation failed:", |
942 |
| - body |
| 894 | + // Send the tweet through request queue |
| 895 | + const result = await this.client.requestQueue.add( |
| 896 | + async () => |
| 897 | + await this.client.twitterClient.sendQuoteTweet( |
| 898 | + quoteContent, |
| 899 | + tweet.id |
| 900 | + ) |
943 | 901 | );
|
| 902 | + |
| 903 | + const body = await result.json(); |
| 904 | + |
| 905 | + if ( |
| 906 | + body?.data?.create_tweet?.tweet_results?.result |
| 907 | + ) { |
| 908 | + elizaLogger.log( |
| 909 | + "Successfully posted quote tweet" |
| 910 | + ); |
| 911 | + executedActions.push("quote"); |
| 912 | + |
| 913 | + // Cache generation context for debugging |
| 914 | + await this.runtime.cacheManager.set( |
| 915 | + `twitter/quote_generation_${tweet.id}.txt`, |
| 916 | + `Context:\n${enrichedState}\n\nGenerated Quote:\n${quoteContent}` |
| 917 | + ); |
| 918 | + } else { |
| 919 | + elizaLogger.error( |
| 920 | + "Quote tweet creation failed:", |
| 921 | + body |
| 922 | + ); |
| 923 | + } |
944 | 924 | }
|
945 | 925 | } catch (error) {
|
946 | 926 | elizaLogger.error(
|
@@ -978,21 +958,23 @@ export class TwitterPostClient {
|
978 | 958 | roomId
|
979 | 959 | );
|
980 | 960 |
|
981 |
| - // Then create the memory |
982 |
| - await this.runtime.messageManager.createMemory({ |
983 |
| - id: stringToUuid(tweet.id + "-" + this.runtime.agentId), |
984 |
| - userId: stringToUuid(tweet.userId), |
985 |
| - content: { |
986 |
| - text: tweet.text, |
987 |
| - url: tweet.permanentUrl, |
988 |
| - source: "twitter", |
989 |
| - action: executedActions.join(","), |
990 |
| - }, |
991 |
| - agentId: this.runtime.agentId, |
992 |
| - roomId, |
993 |
| - embedding: getEmbeddingZeroVector(), |
994 |
| - createdAt: tweet.timestamp * 1000, |
995 |
| - }); |
| 961 | + if (!this.isDryRun) { |
| 962 | + // Then create the memory |
| 963 | + await this.runtime.messageManager.createMemory({ |
| 964 | + id: stringToUuid(tweet.id + "-" + this.runtime.agentId), |
| 965 | + userId: stringToUuid(tweet.userId), |
| 966 | + content: { |
| 967 | + text: tweet.text, |
| 968 | + url: tweet.permanentUrl, |
| 969 | + source: "twitter", |
| 970 | + action: executedActions.join(","), |
| 971 | + }, |
| 972 | + agentId: this.runtime.agentId, |
| 973 | + roomId, |
| 974 | + embedding: getEmbeddingZeroVector(), |
| 975 | + createdAt: tweet.timestamp * 1000, |
| 976 | + }); |
| 977 | + } |
996 | 978 |
|
997 | 979 | results.push({
|
998 | 980 | tweetId: tweet.id,
|
|
0 commit comments