Search code examples
twitter

What is Twitter Direct message max length with media attachment?


I just want to confirm what is the actual Twitter Direct message length when a media is attached?

Currently we observe that it's going down to 9,976 but can't find any twitter official notes. All I can find is one of the many sites that says it's 10,000 characters.

https://marketingland.com/twitter-will-increase-dm-character-limit-from-140-to-10000-131947

Here's the sample JSON payload with attachment

{
"event":{
"type":"message_create",
"message_create":{
"target":{
"recipient_id":"xxxxx"
},
"message_data":{
"text":"Post Man Test with media. Max character is reduce to 9,976 instead of 10,000...",
"attachment":{
"type": "media",
"media": {
  "id": 1243471116468800000 }
}}}}}

Without the attachment object, max characters becomes 10,000


Solution

  • When media is attached, the message will contain a t.co link to the image itself. The length of t.co links is currently 23 characters, so (with a single character space to separate from the text) this would match the length you are seeing.

    You can confirm this by checking the Twitter help/configuration endpoint, which returns:

    "short_url_length_https": 23

    So, yes, the maximum text length with an image in a Direct Message would be 10,000-24, i.e. 9,976 characters. Unlike a regular Tweet, Direct Messages do not have the ability to "discount" the media link from the body of the message.