karlherrick.com

HipChat bot on AWS

Sunday, 04 January 2015

Over the last year or so I’ve spent some time testing out Amazon Web Services. While at first the myriad of options seemed a bit overwhelming, once I figured out what I wanted, it was fairly easy to navigate and manage the setup. In particular I used Elastic Compute Cloud with a Debian Wheezy image and stuck to the AWS Free Tier. This setup allowed me to run a t2.micro instance of Linux continuously (only rebooting it for necessary software updates) with the following basic specs:

  • CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  • RAM: A little over 512 MB
  • Architecture: x86_64

I was a little concerned while I used it that I would push the system out of the free territory, but was pleasantly surprised to not see any charges to my account. The first few months were spent getting familiar with what AWS was all about, and the next few on hosting a few NodeJS ideas.

The best test application I setup for it (and what I finished the free period with) was one based on good ol’ trusty PHP and the HipChat v2 API. As it turns out I haven’t been using an RSS reader in awhile (thanks Google) but still enjoy reading news. Instead of hitting a bunch of different pages to check and see the latest, I figured I would write a simple bot to collect the data for me and message a room in HipChat with the contents. The project is called NewsToChat and installation was straightforward.

On the HipChat profile page:

  • Create an OAuthAPI token

On the AWS instance:

The basic idea is that there are scripts setup to run in cron, and are mapped to the commands available in NewsToChat.


pullnews

  • uses a few classes to pull from and format the identified news sources
  • makes a basic attempt to de-duplicate what was found
  • uses a database service to store the data

pushnews

  • push one article to the identified chat target
  • marks the article as expired

maintenance

  • perform maintenance on the pool of news articles in the database

For the little experiment I was running, I pushed the first article I gathered into the HipChat room on September 6th, 2014 and the last on December 16th, 2014. In all, a little over sixty thousand news items were gathered, providing more than enough content to publish about every five minutes.

It was extremely simplistic, but could have easily been expanded to behave more like an appropriate chat room bot. For instance, had I spent the time on it, it would have been nice for the bot to support user specific preferences and listen to commands from the chat room.

Shortly after the free period expired, I let it run for awhile to see how much it would cost me. Turns out, it was about 0.47 USD per day. Not bad. Less than the cost of a newspaper. 🙂


Home

About

Portfolio

Web Apps Web Enabled Applications Corporate Sites Personal Sites
Preferences Dark Theme Light Theme Notifications
Social GitHub LinkedIn RSS Feed Icon