Nudity filter for Telegram bots
Last updated Mon Nov 09 2026 00:00:00 GMT+0000 (Coordinated Universal Time)
from sfwapi import SfwApi
api = SfwApi(api_key=os.environ["SFWAPI_KEY"])
async def on_photo(update, context):
file = await update.message.photo[-1].get_file()
data = await file.download_as_bytearray()
r = api.analyze_bytes(bytes(data), policy={"block_level": 2, "block_sex_objects": True})
if r["policy"]["blocked"]:
await update.message.delete()Telegram bot downloads are capped at 20 MB, well inside the 32 MB upload limit. Animations (GIF/MP4) work the same way with max_frames=5.