Skip to content

Commit ffc73bb

Browse files
Add docs for global trigger events, app mentions (#132)
## πŸ’Έ TL;DR Drafts documentation about global trigger events, specifically for app mentions. ## πŸ“œ Details Internal issue: DX-11040 ## πŸ§ͺ Testing Steps / Validation `yarn start` docs ## βœ… Checks <!-- Make sure your pr passes the CI checks and do check the following fields as needed - --> - [x] CI tests (if present) are passing - [x] Adheres to code style for repo - [x] Contributor License Agreement (CLA) completed if not a Reddit employee --------- Co-authored-by: Stacy <143668017+stacy-qqq@users.noreply.github.com>
1 parent f2259bb commit ffc73bb

5 files changed

Lines changed: 232 additions & 2 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import Tabs from "@theme/Tabs";
2+
import TabItem from "@theme/TabItem";
3+
4+
# App Mention Triggers
5+
6+
App mention triggers let your app respond to Reddit events even when those events happen outside the subreddit where your app is installed. App mention triggers are limited to app usernames.
7+
8+
Devvit currently supports one global trigger: `onMentionInCommentCreate`
9+
10+
:::note
11+
This is a limited-access feature. Fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLScLU2m-IH9xtt4hqFBNy5AlrswY0pvfvoyTiQREbq_9xDQJkQ/viewform) to request access.
12+
:::
13+
14+
## Example usage
15+
16+
Configure an app mention 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.
17+
18+
```json
19+
"triggers": {
20+
"onMentionInCommentCreate": "/internal/triggers/on-mention-in-comment-create"
21+
}
22+
```
23+
24+
Then handle the app mention trigger event in your server:
25+
26+
<Tabs
27+
variant="pill"
28+
groupId="http-server-framework"
29+
defaultValue="hono"
30+
values={[
31+
{ label: 'Hono', value: 'hono' },
32+
{ label: 'Express', value: 'express' },
33+
]}>
34+
<TabItem value="hono">
35+
36+
```tsx title="server/index.ts"
37+
import type {
38+
OnMentionInCommentCreateRequest,
39+
TriggerResponse,
40+
} from '@devvit/web/shared';
41+
42+
app.post('/internal/triggers/on-mention-in-comment-create', async (c) => {
43+
console.log('Handle event for on-mention-in-comment-create!');
44+
const input = await c.req.json<OnMentionInCommentCreateRequest>();
45+
const commentId = input.comment?.id;
46+
console.log('Comment ID:', commentId);
47+
return c.json<TriggerResponse>({ status: 'ok' });
48+
});
49+
```
50+
51+
</TabItem>
52+
<TabItem value="express">
53+
54+
```tsx title="server/index.ts"
55+
import type {
56+
OnMentionInCommentCreateRequest,
57+
TriggerResponse,
58+
} from '@devvit/web/shared';
59+
60+
const router = express.Router();
61+
62+
// ..
63+
64+
router.post<string, never, TriggerResponse, OnMentionInCommentCreateRequest>(
65+
"/internal/triggers/on-mention-in-comment-create",
66+
async (req, res) => {
67+
console.log("Handle event for on-mention-in-comment-create!");
68+
const commentId = req.body.comment?.id;
69+
console.log("Comment ID:", commentId);
70+
res.status(200).json({ status: "ok" });
71+
}
72+
);
73+
```
74+
75+
</TabItem>
76+
</Tabs>
77+
78+
## Playtesting app mention triggers
79+
80+
During development, you can playtest app mention 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.
81+
82+
## Responding to app mention trigger events across Reddit
83+
84+
To receive app mention trigger events across Reddit, your app version must:
85+
86+
- Be published and approved.
87+
- Be installed to the app's profile subreddit.
88+
89+
## Profile subreddit installations
90+
91+
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 app mention trigger event.
92+
93+
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).
94+
95+
## Limitations
96+
97+
Apps do not receive app mention trigger events when:
98+
99+
- The event does not pass safety checks, such as checks for illegal content. Events may contain NSFW content.

β€Žsidebars.tsβ€Ž

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,24 @@ const sidebars: SidebarsConfig = {
162162
{
163163
type: "category",
164164
label: "Automation & Triggers",
165-
items: ["capabilities/server/scheduler", "capabilities/server/triggers"],
165+
items: [
166+
"capabilities/server/scheduler",
167+
{
168+
type: "category",
169+
label: "Triggers",
170+
link: {
171+
type: "doc",
172+
id: "capabilities/server/triggers",
173+
},
174+
items: [
175+
{
176+
type: "doc",
177+
id: "capabilities/server/global-triggers",
178+
label: "Global Triggers",
179+
},
180+
],
181+
},
182+
],
166183
},
167184
{
168185
type: "doc",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import Tabs from "@theme/Tabs";
2+
import TabItem from "@theme/TabItem";
3+
4+
# App Mention Triggers
5+
6+
App mention triggers let your app respond to Reddit events even when those events happen outside the subreddit where your app is installed. App mention triggers are limited to app usernames.
7+
8+
Devvit currently supports one global trigger: `onMentionInCommentCreate`
9+
10+
:::note
11+
This is a limited-access feature. Fill out this [form](https://docs.google.com/forms/d/e/1FAIpQLScLU2m-IH9xtt4hqFBNy5AlrswY0pvfvoyTiQREbq_9xDQJkQ/viewform) to request access.
12+
:::
13+
14+
## Example usage
15+
16+
Configure an app mention 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.
17+
18+
```json
19+
"triggers": {
20+
"onMentionInCommentCreate": "/internal/triggers/on-mention-in-comment-create"
21+
}
22+
```
23+
24+
Then handle the app mention trigger event in your server:
25+
26+
<Tabs
27+
variant="pill"
28+
groupId="http-server-framework"
29+
defaultValue="hono"
30+
values={[
31+
{ label: 'Hono', value: 'hono' },
32+
{ label: 'Express', value: 'express' },
33+
]}>
34+
<TabItem value="hono">
35+
36+
```tsx title="server/index.ts"
37+
import type {
38+
OnMentionInCommentCreateRequest,
39+
TriggerResponse,
40+
} from '@devvit/web/shared';
41+
42+
app.post('/internal/triggers/on-mention-in-comment-create', async (c) => {
43+
console.log('Handle event for on-mention-in-comment-create!');
44+
const input = await c.req.json<OnMentionInCommentCreateRequest>();
45+
const commentId = input.comment?.id;
46+
console.log('Comment ID:', commentId);
47+
return c.json<TriggerResponse>({ status: 'ok' });
48+
});
49+
```
50+
51+
</TabItem>
52+
<TabItem value="express">
53+
54+
```tsx title="server/index.ts"
55+
import type {
56+
OnMentionInCommentCreateRequest,
57+
TriggerResponse,
58+
} from '@devvit/web/shared';
59+
60+
const router = express.Router();
61+
62+
// ..
63+
64+
router.post<string, never, TriggerResponse, OnMentionInCommentCreateRequest>(
65+
"/internal/triggers/on-mention-in-comment-create",
66+
async (req, res) => {
67+
console.log("Handle event for on-mention-in-comment-create!");
68+
const commentId = req.body.comment?.id;
69+
console.log("Comment ID:", commentId);
70+
res.status(200).json({ status: "ok" });
71+
}
72+
);
73+
```
74+
75+
</TabItem>
76+
</Tabs>
77+
78+
## Playtesting app mention triggers
79+
80+
During development, you can playtest app mention 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.
81+
82+
## Responding to app mention trigger events across Reddit
83+
84+
To receive app mention trigger events across Reddit, your app version must:
85+
86+
- Be published and approved.
87+
- Be installed to the app's profile subreddit.
88+
89+
## Profile subreddit installations
90+
91+
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 app mention trigger event.
92+
93+
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).
94+
95+
## Limitations
96+
97+
Apps do not receive app mention trigger events when:
98+
99+
- The event does not pass safety checks, such as checks for illegal content. Events may contain NSFW content.

β€Žversioned_docs/version-0.13/capabilities/server/triggers.mdxβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Event triggers let your app automatically respond to a user's or moderator's act
3232
- `onModMail`
3333
- `onAutomoderatorFilterPost`
3434
- `onAutomoderatorFilterComment`
35+
- `onMentionInCommentCreate`
3536

3637
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).
3738

β€Žversioned_sidebars/version-0.13-sidebars.jsonβ€Ž

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,21 @@
149149
"label": "Automation & Triggers",
150150
"items": [
151151
"capabilities/server/scheduler",
152-
"capabilities/server/triggers"
152+
{
153+
"type": "category",
154+
"label": "Triggers",
155+
"link": {
156+
"type": "doc",
157+
"id": "capabilities/server/triggers"
158+
},
159+
"items": [
160+
{
161+
"type": "doc",
162+
"id": "capabilities/server/global-triggers",
163+
"label": "Global Triggers"
164+
}
165+
]
166+
}
153167
]
154168
},
155169
{

0 commit comments

Comments
Β (0)