Class ToolboxClient

A client class for interfacing with Toolbox functionality and stored data from within the Devvit platform. Wraps the Reddit API client provided in Devvit events and provides methods to perform various actions.

Example

import {Devvit} from '@devvit/public-api';
import {ToolboxClient} from 'toolbox-devvit';

Devvit.configure({
redditAPI: true,
// ...
});

// A simple action that creates a usernote on a post's author
Devvit.addMenuItem({
location: 'post',
label: 'Create Test Usernote',
description: 'Creates a Toolbox usernote for testing',
onPress: async (event, {reddit, ui, postId}) => {
const subredditName = (await reddit.getCurrentSubreddit()).name;
const username = (await reddit.getPostById(postId!)).authorName;
const text = 'Hihi i am a note';
const wikiRevisionReason = 'Create note via my custom app';

const toolbox = new ToolboxClient(reddit);
await toolbox.addUsernote(subredditName, {
username,
text,
}, wikiRevisionReason);

ui.showToast({
appearance: 'success',
text: 'Note added!',
});
}
});

export default Devvit;

Hierarchy

  • ToolboxClient

Constructors

  • Creates a Toolbox client. Do this at the top of event handlers, where you passing reddit from the event context. Make sure you've called Devvit.configure({redditAPI: true}) as well!

    Parameters

    • redditClient: any

      Your RedditAPIClient instance

    Returns ToolboxClient

Properties

reddit: RedditAPIClient

Methods

  • Creates a usernote.

    Parameters

    • subreddit: string

      Name of the subreddit to create the note in

    • note: UsernoteInit

      Details about the usernote to create

    • reason: undefined | string

      Wiki revision reason to send

    Returns Promise<void>

    Promise which resolves on success or rejects on error

  • Retrieves toolbox configuration for a subreddit.

    Parameters

    • subreddit: string

      Name of the subreddit to retrieve config for

    Returns Promise<SubredditConfig>

  • Gets a handle to all usernotes in a given subreddit.

    Parameters

    • subreddit: string

      Name of the subreddit to get notes from

    Returns Promise<Usernotes>

    Promise which resolves to a Usernotes instance containing the notes, or rejects on error

  • Gets the usernotes on a particular user.

    Parameters

    • subreddit: string

      Name of the subreddit to create the note in

    • username: string

      Username to fetch notes of

    Returns Promise<Usernote[]>

    Promise which resolves to an array of notes or rejects on error

  • Saves usernotes from a Usernotes instance to a subreddit.

    Parameters

    • subreddit: string

      Name of the subreddit to save notes to

    • notes: Usernotes

      Object containing all the subreddit's notes

    • reason: undefined | string

      Wiki revision reason to send

    Returns Promise<void>

    Promise which resolves on success or rejects on error

Generated using TypeDoc