Open Mon - Fri 10:00-18:00
Email Call Now! 0844 357 2296
Open Mon - Fri 10:00-18:00
Email Call Now! 0844 357 2296

A Week In Social Media Experimentation

Real World Chat Bot Experiment

If you follow us on Twitter you may have noticed we have been Tweeting a lot regarding social media automation. This is because in many recent Digital Marketing blogs and articles there has been a lot of talk on the rise of the chatbot and what that means for our industry. Well, we wanted to to take a look at this up and coming trend and see what we could achieve from the perspective of a Digital Marketing agency rather than that of a computer programmer.

A quick word of warning about this article is that it will be written in the style of a tutorial, we set out to do this as we would like to make this information readily available for people to not only use but expand on, and if you do please let us know as we would love to see your work and ideas.

If you are going to follow our guide you are going to need a few prerequisites:

  • Computer / Laptop (Any OS is fine however for the purpose of transparency we are using Antergos Linux)
  • Ruby (Interpreter for the Ruby programming language)
  • Text Editor (We are using Atom , its great and it’s free you can get it at , if you would rather use another editor that is completely fine)
  • Internet connection
  • Patience


If you get stuck please drop us a direct message on Twitter and we will be happy to help @LeemarDigital

Getting Started.

Well firstly we needed to setup a new Twitter account, as we have a well established account currently with 14.3k followers (Thank you all of you) we did not want to annoy our audience, the last thing anyone wants went they visit their favourite Social Media platform is to be bombarded with nonsensical tweets and a barrage of retweets that don’t offer any relevance to their interests as regardless of what people say. We soon realised every successful business has been asking the same question “What is in it for us?” so we were very aware sending out huge amounts of unwanted content would be a sure fire way to get us unfollowed.

So let us introduce to you our new automated account (@theb0tan1st) from here we were sure to edit our bio letting users know that we were in fact a chat bot operated on behalf of @LeemarDigital , this was good as it managed to attract the attention of some of our existing followers while simultaneously growing trust with a future audience by being up front that it was an automated account, honesty is always the best policy when it comes to not only life but marketing.

We chose to stick to a very simple theme for our bio , using an easy on the eyes Numix header image we snagged from a google image search and a nice sepia tone robot image. After our previous experiments on Twitter we noticed that a profile that was easier on the eyes seemed to attract more followers, we also noticed an uneasy trend that users were more likely to follow an account styled as a business rather than a more personal profile, our only thought here was that it we are naturally tuned to put faith in a logo rather than a person. While we can’t attest to the accuracy of this over time we are a superstitious bunch here at Leemar Digital and thought it best applying methods we know to work.

So now you have your new Twitter account and you’ve spruced up your bio page , give yourself a pat on the back and move on to the next step.

Next up head over to and create yourself a new API key, you will need these later. If you are unfamiliar with this term , to put it simply the API key will allow you to access your Twitter feed from an outside source. API keys are used by developers to allow for quick and easy integration to already existing platforms.

Once you have logged in with your new account on you need to click on the button labelled “Create New App” once you have done that you will be presented with the following screen:

You will need to fill out the following fields:

Name: The name of your bot here (Can be anything you want)

Description: Description of what the API key will be used for , in our case a Twitter automation solution.

Website: If you don’t have a website don’t panic , just use

Callback URL: You can leave this blank

Then click to Agree to the developer agreement and you are all set.

Once your app has been created you will be taken to a new page with information about your app , at the top you will see a set of tabs , we want to select Keys & Tokens , once on this page you will need to scroll to the bottom of the page and click Create My Access Token , you will then need to take note of the following information as you will need these later.

  • Consumer Key (API Key)
  • Consumer Secret (API Secret)
  • Access Token
  • Access Token Secret

Getting prepared to write your code

Right, it’s time to open up your text editor we are using Atom. The next thing you are going to want to do is create a new .rb file, this file will be interpreted by Ruby which hopefully you installed at the beginning of this article. If you didnt or dont know how you can use this tutorial to get you up and running (

Once you have your programming environment ready you are going to want to open a Terminal or Command Prompt depending on your operating system as we are going to install some Ruby Gems , you can find out more about Ruby Gems here if you are interested ( you can also find the documentation for the Twitter Gem here ( which features some handy examples for expanding your project.

OK let’s get this gem installed , type the following exactly as you see it into the terminal.


The Twitter gem you have just installed will be used in the bot writing process and will help us communicate quickly and easily with the Twitter API.

Time to head back to our text editor and get down to the nitty gritty of writing some code, I want to start by explaining I am new to Ruby so any experienced developers will quite likely be able to simplify this code very easily. However the end result does work very well, isn’t buggy from a usage perspective and offers some fantastic opportunity for growth. I expect I have likely overused certain bits of code which could be trimmed and if you can suggest any changes be sure to let us know via a DM on Twitter @LeemarDigital , we are always happy to learn something new that will help develop both ourselves and our clients, which is what inspired us to start this project in the first place.

The Code (Grab your API keys from earlier):


Now simply replace the content between the “ ” with your API information that we created earlier.

The above code is very simple , we are starting by telling Ruby that we need to use the Twitter Gem by using require “twitter” we then move on to authenticate with Twitter using our access keys. Once you have done this the most important part of your bot is complete, we can now create somewhat of a personality for our bot.

A little side note here from our previous experiments , depending on what you aim to use this bot for will depend on the “hashtags” you use. We found that a very quick way to build up followers was to automate a tried and tested method and the very basis of Twitter which is the followback rule , which in its very basic terms is if you follow me I will follow you a simple arrangement that helps both parties quickly grow their audience, while this may be considered somewhat of a blackhat method , it is not going to be the main focus of the bot and we found users can be relatively forgiving of such tweets and sometime get involved themselves as long as they don’t feel that they are being spammed.

You can aggregate a rather comprehensive list by using

We are going to use #TrapaDrive , #DigitalMarketing, #SEO, #PPC, #GrowthHacking, @LeemarDigital

The last one is somewhat of a shameless plug , but we are going to use this to retweet new content from our main account.

Adding some personality

Looking back at our code we are going to start to add to it , and start creating some personality, the new code we are adding is going to search for a random hashtag , from the list we gave above , and then retweet and favourite a random number of between 3 and 10 Tweets , we picked this amount of Tweets based on our user behaviour so if you want to change this feel free.



Once you have completed the above code please go ahead and save your .rb file , you can run this in your terminal by navigating to the correct directory , you can do this using the “cd” command on any platform. So for example if I had saved the .rd file to my documents I would type the following


Once in the correct directory you can then run the .rb file using the following command


And that’s it , congratulations you have built a very simple Twitter bot with only a few lines of code , you can also download the code from the bottom of this article.

In part 2 we will be expanding on the code used in this article , to show you how to make your bot reply to mentions , send DM’s , Add new followers & avoid Twitter’s pesky rate limiting problem which we are sure you will encounter while playing with this code.

If you like what you have seen but don’t have time to learn the above skills you will be pleased to know that we build automation solutions for all the well known Social Media platforms, they also offer far more advanced features than we will be covering in our articles that allow you to grow your a loyal audience overtime. You can contact us about this on Twitter by finding @LeemarDigital , you will soon be able to chat to us directly from our website , which is currently under construction.

Thank you for taking the time to read our article and we hope you will join us next time.

We’ve added all the code you need for this article here:

Leave a Reply