Twitter Hashflags (Hash-what?)
Mar 28, 2018 · 4 minute readHave you ever tweeted out a hastag, and discovered a small image attached to the side of it? It could be for#StPatricksDay,#MarchForOurLives, or whatever#白白白白白白白白白白is meant to be. These are hashflags.
A hashflag, sometimes called Twitter emoji, is a small image that appears after a #hashtag for special events. They are not regular emoji, and you can only use them on the Twitter website, or the official Twitter apps.
If you’re a company, andyou have enough money, you can buy your own hashflag as well! That’s exactly what Disney did for the release of Star Wars: The Last Jedi.
New hashtag emojis released by@Twitterand@StarWarsahead of#TheLastJedi!#BB8#BB9E#Porgpic.twitter.com/nnRJf43o0V
— Good Morning America (@GMA)November 28, 2017
If you spend the money to buy a hashflag, it’s important that you launch it correctly—otherwise they can flop.#白白白白白白白白白白is an example of what not to do. At time of writing, it has only 10 uses.
Hashflags aren’t exclusive to English, and they can help add context to a tweet in another language. I don’t speak any Russian, but I do know that this image is of BB-8!
#звёздныевойныэпизод8pic.twitter.com/qZsjHFR4jk
— Hashflags (@HashflagArchive)January 24, 2018
Unfortunately hashflags are temporary, so any context they add to a tweet can sometimes be lost at a later date. Currently Twitter doesn’t provide an official API for hashflags, and there is no canonical list of currently active hashflags.@hashflaglisttracks hashflags, but it’s easy to miss one—this is where Azure Functions come in.
It turns out that onTwitter.comthe list of currently active hashflags is sent as a JSON object in the HTML as initial data. All I need to do is fetch Twitter.com, and extract the JSON object from the HTML.
1$ curl https://twitter.com -v --silent 2>&1|grep -o -P'.{6}activeHashflags.{6}'23"activeHashflags"I wrotesome C#to parse and extract theactiveHashflagsJSON object, and store it in an Azure blob. You can find ithere. Using Azure Functions I can run this code on a timer, so the Azure blob is always up to date with the latest Twitter hashflags. This means the blob can be used as an unofficial Twitter hashflags API—but I didn’t want to stop there.
I wanted to solve some of the issues with hashflags around both discovery and durability. Azure Functions is the perfect platform for these small, single purpose pieces of code. I ended up writing five Azure Functions in total—all of which can be foundon GitHub.
ActiveHashflagsfetches the active hashflags from Twitter, and stores them in a JSON object in an Azure Storage Blob. You can find the list of current hashflagshere.UpdateHashflagStatereads the JSON, and updates the hashflag table with the current state of each hashflag.StoreHashflagImagedownloads the hashflag image, and stores it in a blob store.CreateHeroImagecreates a hero image of the hashtag and hashflag.TweetHashflagtweets the hashtag and hero image.
Say hello to@HashflagArchive!
@HashflagArchive solves both the issues I have with hashflags: it tweets out new hashflags the same hour they are activated on twitter, which solves the issue of discovery; and it tweets an image of the hashtag and hashflag, which solves the issue of hashflags being temporary.
So this is great, but there’s still one issue—how to use hashflags outside of Twitter.com and the official Twitter apps. This is where the JSON blob comes in. I can build a wrapper library around that, and then using that library, build applications with Twitter hashflags. So that’s exactly what I did.
I wrote an npm package calledhashflags. It’s pretty simple to use, and integrates nicely with the officialtwitter-textnpm package.
1import{Hashflags}from'hashflags';23lethf:Hashflags;4Hashflags.FETCH().then((val:Map<string,string>)=>{5hf=newHashflags(val);6console.log(hf.activeHashflags);7});I wrote it in TypeScript, but it can also be used from plain old JS as well.
1constHashflags=require('hashflags').Hashflags;23lethf;4Hashflags.FETCH().then(val=>{5hf=newHashflags(val);6console.log(hf.activeHashflags);7});So there you have it, a quick introduction to Twitter hashflags via Azure Functions and an npm library. If you’ve got any questions please leave a comment below, or reach out to me on Bluesky@jamiemagee.bsky.social.


