Watch a Notion task database and notify people through SendGrid when an existing page's Status changes.
Caution
This is a continuous process that polls Notion every 5 seconds and sends
real emails to EMAIL_TO_FIELD. Use a test database and recipient while
setting it up. The process runs until you stop it with Ctrl+C.
-
Duplicate the example task database into your workspace.
-
Create a Notion integration in the integrations dashboard, then connect it to the duplicated database.
-
Create a SendGrid API key and verify the sender address you plan to use.
-
From the repository root, install and configure the example:
cd examples/database-email-update npm install cp example.env .envFill in
.env:NOTION_KEY=<your-notion-api-key> SENDGRID_KEY=<your-sendgrid-api-key> NOTION_DATABASE_ID=<your-test-database-id> EMAIL_TO_FIELD=<test-recipient@example.com> EMAIL_FROM_FIELD=<your-verified-sender@example.com>
-
Start the watcher:
npm run ts-run
At startup, the process reads every page and stores its current Status in memory. It does not email for this initial snapshot. After the first fetch succeeds, the command stays running and checks the database every 5 seconds.
To verify it, change the Status of an existing page while the process is
running. Within about 5 seconds, the terminal reports the changed task. After
SendGrid accepts the message, it prints Email Sent with the recipient and
sender, and the recipient receives a real email.
Press Ctrl+C to stop polling. Changes made while the process is stopped are
not sent later because each restart takes a new initial snapshot.
This example expects a title property named Name and a select property named Status, as provided by the example database.
