Skip to content

A notion integration that synchronizes Dikata Agenda & Notes database with my google calendar

License

Notifications You must be signed in to change notification settings

ElysMaldov/dikata-google-calendar-notion-integration

Repository files navigation

dikata-google-calendar-notion-integration

A notion integration that synchronizes my Dikata Agenda & Notes notion database with my google calendar.

What is It

This integration will synchronize new, deleted and updated pages in the notion database with google calendar and vice-versa.

The main features of this integration are:

  1. Create new notion page <-> Create new google calendar event
  2. Update notion page <-> Update google calendar event
  3. Update notion page progress to cancelled <-> Delete google calendar event
  4. Update notion page date -> Update notion page progress
  5. Update google event date -> Update notion page progress
  6. Delete notion page -> Delete google calendar event

When updating a page, only the Name, Date and Progress property are considered by this integration.

When updating a google calendar event, only the Summary/Title of the event and the start & end time are considered by this integration.

Target Database & Calendar

Notion Database Schema

This integration was specifically made for my "dikata agenda and notes" notion database and the calendar events that are targeted by this integration are the ones whose title starts with "Dikata:" or "dikata" a string stored in process.env.GOOGLE_CALENDAR_EVENTS_FILTER case-insensitive (more on this later).

But, this integration should target any notion database that has the same database property schema as the one I'm using:

Checkout notion database properties here

  1. "Name" : title
  2. "Date" : date
  3. "Progress" : select
  4. "Summary" : rich_text
  5. "Type" : select

Just make a notion database with that schema and pass in the database id as an environment variable later.

Google Calendar

For the calendar, this integration should not target any specific kind of google calendar. You just need to pass in your OAuth2 token later as an environment variable and start any google calendar event title with "Dikata:" or "dikata" the string stored in process.env.GOOGLE_CALENDAR_EVENTS_FILTER case-insensitive (more on this later).

To change how the integration detects these specific events when the google watcher runs for the first time, you can change codes that detects "Dikata" infront of the event title (like in listDikataEvents and isDikataEvent helper) the process.env.GOOGLE_CALENDAR_EVENTS_FILTER value.

Summarized Integration Logic

Helpers & Controllers

Provided in the source code are some JSDOCumented controllers and helpers that allows this integration's operations to be simplified, reusable and modular. Most of the helpers and controllers handle the CRUD operations this integration does, but there are some other useful ones like RFC3339 date formatters that the google calendar API needs and the Watcher class.

You should take a look around to see if it can help you understand how this integration works or create new features by reusing some of the existing helpers and controllers (Sorry if my documentations are not good tho :P).

Environment Variables

This project uses some environment variables which you should provide (although I can't guarantee that everything is used since I already forgot :D):

PATH_TO_ENV
PORT
MONGODB
NOTION_INTERNAL_INTEGRATION_TOKEN
NOTION_AGENDA_DB_ID
NOTION_SELECTION_PROGRESS_CANCELLED
NOTION_SELECTION_PROGRESS_DONE
NOTION_SELECTION_PROGRESS_IN_PROGRESS
NOTION_SELECTION_PROGRESS_NOT_YET
NOTION_SELECTION_TYPE_DEPARTMENT_MEETING
NOTION_SELECTION_TYPE_ORGANIZATION_MEETING
GOOGLE_CALENDAR_PRIMARY_CALENDARID
GOOGLE_CALENDAR_SERVICE_ACC_KEY
GOOGLE_CALENDAR_OAUTH2_PAT
GOOGLE_CALENDAR_OAUTH2_CB
GOOGLE_CALENDAR_OAUTH2_CLIENT_ID
GOOGLE_CALENDAR_OAUTH2_CLIENT_SECRET
GOOGLE_CALENDAR_OAUTH2_ACCESS_TOKEN
GOOGLE_CALENDAR_OAUTH2_REFRESH_TOKEN
NOTION_DIKATA_AGENDA_WATCHER_MS
GOOGLE_EVENTS_WATCHER_MS
GOOGLE_CALENDAR_EVENTS_FILTER

How it Works (sort of)

  1. Add environment variables
    • For the google oauth2 tokens, you need to authenticate through a browser (I know sucks right) and get the access & refresh token to store as environment variables. This integration provides helpers for this.
  2. When everything is set, the integration should start running by starting the watchers.
  3. The first time the watchers start, they will scan through the database and calendar once to initialize a synchronization between database, calendar and out database.
    • The mongo database will act as a memo that stores sync information about a page and its respective event using the PageEvent model.
    • On the first calendar scan, the events that will be included are the ones whose title starts with "Dikata:", but the synchronization that happens after this initial one can also detect events whose title starts with "dikata" case-insensitive.
    • The events that will be included are the ones whose title starts with the string stored in process.env.GOOGLE_CALENDAR_EVENTS_FILTER case-insensitive. This behavior was updated in v2.0.0 to make the integration a bit more flexible.
  4. After that, the watchers will keep running every ms to keep synchronizing the database and calendar.

⚠️
Once this integration starts running, you should be careful about changing the mongo collection as to not cause unexpected behavior
⚠️

Sometimes you'll see some errors being logged when this integeration is running. But from personal testing, most of them should be harmless (I hope).

About

A notion integration that synchronizes Dikata Agenda & Notes database with my google calendar

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published