|
9 | 9 | createUniqueUuid, |
10 | 10 | ModelType, |
11 | 11 | } from "@elizaos/core"; |
12 | | -import { ClientBase } from "../base.js"; |
13 | 12 |
|
14 | 13 | export const postTweetAction: Action = { |
15 | 14 | name: "POST_TWEET", |
@@ -70,12 +69,26 @@ export const postTweetAction: Action = { |
70 | 69 | logger.info("Executing POST_TWEET action"); |
71 | 70 |
|
72 | 71 | try { |
73 | | - // Initialize a Twitter client directly |
74 | | - const client = new ClientBase(runtime, {}); |
| 72 | + // Get the Twitter service instead of creating a new client |
| 73 | + const twitterService = runtime.getService('twitter') as any; |
| 74 | + |
| 75 | + if (!twitterService) { |
| 76 | + throw new Error("Twitter service not available"); |
| 77 | + } |
| 78 | + |
| 79 | + // Get the initialized client from the service |
| 80 | + const twitterClient = twitterService.twitterClient; |
| 81 | + if (!twitterClient || !twitterClient.client) { |
| 82 | + throw new Error("Twitter client not initialized in service"); |
| 83 | + } |
| 84 | + |
| 85 | + const client = twitterClient.client; |
75 | 86 |
|
76 | | - // Check if client is initialized |
77 | | - if (!client.twitterClient) { |
78 | | - await client.init(); |
| 87 | + // Verify we have a profile |
| 88 | + if (!client.profile) { |
| 89 | + throw new Error( |
| 90 | + "Twitter client not properly initialized - no profile found", |
| 91 | + ); |
79 | 92 | } |
80 | 93 |
|
81 | 94 | // Get tweet text |
@@ -108,13 +121,6 @@ export const postTweetAction: Action = { |
108 | 121 | logger.info(`Truncated tweet: ${text}`); |
109 | 122 | } |
110 | 123 |
|
111 | | - // Verify we have a profile |
112 | | - if (!client.profile) { |
113 | | - throw new Error( |
114 | | - "Twitter client not properly initialized - no profile found", |
115 | | - ); |
116 | | - } |
117 | | - |
118 | 124 | // Generate a more natural tweet if the input is too short or generic |
119 | 125 | let finalTweetText = text; |
120 | 126 | if ( |
|
0 commit comments