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

Function configurePolling

apps/sim/lib/webhooks/providers/outlook.ts:24–112  ·  view source on GitHub ↗
({ webhook: webhookData, requestId }: PollingConfigContext)

Source from the content-addressed store, hash-verified

22 },
23
24 async configurePolling({ webhook: webhookData, requestId }: PollingConfigContext) {
25 logger.info(`[${requestId}] Setting up Outlook polling for webhook ${webhookData.id}`)
26
27 try {
28 const providerConfig = (webhookData.providerConfig as Record<string, unknown>) || {}
29 const credentialId = providerConfig.credentialId as string | undefined
30
31 if (!credentialId) {
32 logger.error(`[${requestId}] Missing credentialId for Outlook webhook ${webhookData.id}`)
33 return false
34 }
35
36 const resolvedOutlook = await resolveOAuthAccountId(credentialId)
37 if (!resolvedOutlook) {
38 logger.error(
39 `[${requestId}] Could not resolve credential ${credentialId} for Outlook webhook ${webhookData.id}`
40 )
41 return false
42 }
43
44 const rows = await db
45 .select()
46 .from(account)
47 .where(eq(account.id, resolvedOutlook.accountId))
48 .limit(1)
49 if (rows.length === 0) {
50 logger.error(
51 `[${requestId}] Credential ${credentialId} not found for Outlook webhook ${webhookData.id}`
52 )
53 return false
54 }
55
56 const effectiveUserId = rows[0].userId
57
58 const accessToken = await refreshAccessTokenIfNeeded(
59 resolvedOutlook.accountId,
60 effectiveUserId,
61 requestId
62 )
63 if (!accessToken) {
64 logger.error(
65 `[${requestId}] Failed to refresh/access Outlook token for credential ${credentialId}`
66 )
67 return false
68 }
69
70 const now = new Date()
71
72 await db
73 .update(webhook)
74 .set({
75 providerConfig: {
76 ...providerConfig,
77 userId: effectiveUserId,
78 credentialId,
79 maxEmailsPerPoll:
80 typeof providerConfig.maxEmailsPerPoll === 'string'
81 ? Number.parseInt(providerConfig.maxEmailsPerPoll, 10) || 25

Callers

nothing calls this directly

Calls 6

resolveOAuthAccountIdFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
setMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected