🔁 Sync Google Calendar events to Discord Scheduled Events.
🤖 Designed to run as a scheduled job in GitHub Actions as a GitHub Action.
# .github/workflows/calsync.yml
name: calsync
on:
schedule:
- cron: "0 * * * *" # hourly
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
name: 🔁 Sync Events
steps:
- uses: acm-uic/calsync@main
with:
discord-guild-id: ${{ secrets.DISCORD_GUILD_ID }}
discord-bot-token: ${{ secrets.DISCORD_BOT_TOKEN }} # needs "bot" scope and "View Channels", "Manage Events", "Create Events" bot permissions. permissions=17600775980032
discord-application-id: ${{ secrets.DISCORD_APPLICATION_ID }}
google-calendar-id: ${{ secrets.GOOGLE_CALENDAR_CALENDAR_ID }}
google-service-account-key-json: ${{ secrets.GOOGLE_CALENDAR_SERVICE_ACCOUNT_KEY_JSON }} # either use google-api-key or google-service-account-key-json
google-api-key: ${{ secrets.GOOGLE_CALENDAR_API_KEY }} # either use google-api-key or google-service-account-key-json
The program fetches upcoming events using the Google Calendar API and then create or updates (events are mapped using the Google calendar event link in the Discord event's description) events if necessary.
The remaining events in Discord that were created by the bot are removed.
Refer to .env.example for configuration options. Configuration can be set either in system environment
variables or in .env.
file in the root of the repository.
The Discord bot needs "Read Messages/View Channels", "Manage Events" permissions.
- Enable the Google Calendar API for the Google Cloud project.
- Create a service account and download the JSON key.
- Credentials -> Create Credentials -> Service Account -> JSON key
- In Step 2 (Grant this service account access to project): Add "Service Account Token Creator" role
- After creation, click on the service account, go to "Keys" tab, and create a new JSON key.
- Save the JSON key as a secret in the GitHub repository.
- Share the Google Calendar with the service account email. "Settings and sharing" -> "Share with specific people" -> Add the service account email. Give it "See all event details" permission.