diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..2c6bf00 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,15 @@ +class PagesController < ActionController::Base + layout "public" + protect_from_forgery with: :exception + + # GET / + # Public landing page introducing the SMS Gateway API. + def home + end + + # GET /docs + # Interactive API documentation covering every endpoint, the WebSocket + # protocol, webhooks, authentication, rate limits, and error codes. + def docs + end +end diff --git a/app/views/layouts/public.html.erb b/app/views/layouts/public.html.erb new file mode 100644 index 0000000..5be8de7 --- /dev/null +++ b/app/views/layouts/public.html.erb @@ -0,0 +1,273 @@ + + +
+ + +Reference
+Every endpoint, parameter, and response for the MySMSAPio SMS Gateway. All routes are prefixed with /api/v1.
The MySMSAPio API is a JSON REST API. There are two classes of consumer:
+api_live_… key.gw_live_… key.Base URL
+https://your-host/api/v1
+ Content-Type
+application/json
+ All authenticated endpoints expect an API key in the Authorization header as a Bearer token. Keys are SHA-256 hashed at rest — the raw key is only shown once at creation.
api_live_<64 hex chars>
+ Permissions-based (send_sms, receive_sms…). Can expire.
+gw_live_<64 hex chars>
+ Bound to a single gateway device. Must be active.
+Limits are enforced via Redis and return 429 Too Many Requests with a retry_after hint.
| Resource | +Limit | +Window | +
|---|---|---|
| Send SMS | 100 | per minute / API key |
| Send OTP | 3 | per hour / phone number |
| OTP verify attempts | 3 | per code |
Errors are returned as JSON with an error field. Validation errors also include details.
| Status | +Meaning | +
|---|---|
| <%= code %> | +<%= meaning %> | +
/sms/send
+ Queues an outbound message. The API returns immediately with a message_id; delivery happens asynchronously via an available gateway. Rate limited to 100/min per API key.
Request body
+| Parameter | +Type | +Required | +Description | +
|---|---|---|---|
| to | string | yes | E.164 phone number (validated via Phonelib) |
| message | string | yes | Message body (max 1600 chars) |
Example request
+Response · 202 Accepted
+/sms/status/:message_id
+ Returns the current lifecycle state of a message, including timestamps.
+ +Path parameters
+| Parameter | +Type | +Description | +
|---|---|---|
| message_id | string | The ID returned when the message was created |
Response · 200 OK
+Statuses: queued → pending → sent → delivered | failed
/sms/received
+ Paginated list of inbound messages, newest first. Optional filters by phone number or date.
+ +Query parameters
+| Parameter | +Type | +Default | +Description | +
|---|---|---|---|
| phone_number | string | — | Filter by sender phone |
| since | datetime | — | Only messages after this time |
| limit | integer | 50 | Items per page |
Response · 200 OK
+/otp/send
+ Generates a 6-digit code, sends it via SMS, and returns the expiry time. Max 3 codes per phone per hour.
+ +Request body
+| Parameter | +Type | +Required | +Default | +
|---|---|---|---|
| phone_number | string | yes | — |
| purpose | string | no | authentication |
| expiry_minutes | integer | no | 5 |
Response · 200 OK
+/otp/verify
+ Validates the 6-digit code. After 3 failed attempts the code is expired. On success the code is marked verified and cannot be reused.
+ +Request body
+| Parameter | +Type | +Required | +
|---|---|---|
| phone_number | string | yes |
| code | string | yes |
Success · 200
+Failure · 200
+/admin/stats
+ Aggregate system metrics: gateway counts, message throughput, pending/failed counts, and OTP performance for today.
+ +Response · 200 OK
+/admin/gateways
+ Returns every registered gateway device with live status and counters.
+ +/admin/gateways/:id/toggle
+ Activate or deactivate a gateway. Toggling off stops it from receiving outbound commands.
+ +Toggle response · 200 OK
+/gateway/register
+ No auth Registers an Android device and returns a fresh gateway API key. Returns 409 if the device_id already exists.
Request body
+| Parameter | +Type | +Required | +Description | +
|---|---|---|---|
| device_id | string | yes | Unique device identifier |
| name | string | no | Friendly name (defaults to device id prefix) |
Response · 201 Created
+ Save api_key immediately — it is never shown again.
/gateway/heartbeat
+ Refreshes the gateway's online status. A gateway is marked offline if no heartbeat arrives within 2 minutes (handled by CheckGatewayHealthJob).
Optional body
+| Parameter | +Type | +Description | +
|---|---|---|
| battery_level | integer | 0–100 |
| signal_strength | integer | dBm |
| messages_in_queue | integer | Pending outbound count on device |
Response · 200 OK
+/gateway/sms/received
+ Called by the gateway when a new SMS arrives on the device. Creates an inbound record and triggers ProcessInboundSmsJob (which fires webhooks).
Request body
+| Parameter | +Type | +Required | +
|---|---|---|
| sender | string | yes |
| message | string | yes |
| timestamp | datetime | no |
Response · 200 OK
+/gateway/sms/status
+ Updates an outbound message's status. On failed, RetryFailedSmsJob is enqueued if retries remain (< 3).
Request body
+| Parameter | +Type | +Required | +Values | +
|---|---|---|---|
| message_id | string | yes | — |
| status | string | yes | sent · delivered · failed |
| error_message | string | no | Reason for failure |
Response · 200 OK
+/cable
+ Gateways maintain a persistent Action Cable connection for real-time command dispatch and status reporting. Connections authenticate with the gateway API key as a query param.
+ +Connect
+Server → Gateway commands
+Gateway → Server events
+| action | +Payload | +
|---|---|
| heartbeat | battery_level, signal_strength, messages_in_queue |
| delivery_report | message_id, status, error_message |
| message_received | sender, message, timestamp |
Outbound HTTP POST
+ When configured, the API delivers signed event payloads to your URL via TriggerWebhookJob. If a secret key is set, each request is signed with HMAC-SHA256.
<%= e[:event] %>
+ <%= e[:desc] %>
+Example payload (sms_received)
+Verifying the signature
++ A production-grade REST & WebSocket API that turns any Android phone into a + programmable SMS gateway. Send messages, generate OTPs, receive inbound texts, + and orchestrate fleets of devices in real time. +
+ +https://<your-host>/api/v1
+
+ Capabilities
+From a single device to a distributed fleet — message queuing, delivery tracking, and OTP workflows are built in.
+<%= f[:desc] %>
+Architecture
+A clean, asynchronous pipeline keeps the API fast and delivery resilient.
+<%= s[:desc] %>
+Quick Start
+No auth required — receive a gateway API key back.
+Keep the device online and ready to receive commands.
+Use a client API key (api_live_…) in the Authorization header.
+Built on a modern stack
+Dive into the complete API reference or jump straight into the admin console to manage your gateways.
+