How to Develop a Simple Twitter Countdown Bot

In only about an hour and at $0 cost I made a simple Christmas countdown Twitter bot. You can too (in a lot less time)!

Crystal Camarao
Jul 3, 2018 · Unlisted

About Time Until Christmas

I love Year Progress, and it inspired me to develop a very simple bot that Tweets the time left until Christmas. You can see the bot in action here.

If you don’t know, Filipinos love Christmas. Personally, I’m a huge fan. I can imagine this will help remind people to buy Christmas gifts for their loved ones. Or it can just generally get people excited for the best time of the year.

Photo by Rhaúl V. Alva on Unsplash

How I Developed it

I did a Google search and discovered Botwiki, which has an existing code for a Twitter bot you can modify that you can host on Glitch for FREE. I remixed the code for my purpose. Most of the work really is writing the code generating what status update to make.

I studied some existing countdown codes and modified them to suit my requirements. Basically, it has to output the time left until Christmas from December 26 of the previous year to December 24 of the current year. Of course, on Christmas it has to say it’s already Christmas.

Exact Steps to Develop Your Own

I’ve released my code on Github to help you. You will need it to follow the steps below, or you can just copy from the Github Gists I’ve embedded.

  1. Go to Botwiki’s Twitterbot Glitch project, and then click on the “Remix your own” button and then voila! You have your own Glitch project.

2. Next, follow steps 1 and 2 on your Glitch project’s readme file. It should be easy and straightforward.

3. Now, let us start following step 3 on your Glitch project’s readme file. First, make sure to add moment as a dependency on your package.json file. You can easily do this by clicking “Add Package” on the page of the package.json file on your Glitch project, searching for “moment” and then clicking on it.

4. Copy lines 36 to 123 of my Github repository’s server.js file and paste at the very end of your own server.js file (starting from line 36 too).

5. Next, edit the variables countdownMonth and countdownDay on lines 36 and 37 on your server.js file to the specific date you want to count down to. In my case, countdownMonth is set to December, and countdownDay is set to the 25th since that is the date of Christmas.

6. Then edit the variable status on 113 on your server.js file to reflect the text content of the post that you want while counting down.

7. Then edit the variable status on line 118 on your server.js file to reflect the text content of the post that you want once the date you are counting down to has arrived.

8. Now, let’s call the function name (countdownMessage) when posting the Twitter update by replacing line 21 of your server.js file with line 21 of my Github repository’s server.js file.

9. Lastly, we need to follow Step 4 of your readme.md file. Again, this should be easy and straightforward. (If you don’t know what a cron job is, you can read about it on Wikipedia.) I used cron-job.org, which is again FREE.

Some Important Notes

In Javascript months are set to 0 to 11 for January to December, respectively, and NOT 1 to 12. So please take note of that!

Also, it was brought to my attention that my code does not account for Daylight Saving Time. I used UTC which does not have Daylight Saving Time, but if you plan to use another time zone you will have to modify it. Here’s a resource for you.

The template bot uses Node.js, which I’ve never used until now, but it wasn’t hard to learn. I just depended on W3Schools a lot since I haven’t used Javascript in a long time. (Hell, I haven’t coded in a long time.) It should be easy for people who are familiar with Javascript, but for those who aren’t, I hope the above instructions were clear enough to help you.

What To Improve On

My bot only outputs text, and my guess is that people will enjoy status updates with images or emojis more. (UPDATE: I just added to the Time Until Christmas bot the ability to upload an accompanying random GIF which was tagged“excited”, thanks to Giphy and the suggestion of my brother.)

It would also probably be more interesting if the updates were random.

Over To You

Programmer or not, did the instructions above help you build your own Twitter countdown bot? I’d love to hear your suggestions and feedback.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store