Skip to content

Add YouTube webhooks and Google Calendar webhooks#214

Merged
SantiagoPidji merged 68 commits into
mainfrom
add-youtube
Nov 2, 2025
Merged

Add YouTube webhooks and Google Calendar webhooks#214
SantiagoPidji merged 68 commits into
mainfrom
add-youtube

Conversation

@Arkteus

@Arkteus Arkteus commented Nov 2, 2025

Copy link
Copy Markdown
Contributor

This pull request introduces significant enhancements to Google service integrations, focusing on enabling and managing push notifications (webhooks) for Gmail, Google Calendar, and YouTube. It adds new environment-based configuration options, expands OAuth scopes, introduces helper functions for managing Google watches, and updates Celery beat scheduling to support webhooks and watch renewals. The changes improve efficiency by reducing reliance on polling and providing robust support for push-based event handling.

Google Webhook (Push Notification) Support:

  • Added a new module google_webhook_helper.py with helper functions to create, stop, and renew push notification watches for Gmail, Calendar, and YouTube, including support for PubSubHubbub for YouTube. This enables the backend to manage Google push notifications more effectively.
  • Introduced new environment variables and settings in base.py to enable/disable webhooks for Gmail, Calendar, and YouTube, configure webhook URLs, and set watch renewal intervals.
  • Expanded OAuth scopes in base.py to include YouTube read-only and force-ssl permissions, required for YouTube webhook support.

Celery Beat Scheduling Updates:

  • Updated the Celery beat schedule in celery.py to:
    • Comment out polling tasks for Google Calendar and YouTube now that webhooks are enabled.
    • Add scheduled tasks for renewing Google watches and ensuring YouTube subscriptions remain active.
    • Add status messages for Google webhook activation and remove Twitch polling logic. [1] [2] [3]

Helper Function Improvements:

  • Added a get_history function to gmail_helper.py to fetch Gmail history changes since a specific history ID, supporting efficient processing of push notification events.
  • Updated the list_upcoming_events function in calendar_helper.py to allow querying a specific calendar ID, improving flexibility for multi-calendar scenarios. [1] [2] [3]

Configuration and Environment:

  • Added a BACKEND_URL setting to base.py for use as the webhook callback endpoint, supporting both development and production environments.

These changes lay the foundation for robust, scalable, and efficient event-driven integrations with Google services by leveraging push notifications and reducing unnecessary polling.

- Added GoogleWebhookWatch model to track active push notification subscriptions for Gmail, Calendar, and YouTube.
- Created views for handling incoming push notifications from Google services.
- Implemented tasks for setting up and renewing Google watches.
- Updated celery beat schedule to include tasks for renewing Google watches and setting up YouTube subscriptions.
- Added helper functions for managing Google push notifications.
- Created migrations for the new GoogleWebhookWatch model.
- Updated URLs to include endpoints for Google webhooks.
@Arkteus Arkteus requested a review from Copilot November 2, 2025 14:10
@Arkteus Arkteus marked this pull request as draft November 2, 2025 14:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive YouTube integration support to the automation platform, including webhook-based push notifications for real-time video updates. The implementation leverages Google OAuth for authentication and introduces YouTube actions (new video monitoring, channel stats, video search) and reactions (post comment, add to playlist, rate video).

Key changes:

  • Added YouTube service with 3 actions and 3 reactions for video automation
  • Implemented Google webhook infrastructure for Gmail, Calendar, and YouTube push notifications
  • Created database model for tracking Google webhook watches with automatic renewal
  • Updated OAuth configuration to include YouTube scopes

Reviewed Changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
mobile/lib/utils/service_token_mapper.dart Maps YouTube service to Google OAuth token
frontend/src/pages/ServiceDetail.tsx Adds YouTube to OAuth providers and displays webhook banner
frontend/src/pages/Debug.tsx Simplified webhook trigger text
frontend/src/components/GoogleWebhookBanner.tsx New component displaying webhook status for Google services
backend/users/oauth_views.py Auto-triggers Google webhook setup after OAuth connection
backend/scripts/test_google_webhooks.py Infrastructure test script for Google webhooks
backend/automations/webhooks.py Added YouTube webhook verification and event extraction
backend/automations/validators.py Added YouTube action/reaction schemas and improved error messages
backend/automations/urls.py Registered dedicated Google webhook endpoints
backend/automations/tasks.py Added YouTube/Calendar polling tasks and Google watch management
backend/automations/serializers.py Updated service configuration with YouTube logo and OAuth mapping
backend/automations/models.py New GoogleWebhookWatch model for tracking push notification subscriptions
backend/automations/migrations/0012_google_webhook_watch.py Migration for GoogleWebhookWatch model
backend/automations/management/commands/init_services.py YouTube service definition with actions/reactions
backend/automations/helpers/youtube_helper.py YouTube Data API v3 helper functions
backend/automations/helpers/google_webhook_helper.py Google webhook creation/management utilities
backend/automations/helpers/gmail_helper.py Added history API support for Gmail webhooks
backend/automations/helpers/calendar_helper.py Added calendar_id parameter for multi-calendar support
backend/automations/google_webhook_views.py Dedicated webhook receivers for Gmail/Calendar/YouTube
backend/area_project/settings/base.py YouTube OAuth scopes and webhook configuration
backend/area_project/celery.py Scheduled tasks for watch renewal and YouTube subscriptions
.env.example Formatting fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/automations/google_webhook_views.py Outdated
Comment thread backend/automations/helpers/google_webhook_helper.py Outdated
Comment thread backend/automations/helpers/google_webhook_helper.py
Comment thread backend/automations/tasks.py
Comment thread backend/automations/tasks.py
@Arkteus Arkteus marked this pull request as ready for review November 2, 2025 14:23
@SantiagoPidji SantiagoPidji self-requested a review November 2, 2025 14:24
@SantiagoPidji SantiagoPidji added this to the Final Product Defense milestone Nov 2, 2025

@SantiagoPidji SantiagoPidji left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@SantiagoPidji SantiagoPidji merged commit 7db897a into main Nov 2, 2025
6 checks passed
@SantiagoPidji SantiagoPidji deleted the add-youtube branch November 2, 2025 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants