Skip to content

πŸ” Example FastAPI webhook processor - demonstrates registration, HMAC validation, and payload handling.

License

Notifications You must be signed in to change notification settings

android-sms-gateway/example-webhooks-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± Example SMS Webhook Processor (FastAPI)

Example License Python FastAPI

⚠️ Example Project Notice
Not intended for production use without proper security review and modifications.

πŸ“‹ Table of Contents

✨ About The Project

Example Project Features:

  • 🧩 Demonstrates webhook registration/deregistration lifecycle
  • πŸ” Example HMAC signature validation implementation
  • πŸ“ Sample payload validation using Pydantic models

πŸ› οΈ Built With

  • πŸš€ FastAPI - Modern Python web framework
  • βœ”οΈ Pydantic - Data validation and settings management
  • 🌐 HTTPX - Async HTTP client
  • ⚑ UVicorn - ASGI server

⚠️ Important Notes

This example intentionally omits:

  • Production-grade error handling
  • Rate limiting
  • Persistent storage integration
  • Advanced security features

Recommended for:

  • πŸ§ͺ Testing SMS Gate webhook integration
  • πŸŽ“ Learning FastAPI webhook implementations

πŸš€ Getting Started

πŸ“¦ Prerequisites

  • Python 3.9+ (development environment)
  • Valid SSL certificate (project's CA available) or reverse proxy (like ngrok)
  • SMS Gate credentials

⚑ Installation

  1. Clone the example repository:

    git clone https://github.com/android-sms-gateway/example-webhooks-fastapi.git
    cd example-webhooks-fastapi
  2. Install development dependencies:

    pip install -r requirements.txt
    # or
    pipenv install
  3. Create example environment file:

    cp .env.example .env

βš™οΈ Configuration

Example .env configuration:

# πŸ”‘ Example SMS Gate API Credentials
SMS_GATE_API_URL="https://api.sms-gate.app/3rdparty/v1" # API root endpoint (optional)
SMS_GATE_API_USERNAME="test_user"                       # API username
SMS_GATE_API_PASSWORD="test_password"                   # API password

# πŸ”’ Example Webhook Security
WEBHOOK_SECRET="your_test_secret_here"                      # signing key (optional)
WEBHOOK_URL="https://localhost:8443/webhook/sms-received"   # current server endpoint

# πŸ›‘οΈ SSL Configuration
SSL_CERT_PATH="./certs/server.crt"  # SSL certificate (optional)
SSL_KEY_PATH="./certs/server.key"   # SSL private key (optional)

πŸ–₯️ Usage

Run the example server:

python main.py

Expected output:

INFO:     Started server process [42516]
INFO:     Waiting for application startup.
Registered webhook with ID: mIv93KBZgaFNGrhl_ivk9
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
Received SMS:
SIM: 1
From: 6505551212
Message: Android is always a sweet treat!
Received at: 2025-04-15 12:28:01+07:00
INFO:     169.150.246.92:0 - "POST /webhook/sms-received HTTP/1.1" 200 OK
^CINFO:     Shutting down
INFO:     Waiting for application shutdown.
Unregistered webhook ID: mIv93KBZgaFNGrhl_ivk9
INFO:     Application shutdown complete.
INFO:     Finished server process [42516]

πŸ“š API Reference

POST /webhook/sms-received

Example Request:

curl -X POST https://localhost:8443/webhook/sms-received \
  -H "X-Signature: abc123..." \
  -H "X-Timestamp: 1690123456" \
  -d @sample_payload.json

Example Response:

{
  "status": "ok"
}

🀝 Contributing

This example project welcomes contributions to:

  • Improve documentation
  • Demonstrate additional features
  • Enhance example security implementations

πŸ“œ License

This example code is released under Apache License 2.0.

About

πŸ” Example FastAPI webhook processor - demonstrates registration, HMAC validation, and payload handling.

Topics

Resources

License

Stars

Watchers

Forks

Languages