(accessToken: string, messageId: string)
| 406 | } |
| 407 | |
| 408 | async function getEmailDetails(accessToken: string, messageId: string): Promise<GmailEmail> { |
| 409 | const messageUrl = `https://gmail.googleapis.com/gmail/v1/users/me/messages/${messageId}?format=full` |
| 410 | |
| 411 | const messageResponse = await fetch(messageUrl, { |
| 412 | headers: { Authorization: `Bearer ${accessToken}` }, |
| 413 | }) |
| 414 | |
| 415 | if (!messageResponse.ok) { |
| 416 | const errorData = await messageResponse.json().catch(() => ({})) |
| 417 | throw new Error( |
| 418 | `Failed to fetch email details for message ${messageId}: ${messageResponse.status} ${messageResponse.statusText} - ${JSON.stringify(errorData)}` |
| 419 | ) |
| 420 | } |
| 421 | |
| 422 | return await messageResponse.json() |
| 423 | } |
| 424 | |
| 425 | function filterEmailsByLabels(emails: GmailEmail[], config: GmailWebhookConfig): GmailEmail[] { |
| 426 | if (!config.labelIds.length) { |
no outgoing calls
no test coverage detected