Skip to main content

No project description provided

Project description

fastapi-security-telegram-webhook

Plugin for FastAPI which allows you secure your Telegram Bot API webhook endpoint with IP restriction and optional secret token.

How to use

Use pip or another package management util:

pip install fastapi-security-telegram-webhook

or

poetry add fastapi-security-telegram-webhook

or

pipenv install fastapi-security-telegram-webhook

Package contains two Security objects:

  • OnlyTelegramNetwork allows request only from telegram subnets
  • OnlyTelegramNetworkWithSecret additionally check secret in path

Example with OnlyTelegramNetworkWithSecret. Pay attention to {secret} in path operation, it's required

from fastapi import FastAPI, Body, Depends
from fastapi_security_telegram_webhook import OnlyTelegramNetworkWithSecret

app = FastAPI()
webhook_security = OnlyTelegramNetworkWithSecret(real_secret="your-secret-from-config-or-env")

# {secret} in path and OnlyTelegramNetworkWithSecret as dependency:
@app.post('/webhook/{secret}', dependencies=[Depends(webhook_security)])
def process_telegram_update(update_raw = Body(...)):
   ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page