Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/capabilities/server/global-triggers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Global Triggers

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:

<Tabs
variant="pill"
groupId="http-server-framework"
defaultValue="hono"
values={[
{ label: 'Hono', value: 'hono' },
{ label: 'Express', value: 'express' },
]}>
<TabItem value="hono">

```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<OnMentionInCommentCreateRequest>();
const commentId = input.comment?.id;
console.log('Comment ID:', commentId);
return c.json<TriggerResponse>({ status: 'ok' });
});
```

</TabItem>
<TabItem value="express">

```tsx title="server/index.ts"
import type {
OnMentionInCommentCreateRequest,
TriggerResponse,
} from '@devvit/web/shared';

const router = express.Router();

// ..

router.post<string, never, TriggerResponse, OnMentionInCommentCreateRequest>(
"/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" });
}
);
```

</TabItem>
</Tabs>

## 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.
19 changes: 18 additions & 1 deletion sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# Global Triggers

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:

<Tabs
variant="pill"
groupId="http-server-framework"
defaultValue="hono"
values={[
{ label: 'Hono', value: 'hono' },
{ label: 'Express', value: 'express' },
]}>
<TabItem value="hono">

```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<OnMentionInCommentCreateRequest>();
const commentId = input.comment?.id;
console.log('Comment ID:', commentId);
return c.json<TriggerResponse>({ status: 'ok' });
});
```

</TabItem>
<TabItem value="express">

```tsx title="server/index.ts"
import type {
OnMentionInCommentCreateRequest,
TriggerResponse,
} from '@devvit/web/shared';

const router = express.Router();

// ..

router.post<string, never, TriggerResponse, OnMentionInCommentCreateRequest>(
"/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" });
}
);
```

</TabItem>
</Tabs>

## 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
16 changes: 15 additions & 1 deletion versioned_sidebars/version-0.13-sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
},
{
Expand Down
Loading