This article desribes how to integrate notion with telegram. I needed to send a daily notification with all my overdue contacts from my notion CRM table. The article assumes you understand the basics of how to manage infrastructuremanage infrastructure
This article describes how you setup your work / writing environment to be productive.1 It use Obsidian to organize what I you do and write. The high-level structure are PARA folders.2 You'll crea... with CDK. The article focuses on the telgram / notion specifics.
Requirements
I have a Notion database with people I stay in touch. Inside the table I have a field Last Contacted
and Cadence days
. The formula in Status
checks if the today is later than last contect + Cadence days
. In cases that today is later it contains "Time to reach out!".
if(dateBetween(now(), prop("Last Contacted"), "days") > prop("Cadence days"), "Time to reach out!", "👍")
Everday at 8 I want to recieve a list of all overdue contacts to reach out in Telegram. The solution be cheap.
Solution
The solution is a serverless cron job that triggers a lambda fuction that get the overdue contacts through the notion api and send the notifications to the telegram bot and the bot then sends this to me.
Project Setup
Follow manage infrastructuremanage infrastructure
This article describes how you setup your work / writing environment to be productive.1 It use Obsidian to organize what I you do and write. The high-level structure are PARA folders.2 You'll crea... up to "Implement Code and Use Level 2/3 Contructs (Add an AWS Lambda Function to Your Stack)" to:
- init repo,
- create cdk template,
- authenticate and bootstrap
Implement the Cron Job
Next remove the sample cdk resources and add the cronjob based on AWS Eventbridge:
Add Integration Lambda Function
Next add an Lambda function that contains the integration, including stubs for the function to get theget_contacts_overdue
(from Notion) and send_message
(to Telegram). Trigger this lambda function from the cron job. First install a new new dependency with pip install aws_cdk.aws_lambda_python_alpha && pip freeze > requirements.txt
Then Get the Overdue Contacts From the Notion Api (registration, Code, query)
Next register and api client ("integration") with notion and write down the api key
Then give the app permission to access the table: Find the table id
Then add the notion client implement the business logic to query the database for the overdue contacts. In this cases this means that the collumn Status contains Time to reach out!1
pip install pytest notion-client && pip freeze > requirements.txt
Then Send the Overdue Contacts to Telegram (registration, Code to Build requests)
Register a bot, as a result you get a botKey, find out the userId you want to send to and then create an REST request to send a message to the bot that is then send to the user.2 Then you implement this into the integration lambda function. After the function collected the overdue contacts with names and links, create a text to send to the telegrambot. In that request add the botKey and the userId and telegram then sends the message to the user.
Replace Environment Variables with AWS Systems Manager Paramter Store
Replace the environment variables with paramters from AWS SSM. SSM has the benefit you can encrypt. To access SSM you need to boto3:
pip install boto3 && pip freeze > requirements.txt
Then you manually create the paramters in SSM (currently you can create encrypted SSM paramter with CDK): See manage infrastructuremanage infrastructure
This article describes how you setup your work / writing environment to be productive.1 It use Obsidian to organize what I you do and write. The high-level structure are PARA folders.2 You'll crea... (Store Credentials Securly Using SSM).