Hacker News bot with Slack’s Events API and StdLib

Nima Gardideh
Feb 23, 2017 · 4 min read

I’m an avid Hacker News consumer. It’s one of the first places I go in the morning and tend to visit it multiple times a day. It might as well be my default tab (though to be fair, I have something way cooler for that).

Recently, I noticed that YC has an open and official API for Hacker News so I set out to create a Slack bot (as a way to train myself for a product we’re working on).

This all took just a few hours and credit should all go to Slack’s great Events API that makes it so you don’t need to run a bot process at all times and enabled me to use StdLib alongside Botkit and put together a pretty decent experience.

Image for post
Image for post

Functionality

The bot currently supports almost all the public functionality of the API (except for users). Here’s how to use them:

You can get the bot to get you multiple post types all at once by asking for the different post types right in one message!

@hackernewsbot get me jobs and top stories

Image for post
Image for post
Querying multiple post types

The bot cycles through all the commands that it sees and performs all of them and concatenates them in the same order. Since I asked it to get me jobs and top stories, it’s showing the job postings first (since it showed up first in my text) and the top stories afterwards.

You can get the top stories (equivalent of going to the front page of HN).

@hackernewsbot top stories

Image for post
Image for post
Top Stories on Hacker News

It will show you the top stories whenever you say anything that contains the word top.

You can get the latest posts (equivalent of posts in /newest on HN).

@hackernewsbot new stories

Image for post
Image for post
New Stories on Hacker News

It will show you the newest posts whenever you mention anything with the word new in it.

You can get the latest Show HN posts (equivalent of /show on HN).

@hackernewsbot Show HNs

Image for post
Image for post
Show HN stories on Hacker News

It’ll get you the latest Show HNs whenever you mention the word show.

It can show you the latest job postings on HN (equivalent of /jobs on HN)

@hackernewsbot jobs

Image for post
Image for post
Job postings on Hacker News

In the future, I’d like it support fetching posts by specific users (which the API supports) and potentially posting automatic notifications whenever a new post hits the front-page!

If you just want to install it to your Slack group, then go here.

If you want to read the code, here it is.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Hacker Noon is how hackers start their afternoons. We’re a part of the @AMI family. We are now accepting submissions and happy to discuss advertising & sponsorship opportunities.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, don’t take the realities of the world for granted!

Image for post
Image for post

HackerNoon.com

#BlackLivesMatter

Sign up for Get Better Tech Emails via HackerNoon.com

By HackerNoon.com

how hackers start their afternoons. the real shit is on hackernoon.com. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Nima Gardideh

Written by

I help companies grow with art and technology at Pearmill. https://pearmill.com

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Nima Gardideh

Written by

I help companies grow with art and technology at Pearmill. https://pearmill.com

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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