( channelId: string, threadTs: string )
| 933 | * Returns all messages in a thread, including the parent message |
| 934 | */ |
| 935 | export async function getThreadReplies( |
| 936 | channelId: string, |
| 937 | threadTs: string |
| 938 | ): Promise<SlackThreadMessage[]> { |
| 939 | if (!SLACK_BOT_TOKEN) { |
| 940 | throw new Error('ADDIE_BOT_TOKEN is not configured'); |
| 941 | } |
| 942 | |
| 943 | try { |
| 944 | const url = new URL(`${SLACK_API_BASE}/conversations.replies`); |
| 945 | url.searchParams.set('channel', channelId); |
| 946 | url.searchParams.set('ts', threadTs); |
| 947 | url.searchParams.set('limit', '100'); // Get up to 100 messages in thread |
| 948 | |
| 949 | const response = await fetch(url.toString(), { |
| 950 | method: 'GET', |
| 951 | headers: { |
| 952 | Authorization: `Bearer ${SLACK_BOT_TOKEN}`, |
| 953 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 954 | }, |
| 955 | }); |
| 956 | |
| 957 | const data = await response.json() as { |
| 958 | ok: boolean; |
| 959 | messages?: SlackThreadMessage[]; |
| 960 | error?: string; |
| 961 | }; |
| 962 | |
| 963 | if (!data.ok) { |
| 964 | logger.warn({ error: data.error, channelId, threadTs }, 'Failed to get thread replies'); |
| 965 | return []; |
| 966 | } |
| 967 | |
| 968 | return data.messages || []; |
| 969 | } catch (error) { |
| 970 | logger.error({ error, channelId, threadTs }, 'Error fetching thread replies'); |
| 971 | return []; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Open a group DM (multi-person direct message) with multiple users |
no test coverage detected