⚠️ Project in progress
This project implements a Telegram bot, which interacts with a Notion database through its API to provide certain information to users.
The bot is implemented with a serverless architecture, leveraging AWS services. Instead of having a long-running process poll the Telegram servers for updates, EscultoideBot configures a webhook and then processes the Telegram events on arrival through Lambda functions. This allows for seamless scaling from zero requests to a massive scale, without incurring in costs when the bot is not being used.
This repository contains both the runtime code for the Lambda functions themselves, and the CDK code that defines the infrastructure they run on.
CDK deals with provisioning the infrastructure and deploying the runtime code, so only a few steps must be taken to run this project.
- AWS account that has been bootstrapped
- Workstation configured with your AWS credentials and region
- Clone or download the project folder, and change to its directory:
$ git clone https://github.com/dieortin/escultoide-bot
$ cd escultoide-bot
- Install the required packages:
$ pip install -r requirements.txt
-
Create two secrets in AWS Secrets Manager, with the API keys to be used for Telegram and Notion.
-
Modify the configuration values in
app.py
to match the names for your secrets in AWS Secrets Manager, and the ID of your Notion database. -
Deploy the application:
$ cdk deploy
The project's backend consists on two main components:
This construct receives and processes updates from Telegram. It consists on two components:
- A Lambda function that processes new Telegram updates
- An API Gateway, which receives HTTP requests from Telegram, invokes the Lambda and responds
This construct manages the Telegram API configuration so that updates are sent to the API.
It consists on a custom resource that represents the configured webhook for the bot in the Telegram API. It manages setting the webhook to the URL of the API so that it can receive updates, and removing it when the component is deleted.
This custom resource has a Lambda function that performs the required actions when lifecycle changes are made to it.