This project is a notification service implemented in Go, designed to handle rate-limited notifications efficiently. Currently, it implements a telegram bot given token ID and chat ID. In a next future, I will implement more services
- Rate Limiting: Implements a rate-limiting mechanism to control the frequency of notifications sent.
- HTTP Server: Includes an HTTP server to receive notification requests.
- Logging: Utilizes logging to track notification activities and errors.
- Docker Support: Provides Dockerfiles for easy deployment in containerized environments.
- Go 1.22 or higher
- Docker
- PostreSql +16
- Clone the repository.
- Install dependencies with
go mod download
. - Set up your environment variables for database connections and API keys.
- Build and run the service with
go run main.go
. - Make POST HTTP requests to
http://localhost:8080/V1/notify
to send notifications.
Create a .env file, like this one:
ENVIRONMENT=dev
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=admin
POSTGRES_DB=notifications
POSTGRES_SSL_MODE=disable
TELEGRAM_TOKEN=PUT_YOUR_CHATBOT_TOKEN_HERE
docker compose up --build
To run the service locally:
go build -o notification_service main.go
export POSTGRES_HOST=localhost # use your IP
export POSTGRES_PORT=5432
export POSTGRES_USER=postgres
export POSTGRES_PASSWORD=admin
export POSTGRES_DB=notifications
export POSTGRES_SSL_MODE=disable
go run main.go
The service exposes the following API endpoints:
-
POST /login: Get auth token. It must be refreshed every 5 min. keys: username, password
-
POST /V1/notify: Sends a notification. Requires a JSON payload with the notification details.
Currently, we have:
('STATUS', 2, EXTRACT(EPOCH FROM INTERVAL '1 minute')),
('NEWS', 1, EXTRACT(EPOCH FROM INTERVAL '1 day')),
('MARKETING', 3, EXTRACT(EPOCH FROM INTERVAL '1 hour'));
Input body
{
"recipient": "romi",
"group" :"NEWS"
}
Output:
{
"recipient": "romi",
"message": "success",
"timestamp": "0001-01-01T00:00:00Z" -- record date
}
- Monitoring (Grafana could be a good option)
- Add more restrictions for messages
- Separate by go modules
- Load balancer implementation
- Add more services (whatsapp, email, etc)
- Abstract service structs