Skip to content

Commit 19dad67

Browse files
authored
Merge pull request elizaOS#1520 from oxSaturn/fix/long-tweet
fix: handle long tweet in utils
2 parents 69db247 + bc17ca1 commit 19dad67

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

packages/client-github/src/index.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,8 @@ export class GitHubClient {
8282
`Successfully cloned repository from ${repositoryUrl}`
8383
);
8484
return;
85-
} catch (error) {
86-
elizaLogger.error(
87-
`Failed to clone repository from ${repositoryUrl}. Retrying...`,
88-
error
89-
);
85+
} catch {
86+
elizaLogger.error(`Failed to clone repository from ${repositoryUrl}. Retrying...`);
9087
retries++;
9188
if (retries === maxRetries) {
9289
throw new Error(

packages/client-twitter/src/utils.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ export async function sendTweet(
171171
twitterUsername: string,
172172
inReplyTo: string
173173
): Promise<Memory[]> {
174-
const tweetChunks = splitTweetContent(
175-
content.text,
176-
client.twitterConfig.MAX_TWEET_LENGTH
177-
);
174+
const maxTweetLength = client.twitterConfig.MAX_TWEET_LENGTH;
175+
const isLongTweet = maxTweetLength > 280;
176+
177+
const tweetChunks = splitTweetContent(content.text, maxTweetLength);
178178
const sentTweets: Tweet[] = [];
179179
let previousTweetId = inReplyTo;
180180

@@ -212,20 +212,20 @@ export async function sendTweet(
212212
})
213213
);
214214
}
215-
const result = await client.requestQueue.add(
216-
async () =>
217-
await client.twitterClient.sendTweet(
218-
chunk.trim(),
219-
previousTweetId,
220-
mediaData
221-
)
215+
const result = await client.requestQueue.add(async () =>
216+
isLongTweet
217+
? client.twitterClient.sendLongTweet(chunk.trim(), previousTweetId, mediaData)
218+
: client.twitterClient.sendTweet(chunk.trim(), previousTweetId, mediaData)
222219
);
220+
223221
const body = await result.json();
222+
const tweetResult = isLongTweet
223+
? body.data.notetweet_create.tweet_results.result
224+
: body.data.create_tweet.tweet_results.result;
224225

225226
// if we have a response
226-
if (body?.data?.create_tweet?.tweet_results?.result) {
227+
if (tweetResult) {
227228
// Parse the response
228-
const tweetResult = body.data.create_tweet.tweet_results.result;
229229
const finalTweet: Tweet = {
230230
id: tweetResult.rest_id,
231231
text: tweetResult.legacy.full_text,
@@ -245,7 +245,7 @@ export async function sendTweet(
245245
sentTweets.push(finalTweet);
246246
previousTweetId = finalTweet.id;
247247
} else {
248-
console.error("Error sending chunk", chunk, "response:", body);
248+
elizaLogger.error("Error sending tweet chunk:", { chunk, response: body });
249249
}
250250

251251
// Wait a bit between tweets to avoid rate limiting issues

0 commit comments

Comments
 (0)