DEV Community

Cover image for I created a Twitter bot to get Elon Musk to follow me
Epic Lee
Epic Lee

Posted on • Updated on


I created a Twitter bot to get Elon Musk to follow me

Due to boredom at work, I thought of an idea.

What if I tweeted everyday something like

"Day XXX, has @ElonMusk followed me yet?"

If he actually followed me, that would be amazing, and I could write it on my resume.

So off I went.

Step 1: Create Twitter developer account

I created a new twitter account called @ElonMuskFan8. To grab Elon's interest, I made my profile a picture of him next to Mars. Then I got API keys from Twitter's developer site. One gotcha I found was, I had to enable write access and THEN regenerate my API keys and secrets or else I'd get 401 errors when trying to POST a tweet.
Alt Text

Step 2: Create long-running process that sends one tweet a day.

I setup a simple nodeJS project, then installed twitter and express. My app would simply start a server and run an interval, checking each minute if it was 9:30 am. If so, I would send a tweet that said:

Day XX: Has @ElonMusk followed me yet?

Step 3: Deploy my app.

For serving my app I chose Heroku. I followed their instructions here and was able to deploy my app within 20 minutes. I also stored my API secrets in heroku's environment variables so I don't expose them in my Github repo.

Step 4: Wait

Now we wait and see if Elon Musk ever replies or follows back. It may take months or years, but we don't care since the bot is taking care of it for us.

If you like these types of posts let me know!

My code:

Top comments (1)

redhoodjt1988 profile image
Jonathan Reeves

this is great you have officially inspired me to do something similar with somebody else but I'm going to use Python instead of nodejs but this is a great idea thank you so much for this post.

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<