Workflow to post media tweets and DM attachments
Use this workflow to post a media tweet or reply. It can also DM 1 uploaded media item. Tweet and reply media posts use public media URLs directly onclient.X.Tweets.New. Send up to 4 image URLs or exactly 1 MP4 video URL. The video can be up to 100 MB. Do not mix video with other media. Do not upload first when the media URL is already public.option.WithResponseBodyInto to capture the durable write action. Send a unique Idempotency-Key. Store id, request.hash, billing, result, and statusUrl. Poll while terminal is false. Retry only when safeToRetry is true, using a new key.ReplyToTweetID.media.MediaID as the only MediaIDs item.client.X.Tweets.New returns TweetID for confirmed posts. Raw create responses can also include the pending write fields above. That happens when confirmation is still running. client.X.Media.Upload returns media.MediaID for DM attachments. client.X.Dm.Send returns dm.MessageID for support tickets, CRM records, queue jobs, or agent memory.
Keep DM body text in private systems. Shared logs, public artifacts, queue status, and agent handoffs should omit full DM bodies. They should store message_id, optional media_id, account, user_id, and send status instead. Leave ReplyToMessageID unset even if generated SDK params expose it. The REST endpoint rejects DM reply threading.
client.X.Dm.DeleteMessage deletes a DM.
Text-only tweet and reply writes cost 30 credits. Tweet media adds 2 credits per started MB across attached files. Uploading media costs 10 credits. Sending the DM costs 10 credits. Do not pass uploaded MediaID values to client.X.Tweets.New. That method uses Media with public media URLs.