72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.
1import { SearchResult, searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
5const KEYWORDS = ["node"];
6const EXCLUDES = "";
7const DISCORD_API_KEY = Deno.env.get("mentionsDiscord");
8const SERP_API_KEY = Deno.env.get("SERP_API_KEY");
9
10export default async function redditTestAlert({ lastRunAt }: Interval) {
19 );
20
21 // Perform searches using SERP API on reddit.com
22 const results = await Promise.all(
23 searchQueries.map((query) =>
24 searchWithSerpApi({
25 query,
26 site: "reddit.com",
27 apiKey: SERP_API_KEY,
28 })
29 ),
49 try {
50 await discordWebhook({
51 url: DISCORD_API_KEY, // Make sure this is set in your environment variables
52 content: `${message}`,
53 });
72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.
1import { SearchResult, searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
5const KEYWORDS = ["node"];
6const EXCLUDES = "";
7const DISCORD_API_KEY = Deno.env.get("mentionsDiscord");
8const SERP_API_KEY = Deno.env.get("SERP_API_KEY");
9
10export default async function redditAlert({ lastRunAt }: Interval) {
19 );
20
21 // Perform searches using SERP API on reddit.com
22 const results = await Promise.all(
23 searchQueries.map((query) =>
24 searchWithSerpApi({
25 query,
26 site: "reddit.com",
27 apiKey: SERP_API_KEY,
28 })
29 ),
49 try {
50 await discordWebhook({
51 url: DISCORD_API_KEY, // Make sure this is set in your environment variables
52 content: `${message}`,
53 });
72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.
1import { SearchResult, searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
6const DAYS_BACK = 1;
7const EXCLUDES = "";
8const DISCORD_API_KEY = Deno.env.get("mentionsDiscord");
9const SERP_API_KEY = Deno.env.get("SERP_API_KEY");
10
11export default async function redditAlert() {
13 const searchQueries = KEYWORDS.map((k) => `"${k}" ${EXCLUDES}`);
14
15 // Perform searches using SERP API on reddit.com
16 const results = await Promise.all(
17 searchQueries.map((query) =>
18 searchWithSerpApi({
19 query,
20 site: "reddit.com",
21 daysBack: DAYS_BACK,
22 apiKey: SERP_API_KEY,
23 })
24 ),
44 try {
45 await discordWebhook({
46 url: DISCORD_API_KEY, // Make sure this is set in your environment variables
47 content: `${message}`,
48 });
72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.
1import { SearchResult, searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
5const KEYWORDS = ["taylor swift"];
6const EXCLUDES = "";
7const DISCORD_API_KEY = Deno.env.get("mentionsDiscord");
8const SERP_API_KEY = Deno.env.get("SERP_API_KEY");
9
10export default async function redditAlert({ lastRunAt }: Interval) {
19 );
20
21 // Perform searches using SERP API on reddit.com
22 const results = await Promise.all(
23 searchQueries.map((query) =>
24 searchWithSerpApi({
25 query,
26 site: "reddit.com",
27 apiKey: SERP_API_KEY,
28 })
29 ),
49 try {
50 await discordWebhook({
51 url: DISCORD_API_KEY, // Make sure this is set in your environment variables
52 content: `${message}`,
53 });
72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.
31Refer to [Twitter's search operators](https://socialdata.gitbook.io/docs/twitter-tweets/retrieve-search-results-by-keyword#endpoint-parameters) to fine-tune your query.
32
33### 4. Test API call
34Set `isProd = false` in the code if you are testing, to ensure there are enough tweets to display. <br>
35Toggle it back to `true` when you're ready to run this cron job in production and actuall send notifications.
60
61### NOTE: Usage Limits
62This val uses the SocialData API for Twitter data:
63
64- **Proxies via Val Town's [SocialDataProxy](https://www.val.town/v/stevekrouse/socialDataProxy)**: Limited to 10 cents per day for [**Val Town Pro users**](https://www.val.town/pricing). This API is *only* for Pro users.
65- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.