Skip to content
Merged
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
57 changes: 51 additions & 6 deletions docs/capabilities/server/text_fallback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,58 @@ const post = await reddit.submitCustomPost({

## Update a post’s text fallback

The post author can edit and update text fallback content after it’s been created. To do this, call post.setTextFallback with the desired fallback content.
Call `post.setTextFallback()` to update the fallback content of an existing custom post. The method uses the app identity by default. For an app-authored post, omit `runAs` or set it to `"APP"`:

```tsx
import { reddit } from '@devvit/web/server';
import { context, reddit } from "@devvit/web/server";

export async function updateAppFallback() {
if (!context.postId) {
throw new Error("Post context required.");
}

const post = await reddit.getPostById(context.postId);
await post.setTextFallback({ text: "Updated instructions for this post." });
}
```

### Update a user-authored post

Starting with Devvit 0.14.3, you can pass `runAs: "USER"` to update fallback content on behalf of the current user. Enable the `SUBMIT_POST` scope:

```json title="devvit.json"
{
"permissions": {
"reddit": {
"enable": true,
"asUser": ["SUBMIT_POST"]
}
}
}
```

Call this function from a signed-in post interaction. This example checks that the current user is the post author before requesting an update:

```tsx
import { context, reddit } from "@devvit/web/server";

export async function updateUserFallback() {
if (!context.userId || !context.postId) {
throw new Error("Signed-in post interaction required.");
}

const post = await reddit.getPostById(context.postId);
if (post.authorId !== context.userId) {
throw new Error("Post author required.");
}

// from a menu action, form, scheduler, trigger, custom post click event, etc
const newTextFallback = { text: 'This is an updated text fallback' };
const post = await reddit.getPostById(context.postId);
await post.setTextFallback(newTextFallback);
await post.setTextFallback({
text: "Updated instructions for this interactive post.",
runAs: "USER",
});
}
```

`"USER"` uses the current request's user. It cannot select an arbitrary user or bypass Reddit's edit permissions. User grants and authorization still apply, and a scheduler or trigger handler may not have a suitable acting-user context.

The method returns `Promise<void>` and rejects if the update fails. Await it before reporting success. See [SetCustomPostTextFallbackOptions](../../api/redditapi/models/type-aliases/SetCustomPostTextFallbackOptions.md) for the content options and `runAs` type.
57 changes: 51 additions & 6 deletions versioned_docs/version-0.14/capabilities/server/text_fallback.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,58 @@ const post = await reddit.submitCustomPost({

## Update a post’s text fallback

The post author can edit and update text fallback content after it’s been created. To do this, call post.setTextFallback with the desired fallback content.
Call `post.setTextFallback()` to update the fallback content of an existing custom post. The method uses the app identity by default. For an app-authored post, omit `runAs` or set it to `"APP"`:

```tsx
import { reddit } from '@devvit/web/server';
import { context, reddit } from "@devvit/web/server";

export async function updateAppFallback() {
if (!context.postId) {
throw new Error("Post context required.");
}

const post = await reddit.getPostById(context.postId);
await post.setTextFallback({ text: "Updated instructions for this post." });
}
```

### Update a user-authored post

Starting with Devvit 0.14.3, you can pass `runAs: "USER"` to update fallback content on behalf of the current user. Enable the `SUBMIT_POST` scope:

```json title="devvit.json"
{
"permissions": {
"reddit": {
"enable": true,
"asUser": ["SUBMIT_POST"]
}
}
}
```

Call this function from a signed-in post interaction. This example checks that the current user is the post author before requesting an update:

```tsx
import { context, reddit } from "@devvit/web/server";

export async function updateUserFallback() {
if (!context.userId || !context.postId) {
throw new Error("Signed-in post interaction required.");
}

const post = await reddit.getPostById(context.postId);
if (post.authorId !== context.userId) {
throw new Error("Post author required.");
}

// from a menu action, form, scheduler, trigger, custom post click event, etc
const newTextFallback = { text: 'This is an updated text fallback' };
const post = await reddit.getPostById(context.postId);
await post.setTextFallback(newTextFallback);
await post.setTextFallback({
text: "Updated instructions for this interactive post.",
runAs: "USER",
});
}
```

`"USER"` uses the current request's user. It cannot select an arbitrary user or bypass Reddit's edit permissions. User grants and authorization still apply, and a scheduler or trigger handler may not have a suitable acting-user context.

The method returns `Promise<void>` and rejects if the update fails. Await it before reporting success. See [SetCustomPostTextFallbackOptions](../../api/redditapi/models/type-aliases/SetCustomPostTextFallbackOptions.md) for the content options and `runAs` type.
Loading