🇬🇧 English
Notion Marketplace Webhook Handler is a robust, production-ready ASP.NET Core Web API designed to process webhooks from the Notion Marketplace.
Unlike simple scripts, this solution handles high-concurrency scenarios using a Fire-and-Forget architecture with background task queues. It ensures that Notion always receives a 200 OK response in milliseconds (<300ms), while heavy processing (such as sending confirmation emails via SMTP) happens asynchronously without blocking the main thread.
- Async Architecture: Implements IHostedService and Background Queues to prevent webhook timeouts (
Error 502/504). - Strict Typing: Custom Payload models (NotionPayload) to safely parse Unix Timestamps and optional fields.
- Email Automation: Integrated SMTP service (Gmail/Outlook) with HTML support and embedded signatures.
- Secure: Validates incoming payloads and handles webhook.test events gracefully.
- Docker Ready: Includes a multi-stage Dockerfile optimized for production (Coolify/Portainer friendly).
- .NET 10 (C#)
- ASP.NET Core Web API
- Docker (Linux Alpine images)
- System.Net.Mail for SMTP
Prerequisites
- .NET 10 SDK
- Docker (Optional)
-
Clone the repository
git clone https://github.com/lautaro-rojas/NotionMarketplaceWebhook.git cd NotionMarketplaceWebhook -
Configure Environment
Update appsettings.json or use Environment Variables (recommended for Docker):
This project is pre-configured to work seamlessly with Google Gmail SMTP.
Note: For Gmail, you cannot use your regular login password. You must generate an App Password.
{ "SMTP_FROM_NAME": "Your name", "SMTP_HOST": "smtp.gmail.com", "SMTP_PASS": "Your password", "SMTP_PORT": 587, "SMTP_USER": "Your gmail", "OWNER_EMAIL": "Your gmail" }To send emails via Gmail API securely, follow these steps:
- Go to your Google Account Security page.
- Crucial: Ensure 2-Step Verification is turned ON. App Passwords will not appear if this is off.
- In the search bar at the top, type "App passwords" and select it.
- Create a new app name (e.g., "Notion Webhook") and click Create.
- Google will generate a 16-character code (e.g., abcd efgh ijkl mnop).
- Copy this code and paste it into the "Password" field in your configuration. You don't need the spaces.
-
Run Locally
dotnet run
-
Deploy with Docker
docker build -t notion-webhook . docker run -d -p 8080:8080 --env-file .env notion-webhook
Once your server is running (either locally with a tunnel or on a VPS), you need to register the webhook URL in your Notion Marketplace settings.
URL Format: Your API endpoint is defined in the controller as /webhook.
Example: https://your-public-domain.com/webhook
Protocol: Notion requires HTTPS. Plain http:// URLs will fail with a 502 or FetchError.
Validation: When you save the URL, Notion will send a test request. If your server is configured correctly, you will see a blue checkmark ✅.
💡 Pro Tip: If you are testing locally, use a tunneling tool like ngrok or Cloudflare Tunnel to get a public HTTPS URL (e.g., https://random-id.ngrok-free.app/webhook).
If this project helped you monetize your Notion templates or saved you development time, please consider sponsoring my work! Your support allows me to maintain this repository and create more open-source tools for the Notion ecosystem.
❤️ Sponsor this project on GitHub
Notion Marketplace Webhook Handler es una API Web robusta construida con ASP.NET Core, diseñada para procesar webhooks del Notion Marketplace de manera eficiente.
A diferencia de scripts simples, esta solución implementa una arquitectura de Fire-and-Forget utilizando colas de tareas en segundo plano. Esto garantiza que Notion siempre reciba una respuesta 200 OK en milisegundos (<300ms), evitando errores de Timeout, mientras que el procesamiento pesado (como el envío de correos SMTP) se ejecuta asíncronamente sin bloquear el hilo principal.
- Arquitectura Asíncrona: Implementación de IHostedService y Background Queues para evitar Timeouts (
Error 502/504). - Tipado Estricto: Modelos personalizados (NotionPayload) para parsear correctamente Timestamps Unix y campos opcionales.
- Automatización de Emails: Servicio SMTP integrado con soporte para HTML.
- Seguro: Validación de payloads entrantes y manejo correcto de eventos webhook.test.
- Listo para Docker: Incluye un Dockerfile multi-etapa optimizado para producción (ideal para Coolify/Portainer).
- .NET 10 (C#)
- ASP.NET Core Web API
- Docker (Imágenes Linux Alpine)
- System.Net.Mail para SMTP
Requisitos
- .NET 10 SDK
- Docker (Opcional)
-
Clonar el repositorio
git clone https://github.com/lautaro-rojas/NotionMarketplaceWebhook.git cd NotionMarketplaceWebhook -
Configurar Entorno
Actualiza el appsettings.json o usa Variables de Entorno (recomendado para Docker)
Este proyecto está pre-configurado para funcionar perfectamente con Google Gmail SMTP.
Nota: Para Gmail, no puedes usar tu contraseña normal de inicio de sesión. Debes generar una Contraseña de Aplicación.
{ "SMTP_FROM_NAME": "Tu nombre", "SMTP_HOST": "smtp.gmail.com", "SMTP_PASS": "Tu contraseña", "SMTP_PORT": 587, "SMTP_USER": "Tu gmail", "OWNER_EMAIL": "Tu gmail" }Para enviar correos vía Gmail de forma segura, sigue estos pasos:
- Ve a la página de Seguridad de tu Cuenta de Google.
- Crucial: Asegúrate de que la Verificación en 2 pasos esté ACTIVADA. La opción de contraseñas de aplicación no aparecerá si esto está desactivado.
- En la barra de búsqueda superior, escribe "Contraseñas de aplicaciones" y selecciónalo.
- Escribe un nombre para la app (ej: "Notion Webhook") y haz clic en Crear.
- Google generará un código de 16 caracteres (ej: abcd efgh ijkl mnop).
- Copia este código y pégalo en el campo "Password" de tu configuración. No es necesario incluir los espacios.
-
Ejecutar Localmente
dotnet run
-
Desplegar con Docker
docker build -t notion-webhook . docker run -d -p 8080:8080 --env-file .env notion-webhook
Una vez que tu servidor esté corriendo (ya sea localmente con un túnel o en un VPS), necesitas registrar la URL del webhook en la configuración del Notion Marketplace.
Formato de URL: Tu endpoint está definido en el controlador como /webhook.
Ejemplo: https://tu-dominio-publico.com/webhook
Protocolo: Notion requiere HTTPS obligatoriamente. Las URLs con http:// fallarán con un error 502 o FetchError.
Validación: Al guardar la URL, Notion enviará una petición de prueba. Si tu servidor responde correctamente, verás un tilde azul de validación ✅.
💡 Consejo Pro: Si estás probando en tu máquina local (localhost), utiliza una herramienta de túnel como ngrok o Cloudflare Tunnel para obtener una URL pública HTTPS (ej: https://random-id.ngrok-free.app/webhook).
Si este proyecto te ayudó a monetizar tus plantillas de Notion o te ahorró tiempo de desarrollo, ¡considera patrocinar mi trabajo! Tu apoyo me permite mantener este repositorio y crear más herramientas open-source para el ecosistema de Notion.
❤️ Patrocinar este proyecto en GitHub