A notion integration that synchronizes my Dikata Agenda & Notes notion database with my google calendar.
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:
- Create new notion page <-> Create new google calendar event
- Update notion page <-> Update google calendar event
- Update notion page progress to cancelled <-> Delete google calendar event
- Update notion page date -> Update notion page progress
- Update google event date -> Update notion page progress
- 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.
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:
"Name"
:title
"Date"
:date
"Progress"
:select
"Summary"
:rich_text
"Type"
:select
Just make a notion database with that schema and pass in the database id as an environment variable later.
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 the listDikataEvents
and isDikataEvent
helper)process.env.GOOGLE_CALENDAR_EVENTS_FILTER
value.
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).
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
- 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.
- When everything is set, the integration should start running by starting the watchers.
- 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 inv2.0.0
to make the integration a bit more flexible.
- The mongo database will act as a memo that stores sync information about a page
and its respective event using the
- 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).