Blog / Finding Leads on Reddit and Using ChatGPT to Score Them

Finding Leads on Reddit and Using ChatGPT to Score Them

From the archive. This post was originally published in May 2024, and the screenshots come from InfoLobby v1. The interface has been refreshed since then, but the building blocks and the process are very close to what you see here, so you can still follow along step by step.

The Reddit Hits table in InfoLobby showing scraped Reddit posts with a sentiment score, subreddit, searcher and post URL

They say Reddit is a gold mine of sales prospects, but who has time to read every post? That would take a team of people. Why not automate this? In this post we build automations to search Reddit for new posts matching keywords, and then use ChatGPT to score the probability that the post is indeed a viable prospect.

What we want to achieve here (and we'll show you how), is:

  • Automatically search Reddit for potential posts where you can plug your product or service
  • Have ChatGPT give a sentiment analysis as to how likely the user posting is looking for what you offer
  • Have ChatGPT create a comment that you can copy and paste and use as a starting point for posting your reply comment on Reddit

Just these steps alone should save you hundreds of man hours.

Setup Assets

Before getting into this, there are 2 integrations you need to set up in your InfoLobby account:

Reddit API Key

Set it up in Reddit at https://www.reddit.com/prefs/apps

Then add it as an oAuth2 API integration in InfoLobby:

The oAuth2 API integration configuration in InfoLobby for the Reddit API

OpenAI API Key

Get an API key at https://platform.openai.com/api-keys

Then set it up as Bearer Token API in InfoLobby:

The Bearer Token API integration configuration in InfoLobby for the OpenAI API

We're also going to need 2 tables to get us started:

  • A table for keyword lists that we're interested in
  • A table for hits that the flow finds in Reddit

Searchers Table

The Searchers table listing three searchers with their Reddit query, status and likelihood criteria

The Searchers table has the following fields:

  • Subject: the title of the searcher for easy reference
  • Query: the search query as expected by Reddit (see this link for modifiers Reddit offers)
  • Status: simple category with "Active" and "Inactive" so we can turn individual searchers on and off
  • After Date: used by the flow to store the last scan date so we don't do double work and overuse our OpenAI credits
  • Likelihood that this person is ...: will become part of what we ask ChatGPT, eg "looking for a CRM solution"

Reddit Hits Table

The Reddit Hits table showing eight scraped posts with sentiment scores, subreddits and links back to Reddit

The Reddit Hits table has the following fields:

  • Title: title of the Reddit post
  • Actioned: simple category field so we can keep track of which ones we've replied to or decided to ignore
  • Sentiment: a simple calculation that color codes the GPT score
  • SubReddit: the Sub-Reddit the post was found in
  • Searcher: lookup to our Searchers table to link to the Searcher that found the hit
  • URL: URL of the Reddit post so we can look at it
  • Post Body: text content of the post (textarea field)
  • Potential Reply: we may as well get ChatGPT to provide us with a starting point for a reply
  • Created: date and time the post was made
  • GPT Score: score that ChatGPT gives the post regarding the "Likelihood that this person is ..." criteria
  • Reddit ID: a compound ID we'll give each hit to prevent duplicates

Searching Reddit

The main Reddit searching flow will be in the Searchers table.

First, we're going to ask the Reddit API for all search results for our given query.

A flow brick calling the Reddit search API with the query from the current record

Then we're going to take just the hits array, and loop through the individual posts.

A flow brick looping over the array of Reddit search results

Next, we're going to look at the post's created date and only continue if it was created after the last logged "After" date.

A flow condition that continues only when the post creation date is after the stored After Date

Next, we're going to calculate a composite ID for the post, search our Reddit Hits table, and only continue if no results were found, thus prevent duplication.

Flow bricks calculating a composite Reddit ID and searching the Reddit Hits table for an existing match

If we got this far, it means we need to save the hit to the table. Next we extract the remaining required field values to make a record.

Flow bricks extracting the title, subreddit, url, created date and post body from the Reddit result

Then, we'll create the record, and trigger the ChatGPT flow on it (coming up next).

A Create New Record brick mapping the extracted variables onto Reddit Hits fields, followed by a Trigger Automation brick

At the very end of the flow, we'll update the searcher with yesterday's date so that future checks won't extend too far into the past.

A flow brick updating the searcher record's After Date to yesterday

Scoring with ChatGPT

The flow to get ChatGPT's sentiment on each post will be in the Reddit Hits table because that's where the individual posts are stored.

To prompt GPT correctly, we'll need to collect a fair amount of information.

Firstly, we'll just have a piece of text that describes what we're selling. Naturally you'll need to adjust this to your own products or services.

A Calculate Variable brick holding a multi-line description of the product being sold

Then we set the system message.

A flow brick setting the system message for the ChatGPT request

We'll also initialize some variables. They'll be overwritten later.

Flow bricks initializing the score and related variables to default values

Next, we'll loop over the parent Searcher record to get some field values, and construct the actual message we want to feed ChatGPT.

A flow loop over the linked Searcher record building the user message from the post body and likelihood criteria

Now we're ready to ask GPT to give us a score on the message.

An API request brick posting the system and user messages to the OpenAI chat completions endpoint

Because of our prompting, ChatGPT should only reply with a percentage. So we're expecting things like "95%", but we want to convert that to just a number.

A Calculate Variable brick stripping the percent sign and converting the reply into a number

If the score is high enough, we'll want GPT to create a potential comment that we can use as a starting block. So we initialize the comment variable, and only continue if the score is higher than 75. There's no point on wasting OpenAI API credits if GPT already determined the poster is likely not looking for what you have to offer.

A flow condition that only continues when the GPT score is greater than 75

Now we'll set a NEW system message because it's a different type of task for GPT.

A flow brick setting a second system message for the comment writing task

And then we'll construct the message to include. Note this variable includes the "about" variable we created in the beginning that describes our product.

A Calculate Variable brick building the comment prompt from the post body and the about variable

Now we're ready to ask ChatGPT again to create a potential comment that we can post.

A second API request brick asking OpenAI to draft a reply comment

And we'll extract the comment body from the JSON payload that we got back.

A Calculate Variable brick pulling the comment text out of the OpenAI JSON response

Lastly, at the very end of the flow, whether or not GPT created a comment, we'll update the Reddit Hits record with the derived score and the comment (if one was asked for).

An Update Record brick writing the GPT Score and Potential Reply back onto the Reddit Hits record

Running this Setup

Make sure that you're following the Reddit Hits table so that you get notifications when new hits are added.

Then, in the Searchers table, you can create a simple flow to trigger every day at a specific time, and process all searchers.

A scheduled flow that runs daily and processes every active searcher record

Closing Thoughts

You now have the automations to regularly search Reddit for new posts matching your search criteria, and having ChatGPT score them and possibly create a comment that you could post.

You might be tempted to have the flow also post the comment in Reddit automatically. We would discourage this. The last thing you want is for your Reddit user to get banned (or worse, shadow banned).

You should always check what any AI thinks and says, and have human user intervention for interacting with the outside world.