Skip to content

Commit d44dc82

Browse files
authored
Merge pull request #41 from scibilo/fix/webhook-async-ai
fix(webhook): remove synchronous AI call from webhook handler
2 parents 1cf6043 + 20f0352 commit d44dc82

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

api/webhook.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,17 @@
138138

139139
try {
140140
$contentId = TelegramBot::handleUpdate($update);
141-
142-
// If the ID is valid and AI is enabled, process immediately (we are already in background)
143-
if ($contentId && ($config['ai_enabled'] ?? false)) {
144-
AIService::processContent($contentId);
145-
}
141+
142+
// AI processing is intentionally NOT done here.
143+
//
144+
// Calling AIService::processContent() inline would block the webhook
145+
// response for the duration of the Gemini API call (typically 1-5s).
146+
// Telegram considers a webhook failed if it does not receive a 2xx
147+
// within a few seconds and will retry — redelivering the same update
148+
// and causing duplicate content or double-tagging.
149+
//
150+
// The cron endpoint (/api/cron.php) picks up rows with ai_processed=0
151+
// on its own schedule. Set it up via: Settings → Cron in the admin.
146152
} catch (Throwable $e) {
147153
error_log('[TELEPAGE][WEBHOOK] ' . $e->getMessage());
148154
}

0 commit comments

Comments
 (0)