From d934e12d3fad177d14cf4b46e9c670fa40b72ef6 Mon Sep 17 00:00:00 2001 From: msmhome <143322410+msmhome@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:58:17 -0400 Subject: [PATCH] Add endpoints to readme, adjust timestamp to be seconds instead of microseconds --- README.md | 14 ++++++++------ server.py | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e9b54b5..202b69c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -A tiny, ready to deploy, simple fax and SMS receive server running on the Telynx Programmable Fax and SMS APIs. +A tiny, ready to deploy, simple fax and SMS receive server running on the Telynx Programmable Fax and SMS SDK/APIs. This is built around my use case and homelab but is versatile to be deployed as-is for yours or be used in something more complex. * **Fax Inbound and Outbound w/ Confirmations** @@ -23,20 +23,22 @@ miniFaxServer revolves around the /Faxes directory. Faxes and SMS messages recei Add your own IP ranges to the .env whitelist. The default entries are for Telnyx's servers and should not be changed. Try host 0.0.0.0 if you encounter problems with whitelist due to cloudflared showing internal IPs. -#### Fax In +Endpoints exposed: +* `/telnyx-webhook` The webhook Telnyx will primarily send fax-related messages to +* `/sms` The webhook Telnyx will use for SMS messages +* `/status` Will post a `{"status":"ONLINE"}` for uptime monitoring -The faxes received will be saved as a PDF in the Faxes directory under the name `Fax__from_+12015551234_at_.pdf`. +#### Fax In +The faxes received will be saved as a PDF in the Faxes directory under the name `Fax__from_+12015551234_at_.pdf`. It's recommended to enable the feature to email faxes in the Telnyx web GUI (it's free). #### Fax Out - -Put any PDF files to be sent out in the Faxes/outbound directory named as the destination phone number, excluding the country code. ie `8885550000.pdf`. This will begin an automatic process to fax that PDF, once delivered, the PDF will be moved to Faxes/outbound\_confirmations as `Fax__to_+18005001234_at__confirmed.pdf`. +Put any PDF files to be sent out in the Faxes/outbound directory named as the destination phone number, excluding the country code. ie `8885550000.pdf`. This will begin an automatic process to fax that PDF, once delivered, the PDF will be moved to Faxes/outbound\_confirmations as `Fax__to_+18005001234_at__confirmed.pdf`. (note for my use I hardcoded the US +1 country code, modify or remove this in the script as necessary) #### SMS In - SMS must be configured in the Telnyx webui and the webhook must point /sms. Your inbound texts will be saved in the Faxes directory as `SMS_from_+12015550000_at_timestamp.txt`. #### [Please submit issues here.](https://github.com/msmhome/miniFaxServer/issues) diff --git a/server.py b/server.py index 895c7e8..f253027 100644 --- a/server.py +++ b/server.py @@ -5,7 +5,7 @@ from datetime import datetime from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler -from fastapi import FastAPI, Request, Depends +from fastapi import FastAPI, Request from starlette.responses import Response from fastapi.staticfiles import StaticFiles from slowapi import Limiter, _rate_limit_exceeded_handler @@ -36,7 +36,7 @@ logging.basicConfig(level=log_level, format='%(asctime)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) -timestamp = datetime.now().strftime('%Y%m%d_%H%M%S_%f') # Using microseconds for uniqueness +timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') # Using seconds for uniqueness # Read and process whitelisted IP ranges from environment variable or use default WHITELISTED_IP_RANGES_STR = os.getenv('WHITELISTED_IP_RANGES') @@ -145,7 +145,7 @@ async def handle_sms(data: SmsData): return Response(status_code=500) @app.post("/telnyx-webhook") -@limiter.limit("100/minute") +@limiter.limit("100/minute") #Set webhook rate limit async def inbound_message(request: Request): try: body = await request.json()