From f7dfb42c674eecdb540b1da6cdfd37ff7023745a Mon Sep 17 00:00:00 2001 From: Dikran Samarjian Date: Thu, 15 Oct 2026 15:54:16 -0700 Subject: [PATCH] Document acting-user updates to custom post text fallback --- docs/capabilities/server/text_fallback.mdx | 57 +++++++++++++++++-- .../capabilities/server/text_fallback.mdx | 57 +++++++++++++++++-- 2 files changed, 102 insertions(+), 12 deletions(-) diff --git a/docs/capabilities/server/text_fallback.mdx b/docs/capabilities/server/text_fallback.mdx index cbe082c86..ca438fcd3 100644 --- a/docs/capabilities/server/text_fallback.mdx +++ b/docs/capabilities/server/text_fallback.mdx @@ -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` 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. diff --git a/versioned_docs/version-0.14/capabilities/server/text_fallback.mdx b/versioned_docs/version-0.14/capabilities/server/text_fallback.mdx index cbe082c86..ca438fcd3 100644 --- a/versioned_docs/version-0.14/capabilities/server/text_fallback.mdx +++ b/versioned_docs/version-0.14/capabilities/server/text_fallback.mdx @@ -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` 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.