(
channelId: string,
options: {
oldest?: string; // Unix timestamp - only messages after this time
latest?: string; // Unix timestamp - only messages before this time
limit?: number; // Max messages per request (default 100, max 1000)
cursor?: string; // Pagination cursor
} = {}
)
| 1231 | * @returns Array of messages and pagination info |
| 1232 | */ |
| 1233 | export async function getChannelHistory( |
| 1234 | channelId: string, |
| 1235 | options: { |
| 1236 | oldest?: string; // Unix timestamp - only messages after this time |
| 1237 | latest?: string; // Unix timestamp - only messages before this time |
| 1238 | limit?: number; // Max messages per request (default 100, max 1000) |
| 1239 | cursor?: string; // Pagination cursor |
| 1240 | } = {} |
| 1241 | ): Promise<{ messages: SlackHistoryMessage[]; hasMore: boolean; nextCursor?: string }> { |
| 1242 | try { |
| 1243 | const response = await slackRequest<{ |
| 1244 | messages: SlackHistoryMessage[]; |
| 1245 | has_more: boolean; |
| 1246 | response_metadata?: { next_cursor?: string }; |
| 1247 | }>('conversations.history', { |
| 1248 | channel: channelId, |
| 1249 | oldest: options.oldest, |
| 1250 | latest: options.latest, |
| 1251 | limit: options.limit ?? 100, |
| 1252 | cursor: options.cursor, |
| 1253 | }); |
| 1254 | |
| 1255 | return { |
| 1256 | messages: response.messages ?? [], |
| 1257 | hasMore: response.has_more ?? false, |
| 1258 | nextCursor: response.response_metadata?.next_cursor, |
| 1259 | }; |
| 1260 | } catch (error) { |
| 1261 | logger.warn({ error, channelId }, 'Failed to get channel history'); |
| 1262 | return { messages: [], hasMore: false }; |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * Get all messages from a channel within a time range |
no test coverage detected