@elizaos/plugin-twitter 1.0.0-beta.14 → 1.0.0-beta.16
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 +27 -24
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -7851,7 +7851,6 @@ import {
|
|
|
7851
7851
|
ChannelType as ChannelType5,
|
|
7852
7852
|
EventType as EventType2,
|
|
7853
7853
|
ModelType as ModelType4,
|
|
7854
|
-
composePrompt as composePrompt2,
|
|
7855
7854
|
createUniqueUuid as createUniqueUuid5,
|
|
7856
7855
|
logger as logger7
|
|
7857
7856
|
} from "@elizaos/core";
|
|
@@ -7912,7 +7911,20 @@ var TwitterInteractionClient = class {
|
|
|
7912
7911
|
logger7.log("Checking Twitter interactions");
|
|
7913
7912
|
const twitterUsername = this.client.profile?.username;
|
|
7914
7913
|
try {
|
|
7915
|
-
const
|
|
7914
|
+
const cursorKey = `twitter/${twitterUsername}/mention_cursor`;
|
|
7915
|
+
const cachedCursor = await this.runtime.getCache(cursorKey);
|
|
7916
|
+
const searchResult = await this.client.fetchSearchTweets(
|
|
7917
|
+
`@${twitterUsername}`,
|
|
7918
|
+
20,
|
|
7919
|
+
1 /* Latest */,
|
|
7920
|
+
cachedCursor
|
|
7921
|
+
);
|
|
7922
|
+
const mentionCandidates = searchResult.tweets;
|
|
7923
|
+
if (mentionCandidates.length > 0 && searchResult.previous) {
|
|
7924
|
+
await this.runtime.setCache(cursorKey, searchResult.previous);
|
|
7925
|
+
} else if (!searchResult.previous && !searchResult.next) {
|
|
7926
|
+
await this.runtime.setCache(cursorKey, null);
|
|
7927
|
+
}
|
|
7916
7928
|
logger7.log("Completed checking mentioned tweets:", mentionCandidates.length);
|
|
7917
7929
|
let uniqueTweetCandidates = [...mentionCandidates];
|
|
7918
7930
|
uniqueTweetCandidates = uniqueTweetCandidates.sort((a, b) => a.id.localeCompare(b.id)).filter((tweet) => tweet.userId !== this.client.profile.id);
|
|
@@ -7994,7 +8006,6 @@ var TwitterInteractionClient = class {
|
|
|
7994
8006
|
return [];
|
|
7995
8007
|
}
|
|
7996
8008
|
};
|
|
7997
|
-
this.runtime.emitEvent(EventType2.MESSAGE_RECEIVED, messagePayload);
|
|
7998
8009
|
const mentionPayload = {
|
|
7999
8010
|
runtime: this.runtime,
|
|
8000
8011
|
message: {
|
|
@@ -8218,8 +8229,8 @@ var TwitterInteractionClient = class {
|
|
|
8218
8229
|
currentPost,
|
|
8219
8230
|
formattedConversation
|
|
8220
8231
|
};
|
|
8221
|
-
const tweetId = createUniqueUuid5(this.runtime, tweet.id);
|
|
8222
|
-
const tweetExists = await this.runtime.getMemoryById(tweetId);
|
|
8232
|
+
const tweetId = message.id || createUniqueUuid5(this.runtime, tweet.id);
|
|
8233
|
+
const tweetExists = (await this.runtime.getMemoryById(tweetId))?.id === tweetId;
|
|
8223
8234
|
if (!tweetExists) {
|
|
8224
8235
|
logger7.log("tweet does not exist, saving");
|
|
8225
8236
|
const entityId = createUniqueUuid5(this.runtime, tweet.userId);
|
|
@@ -8257,29 +8268,17 @@ var TwitterInteractionClient = class {
|
|
|
8257
8268
|
};
|
|
8258
8269
|
this.client.saveRequestMessage(memory, state);
|
|
8259
8270
|
}
|
|
8260
|
-
const
|
|
8261
|
-
state,
|
|
8262
|
-
template: this.runtime.character.templates?.shouldRespondTemplate || ""
|
|
8263
|
-
});
|
|
8264
|
-
const response = await this.runtime.useModel(ModelType4.TEXT_SMALL, {
|
|
8265
|
-
prompt: shouldRespondPrompt
|
|
8266
|
-
});
|
|
8267
|
-
const responseActions = (response.match(/(?:RESPOND|IGNORE|STOP)/g) || ["IGNORE"])[0];
|
|
8268
|
-
if (responseActions !== "RESPOND") {
|
|
8269
|
-
logger7.log(`Not responding to tweet based on shouldRespond decision: ${responseActions}`);
|
|
8270
|
-
return { text: "", actions: [responseActions] };
|
|
8271
|
-
}
|
|
8272
|
-
const callback = async (response2, tweetId2) => {
|
|
8271
|
+
const callback = async (response, tweetId2) => {
|
|
8273
8272
|
try {
|
|
8274
8273
|
const tweetToReplyTo = tweetId2 || tweet.id;
|
|
8275
8274
|
if (this.isDryRun) {
|
|
8276
|
-
logger7.info(`[DRY RUN] Would have replied to ${tweet.username} with: ${
|
|
8275
|
+
logger7.info(`[DRY RUN] Would have replied to ${tweet.username} with: ${response.text}`);
|
|
8277
8276
|
return [];
|
|
8278
8277
|
}
|
|
8279
8278
|
logger7.info(`Replying to tweet ${tweetToReplyTo}`);
|
|
8280
8279
|
const replyTweetResult = await this.client.requestQueue.add(
|
|
8281
8280
|
() => this.client.twitterClient.post("statuses/update", {
|
|
8282
|
-
status:
|
|
8281
|
+
status: response.text.substring(0, 280),
|
|
8283
8282
|
in_reply_to_status_id: tweetToReplyTo,
|
|
8284
8283
|
auto_populate_reply_metadata: true
|
|
8285
8284
|
})
|
|
@@ -8297,7 +8296,7 @@ var TwitterInteractionClient = class {
|
|
|
8297
8296
|
agentId: this.runtime.agentId,
|
|
8298
8297
|
roomId: message.roomId,
|
|
8299
8298
|
content: {
|
|
8300
|
-
...
|
|
8299
|
+
...response,
|
|
8301
8300
|
inReplyTo: message.id
|
|
8302
8301
|
},
|
|
8303
8302
|
createdAt: Date.now()
|
|
@@ -8426,6 +8425,7 @@ import {
|
|
|
8426
8425
|
EventType as EventType3,
|
|
8427
8426
|
createUniqueUuid as createUniqueUuid6,
|
|
8428
8427
|
logger as logger8,
|
|
8428
|
+
parseBooleanFromText,
|
|
8429
8429
|
truncateToCompleteSentence
|
|
8430
8430
|
} from "@elizaos/core";
|
|
8431
8431
|
var TwitterPostClient = class {
|
|
@@ -8444,9 +8444,12 @@ var TwitterPostClient = class {
|
|
|
8444
8444
|
logger8.log("Twitter Client Configuration:");
|
|
8445
8445
|
logger8.log(`- Username: ${this.twitterUsername}`);
|
|
8446
8446
|
logger8.log(`- Dry Run Mode: ${this.isDryRun ? "Enabled" : "Disabled"}`);
|
|
8447
|
-
|
|
8448
|
-
|
|
8447
|
+
this.state.isTwitterEnabled = parseBooleanFromText(
|
|
8448
|
+
String(
|
|
8449
|
+
this.state?.TWITTER_ENABLE_POST_GENERATION || this.runtime.getSetting("TWITTER_ENABLE_POST_GENERATION") || ""
|
|
8450
|
+
)
|
|
8449
8451
|
);
|
|
8452
|
+
logger8.log(`- Auto-post: ${this.state.isTwitterEnabled ? "enabled" : "disabled"}`);
|
|
8450
8453
|
logger8.log(
|
|
8451
8454
|
`- Post Interval: ${this.state?.TWITTER_POST_INTERVAL_MIN || this.runtime.getSetting("TWITTER_POST_INTERVAL_MIN")}-${this.state?.TWITTER_POST_INTERVAL_MAX || this.runtime.getSetting("TWITTER_POST_INTERVAL_MAX")} minutes`
|
|
8452
8455
|
);
|
|
@@ -8462,7 +8465,7 @@ var TwitterPostClient = class {
|
|
|
8462
8465
|
*/
|
|
8463
8466
|
async start() {
|
|
8464
8467
|
logger8.log("Starting Twitter post client...");
|
|
8465
|
-
const tweetGeneration = this.
|
|
8468
|
+
const tweetGeneration = this.state.isTwitterEnabled;
|
|
8466
8469
|
if (tweetGeneration === false) {
|
|
8467
8470
|
logger8.log("Tweet generation is disabled");
|
|
8468
8471
|
return;
|