Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.25 KB

README.md

File metadata and controls

51 lines (39 loc) · 1.25 KB

toolbox-devvit npm version

Helpers for working with /r/toolbox data from Devvit community apps. Read the documentation.

Installation

npm install --production toolbox-devvit

Usage 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;

License

MIT © the toolbox team