Skip to content

Commit

Permalink
Add endpoints to readme, adjust timestamp to be seconds instead of mi…
Browse files Browse the repository at this point in the history
…croseconds
  • Loading branch information
msmhome committed Aug 5, 2024
1 parent 01f3cc4 commit d934e12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img align="right" width="400" height="400" src="https://i.imgur.com/pCU81k6.png">

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**
Expand All @@ -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_<first_5_chars_of_telnyx_fax_id>_from_+12015551234_at_<timestamp>.pdf`.
#### Fax In
The faxes received will be saved as a PDF in the Faxes directory under the name `Fax_<first_5_chars_telnyx_fax_id>_from_+12015551234_at_<timestamp>.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_<first_5_chars_of_telnyx_fax_id>_to_+18005001234_at_<timestamp>_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_<first_5_chars_telnyx_fax_id>_to_+18005001234_at_<timestamp>_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)
Expand Down
6 changes: 3 additions & 3 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d934e12

Please sign in to comment.