From a6a8eab622fda49df671cc8f4f3016bd251fb20a Mon Sep 17 00:00:00 2001 From: Shannon Feng Date: Thu, 18 Jun 2026 15:44:04 -0500 Subject: [PATCH 1/2] initial commit --- docs/capabilities/server/global-triggers.mdx | 6 ++ sidebars.ts | 19 +++- .../capabilities/server/global-triggers.mdx | 99 +++++++++++++++++++ .../capabilities/server/triggers.mdx | 1 + versioned_sidebars/version-0.13-sidebars.json | 16 ++- 5 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 docs/capabilities/server/global-triggers.mdx create mode 100644 versioned_docs/version-0.13/capabilities/server/global-triggers.mdx diff --git a/docs/capabilities/server/global-triggers.mdx b/docs/capabilities/server/global-triggers.mdx new file mode 100644 index 00000000..960a3af1 --- /dev/null +++ b/docs/capabilities/server/global-triggers.mdx @@ -0,0 +1,6 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Global Triggers + +Triggers allow your app to automatically respond to specific events or actions within a Reddit community. Use triggers to build automation, moderation, and engagement features that react to user or moderator activity. diff --git a/sidebars.ts b/sidebars.ts index c7120e57..4cc5aed5 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -157,7 +157,24 @@ const sidebars: SidebarsConfig = { { type: "category", label: "Automation & Triggers", - items: ["capabilities/server/scheduler", "capabilities/server/triggers"], + items: [ + "capabilities/server/scheduler", + { + type: "category", + label: "Triggers", + link: { + type: "doc", + id: "capabilities/server/triggers", + }, + items: [ + { + type: "doc", + id: "capabilities/server/global-triggers", + label: "Global Triggers", + }, + ], + }, + ], }, { type: "doc", diff --git a/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx b/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx new file mode 100644 index 00000000..5a305192 --- /dev/null +++ b/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx @@ -0,0 +1,99 @@ +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Global Triggers + +Global triggers are events that occur on Reddit that can invoke the app. +Unlike other triggers, the events do not need to occur in the subreddit where the app is installed to invoke the app. + +Currently, the only supported global trigger is: + +* `onMentionInCommentCreate` + +## Example usage + +Apps can respond to global trigger events just like any other trigger event. In `devvit.json`, declare the trigger and its corresponding endpoint: + + +```json +"triggers": { + "onMentionInCommentCreate": "/internal/triggers/on-mention-in-comment-create" +} +``` + +Then handle the global trigger event in your server logic: + + + + +```tsx title="server/index.ts" +import { + type OnMentionInCommentCreateRequest, + type TriggerResponse, +} from '@devvit/web/shared'; + +triggers.post('/on-mention-in-comment-create', async (c) => { + console.log('Handle event for on-mention-in-comment-create!'); + const input = await c.req.json(); + const comment = input.comment; + console.log('Comment ID: ', comment?.id); + return c.json({ status: 'ok' }); +}); +``` + + + + +```tsx title="server/index.ts" +import type { OnMentionInCommentCreateRequest } from '@devvit/web/shared'; + +const router = express.Router(); + +// .. + +router.post( + "/internal/on-mention-in-comment-create", + async (req, res) => { + console.log(`Handle event for on-mention-in-comment-create!`); + const commentId = req.body.comment.id; + console.log("Comment ID:", commentId); + res.status(200).json({ status: "ok" }); +}); + +``` + + + + + +## Playtesting global triggers + +When your app is in development, you may playtest global trigger events, but only using events that occur within the playtest subreddit. + +## Responding to global trigger events + +In order for your app to respond to global trigger events across Reddit, your app must meet the following criteria: + +* App version must be published and approved +* App version must be installed to the app's profile subreddit + + +## Profile subreddit installations + +Certain app versions are eligible to be installed to the app's profile subreddit. + +To be eligible for profile installation, the app version must be approved and make use of at least one global trigger event. + +Eligible app versions will appear under the "Profile installation" section on the App's settings page at https://developers.reddit.com/apps/your-app-slug + +## Restrictions +Apps may not receive global trigger events under these circumstances: +* The event originates from a subreddit where the app is banned +* The event does not pass safety checks (eg, contains illegal content). Events may contain NSFW content. diff --git a/versioned_docs/version-0.13/capabilities/server/triggers.mdx b/versioned_docs/version-0.13/capabilities/server/triggers.mdx index 17255ff4..07fbf4f6 100644 --- a/versioned_docs/version-0.13/capabilities/server/triggers.mdx +++ b/versioned_docs/version-0.13/capabilities/server/triggers.mdx @@ -32,6 +32,7 @@ Event triggers let your app automatically respond to a user's or moderator's act - `onModMail` - `onAutomoderatorFilterPost` - `onAutomoderatorFilterComment` +- `onMentionInCommentCreate` A full list of events and their payloads can be found in the [EventTypes documentation](../../api/public-api/@devvit/namespaces/EventTypes/). For more details on Mod specific actions, see [ModActions](../../api/redditapi/models/interfaces/ModAction) and [ModMail](../../api/public-api/type-aliases/ModMailDefinition). diff --git a/versioned_sidebars/version-0.13-sidebars.json b/versioned_sidebars/version-0.13-sidebars.json index c8ac6cf7..8da6ce1a 100644 --- a/versioned_sidebars/version-0.13-sidebars.json +++ b/versioned_sidebars/version-0.13-sidebars.json @@ -147,7 +147,21 @@ "label": "Automation & Triggers", "items": [ "capabilities/server/scheduler", - "capabilities/server/triggers" + { + "type": "category", + "label": "Triggers", + "link": { + "type": "doc", + "id": "capabilities/server/triggers" + }, + "items": [ + { + "type": "doc", + "id": "capabilities/server/global-triggers", + "label": "Global Triggers" + } + ] + } ] }, { From 53298f1722769aa1ba85647f180feedba4b57a56 Mon Sep 17 00:00:00 2001 From: Shannon Feng Date: Thu, 18 Jun 2026 15:48:18 -0500 Subject: [PATCH 2/2] clean-up --- docs/capabilities/server/global-triggers.mdx | 94 ++++++++++++++++++- .../capabilities/server/global-triggers.mdx | 69 +++++++------- 2 files changed, 127 insertions(+), 36 deletions(-) diff --git a/docs/capabilities/server/global-triggers.mdx b/docs/capabilities/server/global-triggers.mdx index 960a3af1..1841611c 100644 --- a/docs/capabilities/server/global-triggers.mdx +++ b/docs/capabilities/server/global-triggers.mdx @@ -3,4 +3,96 @@ import TabItem from "@theme/TabItem"; # Global Triggers -Triggers allow your app to automatically respond to specific events or actions within a Reddit community. Use triggers to build automation, moderation, and engagement features that react to user or moderator activity. +Global triggers let your app respond to Reddit events even when those events happen outside the subreddit where your app is installed. + +Currently, Devvit supports one global trigger: + +- `onMentionInCommentCreate` + +## Example usage + +Configure a global trigger the same way you configure other trigger events: declare the event in `devvit.json`, map it to an internal endpoint, then handle requests at that endpoint. + +```json +"triggers": { + "onMentionInCommentCreate": "/internal/triggers/on-mention-in-comment-create" +} +``` + +Then handle the global trigger event in your server: + + + + +```tsx title="server/index.ts" +import type { + OnMentionInCommentCreateRequest, + TriggerResponse, +} from '@devvit/web/shared'; + +app.post('/internal/triggers/on-mention-in-comment-create', async (c) => { + console.log('Handle event for on-mention-in-comment-create!'); + const input = await c.req.json(); + const commentId = input.comment?.id; + console.log('Comment ID:', commentId); + return c.json({ status: 'ok' }); +}); +``` + + + + +```tsx title="server/index.ts" +import type { + OnMentionInCommentCreateRequest, + TriggerResponse, +} from '@devvit/web/shared'; + +const router = express.Router(); + +// .. + +router.post( + "/internal/triggers/on-mention-in-comment-create", + async (req, res) => { + console.log("Handle event for on-mention-in-comment-create!"); + const commentId = req.body.comment?.id; + console.log("Comment ID:", commentId); + res.status(200).json({ status: "ok" }); + } +); +``` + + + + +## Playtesting global triggers + +During development, you can playtest global trigger events only when the triggering event occurs in the playtest subreddit. Events from other subreddits do not invoke your app while you are playtesting. + +## Responding to global trigger events across Reddit + +To receive global trigger events across Reddit, your app version must: + +- Be published and approved. +- Be installed to the app's profile subreddit. + +## Profile subreddit installations + +Some app versions can be installed to the app's profile subreddit. An app version is eligible when it has been approved and uses at least one global trigger event. + +Eligible app versions appear in the **Profile installation** section of your app's settings page at [developers.reddit.com/apps/your-app-slug](https://developers.reddit.com/apps/your-app-slug). + +## Restrictions + +Apps do not receive global trigger events when: + +- The event originates from a subreddit where the app is banned. +- The event does not pass safety checks, such as checks for illegal content. Events may contain NSFW content. diff --git a/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx b/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx index 5a305192..1841611c 100644 --- a/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx +++ b/versioned_docs/version-0.13/capabilities/server/global-triggers.mdx @@ -3,17 +3,15 @@ import TabItem from "@theme/TabItem"; # Global Triggers -Global triggers are events that occur on Reddit that can invoke the app. -Unlike other triggers, the events do not need to occur in the subreddit where the app is installed to invoke the app. +Global triggers let your app respond to Reddit events even when those events happen outside the subreddit where your app is installed. -Currently, the only supported global trigger is: +Currently, Devvit supports one global trigger: -* `onMentionInCommentCreate` +- `onMentionInCommentCreate` ## Example usage -Apps can respond to global trigger events just like any other trigger event. In `devvit.json`, declare the trigger and its corresponding endpoint: - +Configure a global trigger the same way you configure other trigger events: declare the event in `devvit.json`, map it to an internal endpoint, then handle requests at that endpoint. ```json "triggers": { @@ -21,7 +19,7 @@ Apps can respond to global trigger events just like any other trigger event. In } ``` -Then handle the global trigger event in your server logic: +Then handle the global trigger event in your server: ```tsx title="server/index.ts" -import { - type OnMentionInCommentCreateRequest, - type TriggerResponse, +import type { + OnMentionInCommentCreateRequest, + TriggerResponse, } from '@devvit/web/shared'; -triggers.post('/on-mention-in-comment-create', async (c) => { +app.post('/internal/triggers/on-mention-in-comment-create', async (c) => { console.log('Handle event for on-mention-in-comment-create!'); const input = await c.req.json(); - const comment = input.comment; - console.log('Comment ID: ', comment?.id); + const commentId = input.comment?.id; + console.log('Comment ID:', commentId); return c.json({ status: 'ok' }); }); ``` @@ -52,48 +50,49 @@ triggers.post('/on-mention-in-comment-create', async (c) => { ```tsx title="server/index.ts" -import type { OnMentionInCommentCreateRequest } from '@devvit/web/shared'; +import type { + OnMentionInCommentCreateRequest, + TriggerResponse, +} from '@devvit/web/shared'; const router = express.Router(); // .. router.post( - "/internal/on-mention-in-comment-create", + "/internal/triggers/on-mention-in-comment-create", async (req, res) => { - console.log(`Handle event for on-mention-in-comment-create!`); - const commentId = req.body.comment.id; - console.log("Comment ID:", commentId); - res.status(200).json({ status: "ok" }); -}); - + console.log("Handle event for on-mention-in-comment-create!"); + const commentId = req.body.comment?.id; + console.log("Comment ID:", commentId); + res.status(200).json({ status: "ok" }); + } +); ``` - ## Playtesting global triggers -When your app is in development, you may playtest global trigger events, but only using events that occur within the playtest subreddit. +During development, you can playtest global trigger events only when the triggering event occurs in the playtest subreddit. Events from other subreddits do not invoke your app while you are playtesting. -## Responding to global trigger events +## Responding to global trigger events across Reddit -In order for your app to respond to global trigger events across Reddit, your app must meet the following criteria: - -* App version must be published and approved -* App version must be installed to the app's profile subreddit +To receive global trigger events across Reddit, your app version must: +- Be published and approved. +- Be installed to the app's profile subreddit. ## Profile subreddit installations -Certain app versions are eligible to be installed to the app's profile subreddit. - -To be eligible for profile installation, the app version must be approved and make use of at least one global trigger event. +Some app versions can be installed to the app's profile subreddit. An app version is eligible when it has been approved and uses at least one global trigger event. -Eligible app versions will appear under the "Profile installation" section on the App's settings page at https://developers.reddit.com/apps/your-app-slug +Eligible app versions appear in the **Profile installation** section of your app's settings page at [developers.reddit.com/apps/your-app-slug](https://developers.reddit.com/apps/your-app-slug). ## Restrictions -Apps may not receive global trigger events under these circumstances: -* The event originates from a subreddit where the app is banned -* The event does not pass safety checks (eg, contains illegal content). Events may contain NSFW content. + +Apps do not receive global trigger events when: + +- The event originates from a subreddit where the app is banned. +- The event does not pass safety checks, such as checks for illegal content. Events may contain NSFW content.