A bot that notifies you on Slack whenever your company/product is mentioned on Hacker News. Powered by Vercel Functions & Upstash.

Overview
Banner

Hacker News Slack Bot

A bot that notifies you on Slack whenever your company/product is mentioned on Hacker News.

Demo
Add to Slack

or deploy your own


Built With

  1. Vercel Functions for cron processes & event subscriptions via webhooks
  2. Hacker News API for pulling data
  3. Slack API for sending and unfurling messages
  4. Upstash for key-value storage (Redis) and cron scheduling (qStash).

How It Works

  1. Set up a cron schedule in Upstash (qStash) that pings our /api/cron endpoint once every 60 seconds.
  2. Get the last checked HN post ID (lastCheckedId) and the list of keywords to check against from Upstash.
  3. Get the latestPostId using HN API's maxitem endpoint. Then, perform checks against each post between lastCheckedId and latestPostId to see if they contain any of the delineated keywords.
  4. For each positive post, send its link to Slack using the chat.postMessage method.
  5. Listen to the link_shared event at our /api/event endpoint. Once an event occurs, send a POST request to Slack to unfurl the link using the chat.unfurl method.
Hacker News Slack Bot Overview

One-Click Install

Here's a 90s video that walks you through the installation process, step-by-step.

You can click the button below to install the bot directly into your desired Slack workspace:

Add to Slack

Once it's installed, create a channel to receive notifications in and start configuring the bot with the /configure command.


Deploy Your Own

You can also deploy your own version of this bot using Vercel and Upstash. Note that while this is in early-access, some of these processes might change.

Prefer a video tutorial instead? Watch this video.

Step 1: Create Slack App + Secure Env Vars

  1. Navigate to api.slack.com/apps and click on "Create New App".
  2. Select "From scratch" and input Hacker News Bot as the name of your app.
  3. Voilà! You've just created your Slack app. Here, you'll receive 3 values that will be used for your Vercel deployment in the next step:
    • Client ID: This is your App's unique public-facing ID that will be the value for the NEXT_PUBLIC_SLACK_CLIENT_ID env var.
    • Signing Secret: This is the signing secret used to validate that requests are genuinely coming from Slack. It will be the value for the SLACK_SIGNING_SECRET env var.
    • Verification Token: This is the verification token used to validate that requests are genuinely coming from Slack. It will be the value for the SLACK_VERIFICATION_TOKEN env var.

CleanShot 2022-07-25 at 02 16 31

Step 2: Create Upstash Account

Go to console.upstash.com and create an account. You'll need it for the next step.

Afterwards copy the QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY secrets from console.upstash.com/qstash. You'll need them in the next step.

Similar to the slack signing secret, these are used to verify the authenticity of scheduled requests coming from Upstash.

Step 3: Deploy to Vercel

You can deploy your bot to Vercel with one-click:

Deploy with Vercel

Be sure to include all 5 of the env vars above in your deployment.

When the project finishes deploying, get your project's domain (e.g. https://hacker-news-slack-bot-eight.vercel.app/). You'll need it for the next step.

Step 4: Configuring Slack app

For your Slack app to be able to send/unfurl messages in your Slack workspace, we will need to configure a few things:

Step 4A: Configuring OAuth Scopes

  1. From your Slack app home screen, select "OAuth & Permissions" from the sidebar (under "Features").

  2. Scroll down to "Scopes", and add the following scopes under "Bot Token Scopes":

    • chat:write
    • chat:write.public
    • links:read
    • links:write

    CleanShot 2022-07-25 at 13 49 18

Step 4B: Configuring Event Subscriptions

  1. Now, select "Event Subscriptions" from the sidebar (under "Features").
  2. Toggle "Enable Events" to "ON".
  3. For the "Request URL" field, input your Vercel project's domain and append /api/event to it. The final URL should look something like https://hacker-news-slack-bot-eight.vercel.app/api/event.
  4. Scroll down to "Subscribe to bot events". Add the link_shared bot user event.
  5. Do the same for `Subscribe to events on behalf of users". Slack app configurations (1)
  6. Under "App unfurl domains", add news.ycombinator.com. Slack app configurations
  7. Click on "Save Changes".

Step 4C: Configure Slash Commands

Select "Slash Commands" from the sidebar (under "Features"). Create the following commmand with its respective Request URLs (based on your Vercel project's domain):

  • Command: /configure
  • Request URL: https://[YOUR_VERCEL_PROJECT_DOMAIN]/api/cmd/configure
  • Short Description: Configure your HN Slack Bot

Step 4D: Enable Interactivity

  1. Now, select "Interactivity & Shortcuts" from the sidebar (under "Features").
  2. Toggle "Interactivity" to "ON".
  3. For the "Request URL" field, input your Vercel project's domain and append /api/response to it. The final URL should look something like https://hacker-news-slack-bot-eight.vercel.app/api/response.
  4. Click on "Save Changes".

Step 4E: Install App to Slack Workspace + Get OAuth token

  1. Go to "Basic Information" (under "Settings").
  2. Under "Install your app", click on "Install to Workspace".
  3. You should receive a notification that your app has been installed in your Slack workspace.
  4. Go back to "OAuth & Permissions". Copy the value of "Bot User OAuth Token". CleanShot 2022-07-25 at 18 28 46
  5. Set it as the SLACK_OAUTH_TOKEN env var in your Vercel project. Here's a guide on how to do that. Add env var
  6. Redeploy your Vercel project for the changes to take effect.
  7. To verify that this worked, go to any channel on your Slack workspace and send a Hacker News link. The link should now unfurl and show a nice preview (like the one above).

Step 5: Set Up Cron Processes in qStash

  1. Go to console.upstash.com/qstash and scroll down to the Request Builder.
  2. Configure the endpoint URL as https://[YOUR_VERCEL_PROJECT_DOMAIN]/api/cron.
  3. Select the type as Scheduled.
  4. Configure the cron schedule as * * * * * (select the "day" dropdown and change it to "minute").
  5. Click on Schedule.
  6. Go back to Slack and use the /configure slash command that you set up earlier to add keyewords to track + set the channel to receive notifications in.
  7. You should now start receiving notifications whenever your keywords are mentioned on Hacker News.

Authors

This project was originally created by Steven Tey at Vercel, with contributions/feedback from:


License

The MIT License.


Comments
  • Include HN title in previews

    Include HN title in previews

    I think it'd be useful to include the HN title in place of the "Hacker News" text at the bottom. The additional context would help, for instance, to know that the comment is discussion a hot article (which is getting a lot of comments), or if it's a new post. Screen Shot 2022-07-22 at 9 31 03 PM

    opened by jridgewell 2
  • Refactor Redis to improve scale

    Refactor Redis to improve scale

    This PR is gonna help us scale incredibly well – in the past we were storing team’s keywords as key-set pairs in Redis, and we end up doing one request per team per cron (O(n)).

    With this PR we’re storing all the team keywords as a hash, and we’ll only do one request per cron (O(1)).

    We also refactor to use https://github.com/upstash/upstash-redis in this PR.

    opened by steven-tey 1
  • Improved Onboarding UX Flow

    Improved Onboarding UX Flow

    1. Created a new UX for new user onboarding: CleanShot 2022-07-29 at 15 10 28
    2. Consolidated commands: deprecated /list, /track, /untrack, /channel and consolidated all of them into /configure.
    3. Created new endpoint for interactive messages on Slack: /api/response – this listens to any user interaction with our Bot Configuration message above and returns the appropriate response.
    4. Implemented pipelining for certain Upstash requests as per @chronark's suggestion
    opened by steven-tey 1
  • Use block kit instead of two step flow?

    Use block kit instead of two step flow?

    IIUC the main reason to do a two step flow (post link and then unfurl) is so the link gets displayed "nicely" in slack.

    Wouldn't using block kit (https://api.slack.com/block-kit) allow making a single postMessage call and style the Slack message in a same way?

    That would simplify things quite a bit.

    opened by marcosnils 0
  • Step 4E redeploy not working

    Step 4E redeploy not working

    Has anyone else had this issue? I also tried to trigger a redeploy by making changes in the repo and it's not happening. A temporary issue with Vercel maybe?

    image

    opened by pguardiario 0
  • Stub out code for case sensitive matching

    Stub out code for case sensitive matching

    We store 2 mappings now, one with case-sensitive keywords and one with insensitive keywords. When matching in regex, we perform it insensitively, and lookup both mappings to see which teams we should be notifying.

    opened by jridgewell 1
  • Reddit Support

    Reddit Support

    I've gotten a bunch of requests for Reddit support and I'm brainstorming how this would work.

    I'm thinking of using something that streams comments from Reddit, something like https://github.com/rockets/demo but an NPM module.

    Thoughts?

    PRs welcome too! :)

    enhancement help wanted 
    opened by steven-tey 5
  • Use `Regexp.exec` instead of `replace` for side-effects

    Use `Regexp.exec` instead of `replace` for side-effects

    This replaces the String.p.replace uses that are only used for side-effects with a faster RegExp.p.exec loop. This avoids the string allocation of the output string, and makes it a little more clear the loop is used for side-effects.

    opened by jridgewell 2
Owner
Vercel Labs
Develop. Preview. Ship. Creators of Next.js.
Vercel Labs
A fast, robust and extensible distributed task/job queue for Node.js, powered by Redis.

Conveyor MQ A fast, robust and extensible distributed task/job queue for Node.js, powered by Redis. Introduction Conveyor MQ is a general purpose, dis

Conveyor MQ 45 Dec 15, 2022
Out of the box modern User Interface, so you can see and manage your Workhorse jobs in realtime

WORKHORSE UI Out of the box modern User Interface, so you can see and manage your Workhorse jobs in realtime. Start local Run npm i Copy and name prox

Workhorse 2 Apr 15, 2022
generate statistics on the number of audience minutes your site is generating, and if readers make it to the end of your screeds

audience-minutes generate statistics on the number of audience minutes your site is receiving, and if readers make it to the end of your screeds. “If

bert hubert 35 Dec 28, 2022
This project demonstrates how you can use the multi-model capabilities of Redis to create a real-time stock watchlist application.

Introduction This project demonstrates how you can use Redis Stack to create a real-time stock watchlist application. It uses several different featur

Redis Developer 43 Jan 2, 2023
Cloud Run Jobs Demos - A collection of samples to show you how and when to run a container to completion without a server

Cloud Run Jobs Demo Applications Cloud Run Jobs allows you to run a container to completion without a server. This repository contains a collection of

Google Cloud Platform 34 Dec 23, 2022
TypeScript Data Structures that you need!

TSDS TypeScript Data Structures that you need! Doc Website Introduction A data structure is a way to store and organize data in order to facilitate ac

Ehsan Samavati 25 Dec 8, 2022
Cloudflare Worker that will allow you to progressively migrate files from an S3-compatible object store to Cloudflare R2.

A Cloudflare Worker for Progressive S3 to R2 Blog Post: https://kian.org.uk/progressive-s3-to-cloudflare-r2-migration-using-workers/ This is a Cloudfl

Kian 29 Dec 30, 2022
Build and deploy a roadmap voting app for your porject

Roadmap Voting App You can deploy Roadmap application yourself and get feedback from your users about your roadmap features. See the live example. In

Upstash 91 Jan 3, 2023
Making service workers easy so that your app is fast and reliable, even offline.

tulo.js Making service workers easy to use so that your app can be fast and reliable, even offline. Welcome to tulo.js, a service worker library that

OSLabs Beta 37 Nov 16, 2022
⚡️ Supercharge your ViewComponent development process 🚀

L ?? kbook ⚡️ Supercharge your ViewComponent development process ?? About Lookbook provides a ready-to-go UI for navigating, inspecting and interactin

Mark Perkins 466 Dec 26, 2022
Use Cloudflare Workers Cron Triggers to keep your Hetzner Cloud Firewall allowing the latest list of Cloudflare IPs, or any other lists!

Hetzner Cloud Firewall automation with Cloudflare Workers Heavily inspired by xopez/Hetzner-Cloud-Firewall-API-examples, this repository holds a Cloud

Erisa A 9 Dec 17, 2022
Build your Cloudflare Workers with esbuild.

build-worker Bundle your Cloudflare Worker with esbuild instead of webpack. (It's ridiculously faster!) Wrangler v1 uses webpack. Wrangler v2 is using

Rom 7 Oct 24, 2022
A Remix.run stack to monitor your BullMQ queues

Remix Matador stack A bold interface that helps you monitor your BullMQ queues. Learn more about Remix Stacks. $ npx create-remix@latest --template nu

Andrea 19 Dec 15, 2022
Adds clap button (like medium) to any page for your Next.js apps.

@upstash/claps Add a claps button (like medium) to any page for your Next.js apps. Nothing to maintain, it is completely serverless ?? Check out the d

Upstash 49 Nov 23, 2022
Hacker-news-with-react - 👾 Consuming the hacker news api, i created a more modern design for than the current site.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

João Thomaz 1 Jan 3, 2022
NewsStation is a news app which can be used to grab daily news bites. If you are interested in news whether politics, business, entertainment, general, health, science, sports and technology news NewsStation is for you!

This is a NewsStation WebApp Project Using News API NewsStation is a news app which can be used to grab daily news bites. If you are interested in new

Ravi Chauhan 2 Feb 7, 2022
An open-source link shortener built with Vercel Edge Functions and Upstash Redis.

Dub An open-source link shortener built with Vercel Edge Functions and Upstash Redis. Introduction · Deploy Your Own · Contributing Introduction Dub i

Steven Tey 4.9k Jan 5, 2023
Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Twitter.

news.ycombinator1.com Lets you add a character to Hacker News links to add social media and OpenGraph previews for sharing on things like Slack or Dis

Ian Langworth ☠ 38 Sep 18, 2022
If you are a Slack browser user, this userscript will allow you to auto-redirect without Slack asking if you want to open on the desktop app.

Auto-redirect for browser Slack users If you are a Slack browser user, this userscript will allow you to auto-redirect without Slack asking if you wan

Felipe Santos (he/him) 6 Aug 23, 2022
An example implementation of the slack-gpt starter which ingests confluence pages to create a helpful slack bot

Slack-GPT (HR bot example implementation) Table of Contents Introduction Prerequisites Creating and installing the application Configuration Starting

Martin Hunt 17 Jul 31, 2023