Hacker News Slack Bot

R
Renaudil y a 2 jours
0

Description

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

npx boilerapp hacker-news-slack-bot

文档

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).
<br/>

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.
<picture> <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/28986134/221011048-524226f6-b9aa-4f64-b39e-70267ed8eb37.png"> <source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/28986134/221011121-c6f368b6-cbff-4b67-a0ee-ffc7986d9add.png"> <img alt="Slacker Overview" src="https://user-images.githubusercontent.com/28986134/221011121-c6f368b6-cbff-4b67-a0ee-ffc7986d9add.png"> </picture>

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:

<a href="https://slack.com/oauth/v2/authorize?scope=chat:write,chat:write.public,links:read,links:write,commands,team:read&client_id=12364000946.3845028209600"><img alt="Add to Slack" height="40" width="139" src="https://platform.slack-edge.com/img/add_to_slack@2x.png" /></a>

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

<br/>

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\

Prix

Gratuit

FREE

评论 (0)

常见问题

常见问题解答 (FAQ)

有问题?我们有答案。如果您找不到想要的答案,请随时联络我们。

Boilerapp 是一个专门用于分享 Boilerplates、入门套件(Starter Kits)和项目模版的开发者社区平台。我们的目标很简单:为您节省初始配置(Setup)的时间,让您可以专注于真正重要的代码。无论您是在寻找简单的代码库还是完整的 SaaS 项目,都能在这里找到。

还有其他问题?

我们的团队随时为您提供帮助。联络我们,我们将尽快回复。

Hacker News Slack Bot | BoilerApp