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.
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 { searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
5const query = "\"val town\" OR \"val.town\"";
6const discordWebhookUrl = Deno.env.get("mentionsDiscord");
7const serpApiKey = Deno.env.get("SERP_API_KEY");
8
9export async function redditAlert({ lastRunAt }: Interval) {
10 if (!serpApiKey || !discordWebhookUrl) {
11 console.error("Missing SERP_API_KEY or Discord webhook URL. Exiting.");
12 return;
13 }
14
15 // Calculate the `as_qdr` parameter (https://serpapi.com/advanced-google-query-parameters#api-parameters-advanced-search-query-parameters-as-qdr) or default to 7 days
16 const asQdr = lastRunAt
17 ? `d${Math.floor((Date.now() - lastRunAt.getTime()) / (24 * 60 * 60 * 1000))}`
19
20 try {
21 const response = await searchWithSerpApi({
22 query,
23 site: "reddit.com",
24 apiKey: serpApiKey,
25 as_qdr: asQdr,
26 });
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.