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

Function pollWebhook

apps/sim/lib/webhooks/polling/google-sheets.ts:54–249  ·  view source on GitHub ↗
(ctx: PollWebhookContext)

Source from the content-addressed store, hash-verified

52 label: 'Google Sheets',
53
54 async pollWebhook(ctx: PollWebhookContext): Promise<'success' | 'failure'> {
55 const { webhookData, workflowData, requestId, logger } = ctx
56 const webhookId = webhookData.id
57
58 try {
59 const accessToken = await resolveOAuthCredential(
60 webhookData,
61 'google-sheets',
62 requestId,
63 logger
64 )
65
66 const config = getProviderConfig<GoogleSheetsWebhookConfig>(webhookData.providerConfig)
67 // Canonical keys (`spreadsheetId`/`sheetName`) first; the `manual*` keys are a transitional
68 // basic-first fallback for configs deployed before the canonical key existed.
69 const spreadsheetId = readCanonicalTriggerValue(
70 config.spreadsheetId,
71 config.manualSpreadsheetId
72 )
73 const sheetName = readCanonicalTriggerValue(config.sheetName, config.manualSheetName)
74 const now = new Date()
75
76 if (!spreadsheetId || !sheetName) {
77 logger.error(`[${requestId}] Missing spreadsheetId or sheetName for webhook ${webhookId}`)
78 await markWebhookFailed(webhookId, logger)
79 return 'failure'
80 }
81
82 const { unchanged: skipPoll, currentModifiedTime } = await isDriveFileUnchanged(
83 accessToken,
84 spreadsheetId,
85 config.lastModifiedTime,
86 requestId,
87 logger
88 )
89
90 if (skipPoll) {
91 await updateWebhookProviderConfig(
92 webhookId,
93 { lastCheckedTimestamp: now.toISOString() },
94 logger
95 )
96 await markWebhookSuccess(webhookId, logger)
97 logger.info(`[${requestId}] Sheet not modified since last poll for webhook ${webhookId}`)
98 return 'success'
99 }
100
101 const valueRender = config.valueRenderOption || 'FORMATTED_VALUE'
102 const dateTimeRender = config.dateTimeRenderOption || 'SERIAL_NUMBER'
103
104 const {
105 rowCount: currentRowCount,
106 headers,
107 headerRowIndex,
108 } = await fetchSheetState(
109 accessToken,
110 spreadsheetId,
111 sheetName,

Callers

nothing calls this directly

Calls 13

resolveOAuthCredentialFunction · 0.90
getProviderConfigFunction · 0.90
markWebhookFailedFunction · 0.90
markWebhookSuccessFunction · 0.90
isDriveFileUnchangedFunction · 0.85
fetchSheetStateFunction · 0.85
fetchRowRangeFunction · 0.85
processRowsFunction · 0.85
errorMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected