Sometimes when I've had a break from personal tech projects for a while I want to get back into the saddle but don't want to commit to something massive. I want a bite-sized, single evening project with a definite output and often a Twitter bot is the perfect creation to fill that niche. Once you have the basic formula down pat, the process is pretty easy, with most of the hassle being in convincing Twitter to give you developer access if you want to go the manual route. ## Idea When it comes to ideas, as long as you follow the limits set out below you should be able to have your Twitter bot run wild and free for as long as you like. I've done a few over time, including: * [A Twitter text adventure game](https://twitter.com/140charADV) * Cat facts * [Queer fortunes and affirmations](https://twitter.com/QueerFortune) [(source)](https://github.com/judges119/queerfortune) * [Parody Harry Potter announcements](https://twitter.com/HPAnnouncements) [(source)](https://github.com/judges119/harry-potter) * [A chicken clucking in different languages](https://twitter.com/cluckcluckbot) The easiest ones are timed Twitter bots, ones that just post something a couple of times a day. Whether it's [emoji meadows](https://twitter.com/EmojiMeadow), [generated landscapes](https://twitter.com/softlandscapes), or even just the [lyrics to one of the greatest songs of all time](https://twitter.com/africabytotobot), these bots are a great way to practice coding and creativity within a limited medium. Ones that reply to tweets directed at the bot are possible, but the Twitter API for hooking into that kind of notification has changed a bunch over time, and often for the worse. Many times I've had bots stop working and the amount of work required to bring them back into play exceeded the enjoyment or satisfaction I would feel from doing it. ## Limits The main limits for Twitter are pretty simple: * 280 character maximum (so long, 140 limit!). * Can't repeat a tweet regularly. These are hard limits in that Twitter won't let you violate them, but there's many other soft limits surrounding things like replying to a tweet automatically that wasn't initially directed at you, byzantine rules about posting images, and posting too quickly in response to something. These can get your account suspended or under review, sometimes not even immediately but some time later at the whim of whatever daemons watch over that unholy platform. ## Bot-as-a-Service Platforms If you don't want to muck around too much with writing all your own code, nor the hassle of trying to get access to Twitter's developer tools for your account, there are services out there like [Cheap Bots Done Quick](https://cheapbotsdonequick.com/) that can help you get a timed-posting Twitter bot up and running using the interesting Tracery tools that let's you author grammars for story generation. I haven't used this one myself, but it has a strong pedigree of famous Twitter bots built around it. ## Make Your Own If you want to make your own, you'll have to create a Twitter account and visit the [Twitter Developer centre](https://developer.twitter.com/) and using the banner menu apply for access to a developer account. There'll be a bunch of questions you'll have to figure out and at the moment there's a few day turnaround on having your access approved. Once you do have access, you'll need to create a new "app" and set up some information, then grab the secrets for your account. There's a bunch of different libraries to use the Twitter API for a bunch of different languages, but I tend to use [`twit`](https://www.npmjs.com/package/twit) for [Node.js](https://nodejs.org/en/) and knock something quick up in JavaScript. You can see the source for two of my bots above, which should give you an idea of how easy they are to put together. You will need something to host it on, but I run about 5-6 bots on the cheapest VPS from [DigitalOcean](https://www.digitalocean.com/) with a few other projects and haven't run into any problems. To keep them running while you're not connected to the VPS I use [PM2](https://www.npmjs.org/package/pm2) which has served me well for a few years without issue. ## Conclusion Twitter bots are a great way to explore some of that blend of technical+creative output without committing to anything major. You don't have to limit yourself to Twitter either, most social mediums have some API you can get access to, like [I did recently with Tumblr]({{< relref "/content/dev/2021-05-20-every-ssh-key.md" >}}). You can have fun with them, explore ideas, and if you get tired of it you can shut it down as well with no hassle.