Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/reddit

src/submit-comment.ts

18 lines · 847 B · TypeScript
import { requireRecord, requireStringField, submitComment } from './client.ts'
import type { SubmitCommentInput } from './client.ts'

/**
 * Create or dry-run a Reddit comment. Publishing requires confirm: true.
 * @example
 * import submitComment from 'kody:@kody/reddit/submit-comment'
 * const preview = await submitComment({ parentId: 't3_abc123', text: 'Nice post', dryRun: true })
 * // => { dryRun: true, method: 'POST', url: 'https://oauth.reddit.com/api/comment', requiresConfirm: true }
 */
export default async function submitCommentEntrypoint(
	params: Partial<SubmitCommentInput> & Record<string, unknown> = {},
) {
	const input = requireRecord(params, 'submit-comment')
	requireStringField(input, 'parentId', 'submit-comment')
	requireStringField(input, 'text', 'submit-comment')
	return submitComment(input as SubmitCommentInput)
}