(ctx: PollWebhookContext)
| 64 | label: 'Gmail', |
| 65 | |
| 66 | async pollWebhook(ctx: PollWebhookContext): Promise<'success' | 'failure'> { |
| 67 | const { webhookData, workflowData, requestId, logger } = ctx |
| 68 | const webhookId = webhookData.id |
| 69 | |
| 70 | try { |
| 71 | const accessToken = await resolveOAuthCredential( |
| 72 | webhookData, |
| 73 | 'google-email', |
| 74 | requestId, |
| 75 | logger |
| 76 | ) |
| 77 | |
| 78 | const config = getProviderConfig<GmailWebhookConfig>(webhookData.providerConfig) |
| 79 | const now = new Date() |
| 80 | |
| 81 | const { emails, latestHistoryId } = await fetchNewEmails( |
| 82 | accessToken, |
| 83 | config, |
| 84 | requestId, |
| 85 | logger |
| 86 | ) |
| 87 | |
| 88 | if (!emails || !emails.length) { |
| 89 | await updateWebhookProviderConfig( |
| 90 | webhookId, |
| 91 | { |
| 92 | lastCheckedTimestamp: now.toISOString(), |
| 93 | ...(latestHistoryId || config.historyId |
| 94 | ? { historyId: latestHistoryId || config.historyId } |
| 95 | : {}), |
| 96 | }, |
| 97 | logger |
| 98 | ) |
| 99 | await markWebhookSuccess(webhookId, logger) |
| 100 | logger.info(`[${requestId}] No new emails found for webhook ${webhookId}`) |
| 101 | return 'success' |
| 102 | } |
| 103 | |
| 104 | logger.info(`[${requestId}] Found ${emails.length} new emails for webhook ${webhookId}`) |
| 105 | |
| 106 | const { processedCount, failedCount } = await processEmails( |
| 107 | emails, |
| 108 | webhookData, |
| 109 | workflowData, |
| 110 | config, |
| 111 | accessToken, |
| 112 | requestId, |
| 113 | logger |
| 114 | ) |
| 115 | |
| 116 | await updateWebhookProviderConfig( |
| 117 | webhookId, |
| 118 | { |
| 119 | lastCheckedTimestamp: now.toISOString(), |
| 120 | ...(latestHistoryId || config.historyId |
| 121 | ? { historyId: latestHistoryId || config.historyId } |
| 122 | : {}), |
| 123 | }, |
nothing calls this directly
no test coverage detected