MCPcopy Index your code
hub / github.com/simstudioai/sim / pollWebhook

Function pollWebhook

apps/sim/lib/webhooks/polling/outlook.ts:113–173  ·  view source on GitHub ↗
(ctx: PollWebhookContext)

Source from the content-addressed store, hash-verified

111 label: 'Outlook',
112
113 async pollWebhook(ctx: PollWebhookContext): Promise<'success' | 'failure'> {
114 const { webhookData, workflowData, requestId, logger } = ctx
115 const webhookId = webhookData.id
116
117 try {
118 logger.info(`[${requestId}] Processing Outlook webhook: ${webhookId}`)
119
120 const accessToken = await resolveOAuthCredential(webhookData, 'outlook', requestId, logger)
121 const config = getProviderConfig<OutlookWebhookConfig>(webhookData.providerConfig)
122 const now = new Date()
123
124 const { emails } = await fetchNewOutlookEmails(accessToken, config, requestId, logger)
125
126 if (!emails || !emails.length) {
127 await updateWebhookProviderConfig(
128 webhookId,
129 { lastCheckedTimestamp: now.toISOString() },
130 logger
131 )
132 await markWebhookSuccess(webhookId, logger)
133 logger.info(`[${requestId}] No new emails found for webhook ${webhookId}`)
134 return 'success'
135 }
136
137 logger.info(`[${requestId}] Found ${emails.length} emails for webhook ${webhookId}`)
138
139 const { processedCount, failedCount } = await processOutlookEmails(
140 emails,
141 webhookData,
142 workflowData,
143 config,
144 accessToken,
145 requestId,
146 logger
147 )
148
149 await updateWebhookProviderConfig(
150 webhookId,
151 { lastCheckedTimestamp: now.toISOString() },
152 logger
153 )
154
155 if (failedCount > 0 && processedCount === 0) {
156 await markWebhookFailed(webhookId, logger)
157 logger.warn(
158 `[${requestId}] All ${failedCount} emails failed to process for webhook ${webhookId}`
159 )
160 return 'failure'
161 }
162
163 await markWebhookSuccess(webhookId, logger)
164 logger.info(
165 `[${requestId}] Successfully processed ${processedCount} emails for webhook ${webhookId}${failedCount > 0 ? ` (${failedCount} failed)` : ''}`
166 )
167 return 'success'
168 } catch (error) {
169 logger.error(`[${requestId}] Error processing Outlook webhook ${webhookId}:`, error)
170 await markWebhookFailed(webhookId, logger)

Callers

nothing calls this directly

Calls 10

resolveOAuthCredentialFunction · 0.90
getProviderConfigFunction · 0.90
markWebhookSuccessFunction · 0.90
markWebhookFailedFunction · 0.90
fetchNewOutlookEmailsFunction · 0.85
processOutlookEmailsFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected