@elizaos/plugin-twitter 1.0.2 → 1.0.5

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 CHANGED
@@ -565,10 +565,7 @@ function generateRandomIP() {
565
565
  // src/client/auth.ts
566
566
  function withTransform(fetchFn, transform) {
567
567
  return async (input, init) => {
568
- const fetchArgs = await transform?.request?.(input, init) ?? [
569
- input,
570
- init
571
- ];
568
+ const fetchArgs = await transform?.request?.(input, init) ?? [input, init];
572
569
  const res = await fetchFn(...fetchArgs);
573
570
  return await transform?.response?.(res) ?? res;
574
571
  };
@@ -3222,7 +3219,7 @@ async function createCreateNoteTweetRequest(text, auth, tweetId, mediaData) {
3222
3219
  const xCsrfToken = cookies.find((cookie) => cookie.key === "ct0");
3223
3220
  const baseHeaders = await getTwitterApiHeaders();
3224
3221
  const headers = new Headers({
3225
- ...baseHeaders,
3222
+ ...Object.fromEntries(baseHeaders.entries()),
3226
3223
  authorization: `Bearer ${auth.bearerToken}`,
3227
3224
  cookie: await auth.cookieJar().getCookieString(onboardingTaskUrl),
3228
3225
  "content-type": "application/json",
@@ -3340,7 +3337,7 @@ async function deleteTweet(tweetId, auth) {
3340
3337
  const xCsrfToken = cookies.find((cookie) => cookie.key === "ct0");
3341
3338
  const baseHeaders = await getTwitterApiHeaders();
3342
3339
  const headers = new Headers({
3343
- ...baseHeaders,
3340
+ ...Object.fromEntries(baseHeaders.entries()),
3344
3341
  authorization: `Bearer ${auth.bearerToken}`,
3345
3342
  cookie: await auth.cookieJar().getCookieString(onboardingTaskUrl),
3346
3343
  "content-type": "application/json",
@@ -3629,7 +3626,7 @@ async function createQuoteTweetRequest(text, quotedTweetId, auth, mediaData) {
3629
3626
  const xCsrfToken = cookies.find((cookie) => cookie.key === "ct0");
3630
3627
  const baseHeaders = await getTwitterApiHeaders();
3631
3628
  const headers = new Headers({
3632
- ...baseHeaders,
3629
+ ...Object.fromEntries(baseHeaders.entries()),
3633
3630
  authorization: `Bearer ${auth.bearerToken}`,
3634
3631
  cookie: await auth.cookieJar().getCookieString(onboardingTaskUrl),
3635
3632
  "content-type": "application/json",
@@ -3775,7 +3772,7 @@ async function createCreateLongTweetRequest(text, auth, tweetId, mediaData) {
3775
3772
  const xCsrfToken = cookies.find((cookie) => cookie.key === "ct0");
3776
3773
  const baseHeaders = await getTwitterApiHeaders();
3777
3774
  const headers = new Headers({
3778
- ...baseHeaders,
3775
+ ...Object.fromEntries(baseHeaders.entries()),
3779
3776
  authorization: `Bearer ${auth.bearerToken}`,
3780
3777
  cookie: await auth.cookieJar().getCookieString(onboardingTaskUrl),
3781
3778
  "content-type": "application/json",
@@ -12733,6 +12730,20 @@ var TwitterInteractionClient = class {
12733
12730
  logger7.log(`Already responded to tweet ${tweet.id}, skipping`);
12734
12731
  continue;
12735
12732
  }
12733
+ const conversationRoomId = createUniqueUuid5(this.runtime, tweet.conversationId);
12734
+ const existingReplies = await this.runtime.getMemories({
12735
+ tableName: "messages",
12736
+ roomId: conversationRoomId,
12737
+ count: 10
12738
+ // Check recent messages in this room
12739
+ });
12740
+ const hasExistingReply = existingReplies.some(
12741
+ (memory2) => memory2.content?.inReplyTo === tweetId || memory2.content?.source === "twitter" && memory2.agentId === this.runtime.agentId && memory2.content?.inReplyTo === tweetId
12742
+ );
12743
+ if (hasExistingReply) {
12744
+ logger7.log(`Already replied to tweet ${tweet.id} (found existing reply), skipping`);
12745
+ continue;
12746
+ }
12736
12747
  logger7.log("New Tweet found", tweet.permanentUrl);
12737
12748
  const entityId = createUniqueUuid5(
12738
12749
  this.runtime,
@@ -13736,9 +13747,7 @@ var ClientBaseTestSuite = class {
13736
13747
  };
13737
13748
 
13738
13749
  // src/index.ts
13739
- console.log(
13740
- `Twitter plugin loaded with service name: ${TWITTER_SERVICE_NAME}`
13741
- );
13750
+ console.log(`Twitter plugin loaded with service name: ${TWITTER_SERVICE_NAME}`);
13742
13751
  var TwitterClientInstance = class {
13743
13752
  constructor(runtime, state) {
13744
13753
  this.client = new ClientBase(runtime, state);
@@ -13746,11 +13755,7 @@ var TwitterClientInstance = class {
13746
13755
  this.post = new TwitterPostClient(this.client, runtime, state);
13747
13756
  }
13748
13757
  if (runtime.getSetting("TWITTER_INTERACTION_ENABLE") !== false) {
13749
- this.interaction = new TwitterInteractionClient(
13750
- this.client,
13751
- runtime,
13752
- state
13753
- );
13758
+ this.interaction = new TwitterInteractionClient(this.client, runtime, state);
13754
13759
  }
13755
13760
  if (runtime.getSetting("TWITTER_TIMELINE_ENABLE") === true) {
13756
13761
  this.timeline = new TwitterTimelineClient(this.client, runtime, state);
@@ -13814,9 +13819,7 @@ var _TwitterService = class _TwitterService extends Service {
13814
13819
  async emitServerJoinedEvent(runtime, client) {
13815
13820
  try {
13816
13821
  if (!client.client.profile) {
13817
- logger11.warn(
13818
- "Twitter profile not available yet, can't emit WORLD_JOINED event"
13819
- );
13822
+ logger11.warn("Twitter profile not available yet, can't emit WORLD_JOINED event");
13820
13823
  return;
13821
13824
  }
13822
13825
  const profile = client.client.profile;
@@ -13839,10 +13842,7 @@ var _TwitterService = class _TwitterService extends Service {
13839
13842
  }
13840
13843
  }
13841
13844
  };
13842
- const homeTimelineRoomId = createUniqueUuid8(
13843
- runtime,
13844
- `${twitterId}-home`
13845
- );
13845
+ const homeTimelineRoomId = createUniqueUuid8(runtime, `${twitterId}-home`);
13846
13846
  const homeTimelineRoom = {
13847
13847
  id: homeTimelineRoomId,
13848
13848
  name: `${username}'s Timeline`,
@@ -13852,10 +13852,7 @@ var _TwitterService = class _TwitterService extends Service {
13852
13852
  serverId: twitterId,
13853
13853
  worldId
13854
13854
  };
13855
- const mentionsRoomId = createUniqueUuid8(
13856
- runtime,
13857
- `${twitterId}-mentions`
13858
- );
13855
+ const mentionsRoomId = createUniqueUuid8(runtime, `${twitterId}-mentions`);
13859
13856
  const mentionsRoom = {
13860
13857
  id: mentionsRoomId,
13861
13858
  name: `${username}'s Mentions`,
@@ -13879,16 +13876,14 @@ var _TwitterService = class _TwitterService extends Service {
13879
13876
  }
13880
13877
  }
13881
13878
  };
13882
- runtime.emitEvent(
13883
- ["TWITTER_WORLD_JOINED" /* WORLD_JOINED */, EventType4.WORLD_JOINED],
13884
- {
13885
- runtime,
13886
- world,
13887
- rooms: [homeTimelineRoom, mentionsRoom],
13888
- users: [twitterUser],
13889
- source: "twitter"
13890
- }
13891
- );
13879
+ console.log("twitterUser:::::::", twitterUser);
13880
+ runtime.emitEvent(["TWITTER_WORLD_JOINED" /* WORLD_JOINED */, EventType4.WORLD_JOINED], {
13881
+ runtime,
13882
+ world,
13883
+ rooms: [homeTimelineRoom, mentionsRoom],
13884
+ entities: [twitterUser],
13885
+ source: "twitter"
13886
+ });
13892
13887
  logger11.info(`Emitted WORLD_JOINED event for Twitter account ${username}`);
13893
13888
  } catch (error) {
13894
13889
  logger11.error("Failed to emit WORLD_JOINED event for Twitter:", error);
@@ -13925,11 +13920,7 @@ var _TwitterService = class _TwitterService extends Service {
13925
13920
  if (config.TWITTER_USERNAME && // Basic auth
13926
13921
  config.TWITTER_PASSWORD && config.TWITTER_EMAIL) {
13927
13922
  logger11.info("Creating default Twitter client from character settings");
13928
- await twitterClientManager.createClient(
13929
- runtime,
13930
- runtime.agentId,
13931
- config
13932
- );
13923
+ await twitterClientManager.createClient(runtime, runtime.agentId, config);
13933
13924
  }
13934
13925
  } catch (error) {
13935
13926
  logger11.error("Failed to create default Twitter client:", error);