@elizaos/plugin-twitter 1.2.17 → 1.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7073,45 +7073,54 @@ var TwitterPostClient = class {
|
|
|
7073
7073
|
logger5.log("Twitter post client stopped, exiting loop");
|
|
7074
7074
|
return;
|
|
7075
7075
|
}
|
|
7076
|
+
await this.generateNewTweet();
|
|
7077
|
+
if (!this.isRunning) {
|
|
7078
|
+
logger5.log("Twitter post client stopped after tweet, exiting loop");
|
|
7079
|
+
return;
|
|
7080
|
+
}
|
|
7076
7081
|
const postIntervalMinutes = getRandomInterval(this.runtime, "post");
|
|
7077
7082
|
const interval = postIntervalMinutes * 60 * 1e3;
|
|
7078
7083
|
logger5.info(`Next tweet scheduled in ${postIntervalMinutes.toFixed(1)} minutes`);
|
|
7079
7084
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
7080
|
-
if (!this.isRunning) {
|
|
7081
|
-
logger5.log("Twitter post client stopped during wait, exiting loop");
|
|
7082
|
-
return;
|
|
7083
|
-
}
|
|
7084
|
-
await this.generateNewTweet();
|
|
7085
7085
|
if (this.isRunning) {
|
|
7086
7086
|
generateNewTweetLoop();
|
|
7087
7087
|
}
|
|
7088
7088
|
};
|
|
7089
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
7089
|
+
await new Promise((resolve) => setTimeout(resolve, 5e3));
|
|
7090
7090
|
const postImmediately = this.state?.TWITTER_POST_IMMEDIATELY || getSetting(this.runtime, "TWITTER_POST_IMMEDIATELY") || process.env.TWITTER_POST_IMMEDIATELY;
|
|
7091
7091
|
if (postImmediately === "true" || postImmediately === true) {
|
|
7092
7092
|
logger5.info(
|
|
7093
7093
|
"TWITTER_POST_IMMEDIATELY is true, generating initial tweet now"
|
|
7094
7094
|
);
|
|
7095
|
-
|
|
7095
|
+
let retries = 0;
|
|
7096
|
+
while (retries < 5) {
|
|
7097
|
+
const success = await this.generateNewTweet();
|
|
7098
|
+
if (success) break;
|
|
7099
|
+
retries++;
|
|
7100
|
+
logger5.info(`Retrying immediate tweet (attempt ${retries}/5)...`);
|
|
7101
|
+
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
7102
|
+
}
|
|
7096
7103
|
}
|
|
7097
7104
|
generateNewTweetLoop();
|
|
7098
7105
|
}
|
|
7099
7106
|
/**
|
|
7100
7107
|
* Handles the creation and posting of a tweet by emitting standardized events.
|
|
7101
7108
|
* This approach aligns with our platform-independent architecture.
|
|
7109
|
+
* @returns {Promise<boolean>} true if tweet was posted successfully
|
|
7102
7110
|
*/
|
|
7103
7111
|
async generateNewTweet() {
|
|
7104
7112
|
logger5.info("Attempting to generate new tweet...");
|
|
7105
7113
|
if (this.isPosting) {
|
|
7106
7114
|
logger5.info("Already posting a tweet, skipping concurrent attempt");
|
|
7107
|
-
return;
|
|
7115
|
+
return false;
|
|
7108
7116
|
}
|
|
7109
7117
|
this.isPosting = true;
|
|
7110
7118
|
try {
|
|
7111
7119
|
const userId = this.client.profile?.id;
|
|
7112
7120
|
if (!userId) {
|
|
7113
7121
|
logger5.error("Cannot generate tweet: Twitter profile not available");
|
|
7114
|
-
|
|
7122
|
+
this.isPosting = false;
|
|
7123
|
+
return false;
|
|
7115
7124
|
}
|
|
7116
7125
|
logger5.info(
|
|
7117
7126
|
`Generating tweet for user: ${this.client.profile?.username} (${userId})`
|
|
@@ -7174,11 +7183,11 @@ Generate a single tweet that sounds like YOU would actually write it:`;
|
|
|
7174
7183
|
const tweetText = generatedContent.trim();
|
|
7175
7184
|
if (!tweetText || tweetText.length === 0) {
|
|
7176
7185
|
logger5.error("Generated empty tweet content");
|
|
7177
|
-
return;
|
|
7186
|
+
return false;
|
|
7178
7187
|
}
|
|
7179
7188
|
if (tweetText.includes("Error: Missing")) {
|
|
7180
7189
|
logger5.error("Error in generated content:", tweetText);
|
|
7181
|
-
return;
|
|
7190
|
+
return false;
|
|
7182
7191
|
}
|
|
7183
7192
|
if (tweetText.length > 280) {
|
|
7184
7193
|
logger5.warn(`Generated tweet too long (${tweetText.length} chars), truncating...`);
|
|
@@ -7195,27 +7204,27 @@ Generate a single tweet that sounds like YOU would actually write it:`;
|
|
|
7195
7204
|
logger5.info(`Truncated tweet: ${finalTweet}`);
|
|
7196
7205
|
if (this.isDryRun) {
|
|
7197
7206
|
logger5.info(`[DRY RUN] Would post tweet: ${finalTweet}`);
|
|
7198
|
-
return;
|
|
7207
|
+
return false;
|
|
7199
7208
|
}
|
|
7200
7209
|
const result2 = await this.postToTwitter(finalTweet, []);
|
|
7201
7210
|
if (result2 === null) {
|
|
7202
7211
|
logger5.info("Skipped posting duplicate tweet");
|
|
7203
|
-
return;
|
|
7212
|
+
return false;
|
|
7204
7213
|
}
|
|
7205
7214
|
const tweetId2 = result2.id;
|
|
7206
7215
|
logger5.info(`Tweet posted successfully! ID: ${tweetId2}`);
|
|
7207
7216
|
logger5.info("Tweet posted successfully (memory saving disabled due to room constraints)");
|
|
7208
|
-
return;
|
|
7217
|
+
return true;
|
|
7209
7218
|
}
|
|
7210
7219
|
logger5.info(`Generated tweet: ${tweetText}`);
|
|
7211
7220
|
if (this.isDryRun) {
|
|
7212
7221
|
logger5.info(`[DRY RUN] Would post tweet: ${tweetText}`);
|
|
7213
|
-
return;
|
|
7222
|
+
return false;
|
|
7214
7223
|
}
|
|
7215
7224
|
const result = await this.postToTwitter(tweetText, []);
|
|
7216
7225
|
if (result === null) {
|
|
7217
7226
|
logger5.info("Skipped posting duplicate tweet");
|
|
7218
|
-
return;
|
|
7227
|
+
return false;
|
|
7219
7228
|
}
|
|
7220
7229
|
const tweetId = result.id;
|
|
7221
7230
|
logger5.info(`Tweet posted successfully! ID: ${tweetId}`);
|
|
@@ -7255,9 +7264,11 @@ Generate a single tweet that sounds like YOU would actually write it:`;
|
|
|
7255
7264
|
};
|
|
7256
7265
|
await this.runtime.createMemory(postedMemory, "messages");
|
|
7257
7266
|
logger5.info("Tweet posted and saved to memory successfully");
|
|
7267
|
+
return true;
|
|
7258
7268
|
}
|
|
7259
7269
|
} catch (error) {
|
|
7260
7270
|
logger5.error("Error generating tweet:", error);
|
|
7271
|
+
return false;
|
|
7261
7272
|
} finally {
|
|
7262
7273
|
this.isPosting = false;
|
|
7263
7274
|
}
|
|
@@ -9096,9 +9107,19 @@ var postTweetAction = {
|
|
|
9096
9107
|
handler: async (runtime, message, state, _options, callback) => {
|
|
9097
9108
|
logger10.info("Executing POST_TWEET action");
|
|
9098
9109
|
try {
|
|
9099
|
-
const
|
|
9100
|
-
if (!
|
|
9101
|
-
|
|
9110
|
+
const twitterService = runtime.getService("twitter");
|
|
9111
|
+
if (!twitterService) {
|
|
9112
|
+
throw new Error("Twitter service not available");
|
|
9113
|
+
}
|
|
9114
|
+
const twitterClient = twitterService.twitterClient;
|
|
9115
|
+
if (!twitterClient || !twitterClient.client) {
|
|
9116
|
+
throw new Error("Twitter client not initialized in service");
|
|
9117
|
+
}
|
|
9118
|
+
const client = twitterClient.client;
|
|
9119
|
+
if (!client.profile) {
|
|
9120
|
+
throw new Error(
|
|
9121
|
+
"Twitter client not properly initialized - no profile found"
|
|
9122
|
+
);
|
|
9102
9123
|
}
|
|
9103
9124
|
let text = message.content?.text?.trim();
|
|
9104
9125
|
if (!text) {
|
|
@@ -9125,11 +9146,6 @@ var postTweetAction = {
|
|
|
9125
9146
|
text = truncated.trim() || text.substring(0, 277) + "...";
|
|
9126
9147
|
logger10.info(`Truncated tweet: ${text}`);
|
|
9127
9148
|
}
|
|
9128
|
-
if (!client.profile) {
|
|
9129
|
-
throw new Error(
|
|
9130
|
-
"Twitter client not properly initialized - no profile found"
|
|
9131
|
-
);
|
|
9132
|
-
}
|
|
9133
9149
|
let finalTweetText = text;
|
|
9134
9150
|
if (text.length < 50 || text.toLowerCase().includes("post") || text.toLowerCase().includes("tweet")) {
|
|
9135
9151
|
const tweetPrompt = `You are ${runtime.character.name}.
|