( accessToken: string, userId: string, requestId: string, logger: Logger )
| 204 | * Opens a DM channel with a user and returns the channel ID |
| 205 | */ |
| 206 | export async function openDMChannel( |
| 207 | accessToken: string, |
| 208 | userId: string, |
| 209 | requestId: string, |
| 210 | logger: Logger |
| 211 | ): Promise<string> { |
| 212 | const response = await fetch('https://slack.com/api/conversations.open', { |
| 213 | method: 'POST', |
| 214 | headers: { |
| 215 | 'Content-Type': 'application/json', |
| 216 | Authorization: `Bearer ${accessToken}`, |
| 217 | }, |
| 218 | body: JSON.stringify({ |
| 219 | users: userId, |
| 220 | }), |
| 221 | }) |
| 222 | |
| 223 | const data = await response.json() |
| 224 | |
| 225 | if (!data.ok) { |
| 226 | logger.error(`[${requestId}] Failed to open DM channel:`, data.error) |
| 227 | throw new Error(data.error || 'Failed to open DM channel with user') |
| 228 | } |
| 229 | |
| 230 | logger.info(`[${requestId}] Opened DM channel: ${data.channel.id}`) |
| 231 | return data.channel.id |
| 232 | } |
| 233 | |
| 234 | export interface SlackMessageParams { |
| 235 | accessToken: string |
no test coverage detected