@@ -171,10 +171,10 @@ export async function sendTweet(
171
171
twitterUsername : string ,
172
172
inReplyTo : string
173
173
) : 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 ) ;
178
178
const sentTweets : Tweet [ ] = [ ] ;
179
179
let previousTweetId = inReplyTo ;
180
180
@@ -212,20 +212,20 @@ export async function sendTweet(
212
212
} )
213
213
) ;
214
214
}
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 )
222
219
) ;
220
+
223
221
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 ;
224
225
225
226
// if we have a response
226
- if ( body ?. data ?. create_tweet ?. tweet_results ?. result ) {
227
+ if ( tweetResult ) {
227
228
// Parse the response
228
- const tweetResult = body . data . create_tweet . tweet_results . result ;
229
229
const finalTweet : Tweet = {
230
230
id : tweetResult . rest_id ,
231
231
text : tweetResult . legacy . full_text ,
@@ -245,7 +245,7 @@ export async function sendTweet(
245
245
sentTweets . push ( finalTweet ) ;
246
246
previousTweetId = finalTweet . id ;
247
247
} else {
248
- console . error ( "Error sending chunk" , chunk , " response:" , body ) ;
248
+ elizaLogger . error ( "Error sending tweet chunk: " , { chunk, response : body } ) ;
249
249
}
250
250
251
251
// Wait a bit between tweets to avoid rate limiting issues
0 commit comments