• Stars
    star
    341
  • Rank 123,998 (Top 3 %)
  • Language
    TypeScript
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Slacker

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. Vercel Cron Jobs for triggering cron processes.
  3. Hacker News API for pulling data
  4. Slack API for sending and unfurling messages
  5. Upstash for key-value storage (Redis).

How It Works

  1. Set up a Vercel cron job 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.
Slacker Overview

One-Click Install

Here's a 60s 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.

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://slacker-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://slacker-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://slacker-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).

Authors

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


License

The MIT License.


More Repositories

1

gemini-chatbot

Build your own generative UI chatbot using the Vercel AI SDK and Google Gemini
TypeScript
673
star
2

next-fetch

Intuitive data fetching for Next.js
TypeScript
593
star
3

react-on-the-edge

Server-rendered React using Vercel Edge Functions.
TypeScript
219
star
4

app-router-auth

Auth patterns using Next.js App Router
TypeScript
212
star
5

function-database-latency

Visualize the latency of databases from Vercel Functions.
JavaScript
171
star
6

semantic-image-search

Semantic Image Search with Vercel AI SDK
TypeScript
118
star
7

ai-sdk-preview-rag

TypeScript
110
star
8

ai-sdk-preview-rsc-genui

Generative UI with React Server Components and Vercel AI SDK
TypeScript
101
star
9

rsc-llm-on-the-edge

TypeScript
100
star
10

remix-on-the-edge

Remix running on Vercel Edge Functions
TypeScript
82
star
11

ai-sdk-preview-use-object

TypeScript
35
star
12

ai-sdk-preview-multi-steps

TypeScript
29
star
13

ai-sdk-preview-attachments

TypeScript
27
star
14

next-on-the-edge

TypeScript
21
star
15

remix-platforms

Multi-tenant Remix application (multiple custom domains with a single codebase)
CSS
13
star
16

ai-sdk-flags-edge-config

Example project showing how you can use Edge Config and Feature Flags with the Vercel AI SDK
TypeScript
12
star
17

blue-green

TypeScript
12
star
18

ai-sdk-preview-array-output-mode

TypeScript
10
star
19

react-spa

A React SPA with Express
JavaScript
7
star
20

next-spa-drizzle

https://next-spa-drizzle.vercel.app/
TypeScript
3
star
21

vercel-nav-demo

v0 + Shadcn UI version
TypeScript
3
star
22

ai-sdk-deployment-guide

TypeScript
3
star
23

without-react-tweet-iframes

TypeScript
2
star