Skip to content

Commit c0d8aab

Browse files
get service from runtime for posts
1 parent ddf8882 commit c0d8aab

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@elizaos/plugin-twitter",
3-
"version": "1.2.17",
3+
"version": "1.2.18",
44
"type": "module",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/actions/postTweet.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
createUniqueUuid,
1010
ModelType,
1111
} from "@elizaos/core";
12-
import { ClientBase } from "../base.js";
1312

1413
export const postTweetAction: Action = {
1514
name: "POST_TWEET",
@@ -70,12 +69,26 @@ export const postTweetAction: Action = {
7069
logger.info("Executing POST_TWEET action");
7170

7271
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;
7586

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+
);
7992
}
8093

8194
// Get tweet text
@@ -108,13 +121,6 @@ export const postTweetAction: Action = {
108121
logger.info(`Truncated tweet: ${text}`);
109122
}
110123

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-
118124
// Generate a more natural tweet if the input is too short or generic
119125
let finalTweetText = text;
120126
if (

0 commit comments

Comments
 (0)