Skip to content
← Public packages

@kody/slack

Read Slack conversations and safely send messages as the authorizing user through the saved slack OAuth integration.

src/get-replies.ts

34 lines · 1.0 KB · TypeScript
import { nextCursor, resolveIntegrationName, slackRequest } from './request.ts'
import { boundedLimit, inputRecord, optionalBoolean, optionalString, requiredString } from './validation.ts'

type RepliesResponse = {
	ok: boolean
	messages?: unknown[]
	has_more?: boolean
	response_metadata?: { next_cursor?: string }
	[key: string]: unknown
}

/** Read a Slack message thread available to the user. */
export default async function getReplies(params: Record<string, unknown>) {
	const input = inputRecord(params)
	const result = await slackRequest<RepliesResponse>(
		'conversations.replies',
		{
			channel: requiredString(input, 'channel'),
			ts: requiredString(input, 'ts'),
			limit: boundedLimit(input.limit),
			cursor: optionalString(input, 'cursor'),
			oldest: optionalString(input, 'oldest'),
			latest: optionalString(input, 'latest'),
			inclusive: optionalBoolean(input, 'inclusive'),
		},
		resolveIntegrationName(input.integration),
	)

	return {
		messages: result.messages ?? [],
		hasMore: result.has_more === true,
		nextCursor: nextCursor(result),
	}
}