← Hacker News

New Comments by Keyword from Hacker News API

Pipedream makes it easy to connect APIs for Hacker News and 900+ other apps remarkably fast.

Trigger workflow on
New Comments by Keyword from the Hacker News API
Next, do this
Connect to 900+ APIs using code and no-code building blocks
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜
Trusted by 250,000+ developers from startups to Fortune 500 companies:
Trusted by 250,000+ developers from startups to Fortune 500 companies

Developers Pipedream

Getting Started

Trigger a workflow on New Comments by Keyword with Hacker News API. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Configure the New Comments by Keyword trigger
    1. Connect your Hacker News account
    2. Configure timer
    3. Optional- Configure Keyword
  2. Add steps to connect to 900+ APIs using code and no-code building blocks
  3. Deploy the workflow
  4. Send a test event to validate your setup
  5. Turn on the trigger

Integrations

Send Message with Discord Webhook API on New Comments by Keyword from Hacker News API
Hacker News + Discord Webhook
 
Try it
Add Multiple Rows with Google Sheets API on New Comments by Keyword from Hacker News API
Hacker News + Google Sheets
 
Try it
Get Film with SWAPI API on New Comments by Keyword from Hacker News API
Hacker News + SWAPI - Star Wars
 
Try it
Create Multiple Records with Airtable API on New Comments by Keyword from Hacker News API
Hacker News + Airtable
 
Try it
Custom Request with HTTP / Webhook API on New Comments by Keyword from Hacker News API
Hacker News + HTTP / Webhook
 
Try it

Details

This is a pre-built, open source component from Pipedream's GitHub repo. The component is developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

New Comments by Keyword on Hacker News
Description:Emit new comments that mention a specific keyword
Version:0.0.3
Key:hacker_news-new-comments-by-keyword

Code

const Parser = require("rss-parser")
const parser = new Parser()

const hacker_news = require('../../hacker_news.app.js')

module.exports = {
  key: "hacker_news-new-comments-by-keyword",
  name: "New Comments by Keyword",
  description: "Emit new comments that mention a specific keyword",
  app: "hacker_news",
  version: "0.0.3",
  props: {
    hacker_news,
    timer: {
      type: "$.interface.timer",
      default: {
        intervalSeconds: 15,
      },
    },
    db: "$.service.db",
    // If you want a single search feed but multiple keywords, separate the keywords with " OR ":
    keyword: {
      type: "string", 
      label: "Keyword",
      description: "Keyword to watch. Matches comments. Leave blank to get all comments.",
      optional: true,
      default: "",
    },
  },
  methods: {
    // in theory if alternate setting title and description or aren't unique this won't work
    itemKey(item) {
      return item.guid || item.id || item.title || item.description
    },
  },
  async run() {
    const seenKeys = this.db.get("seenKeys") || []
    const seenKeysMap = seenKeys.reduce((acc, v) => {
      acc[v] = true
      return acc
    }, {})
    // All elements of an item are optional, however at least one of title or description must be present.
    // should be listed from most recent to least recent
    const feed = await parser.parseURL(`https://hnrss.org/newcomments?q=${encodeURIComponent(this.keyword)}`)
    for (let idx = feed.items.length - 1; idx >= 0; idx--) {
      const item = feed.items[idx]
      const key = this.itemKey(item)
      // XXX throw if !key?
      if (seenKeysMap[key]) continue
      seenKeys.unshift(key)
      seenKeysMap[key] = true // just in case of dupes
      this.$emit(item, {
        id: this.itemKey(item),
        summary: item.title,
        ts: item.pubdate && +new Date(item.pubdate), 
      })
    }
    if (seenKeys.length) {
      // XXX restrict by byte size instead of el size
      this.db.set("seenKeys", seenKeys.slice(0, 1000))
    }
  },
}

Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
Hacker Newshacker_newsappThis component uses the Hacker News app.
timer$.interface.timer
N/Adb$.service.dbThis component uses $.service.db to maintain state between component invocations.
Keywordkeywordstring

Keyword to watch. Matches comments. Leave blank to get all comments.

Authentication

The Hacker News API does not require authentication.

About Hacker News

Social news website

More Ways to Use Hacker News

Triggers

New Stories by Keyword from the Hacker News API

Emit new stories that mention a specific keyword

 
Try it