An open API service indexing awesome lists of open source software.

https://github.com/levintoo/mock-sms-server


https://github.com/levintoo/mock-sms-server

api laravel webhook-server

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# ๐Ÿ“ก Mock SMS Server

A mock SMS gateway built with Laravel to simulates sending and delivering SMS messages with status updates and webhook notifications โ€” for local and staging environments.

## ๐Ÿš€ Features

- ๐Ÿ“ค Simulate message sending (single or bulk)
- ๐Ÿ“ฆ Message statuses: `queued`, `sent`, `delivered`, `failed`
- ๐Ÿ” Automatic status progression via jobs
- ๐Ÿ“ก Webhook dispatching for each status update
- ๐Ÿ” Simple Bearer token authentication (`test-key`)
- ๐Ÿงช Supports JSON and form-data requests
- โณ Intelligent webhook polling (up to 24 hours)

## ๐Ÿ“ฆ Installation

Clone the repository

```bash
git clone git@github.com:levintoo/mock-sms-server.git
cd mock-sms-server
````

Install PHP dependencies
```bash
composer install
````

Copy environment file and generate app key
```bash
cp .env.example .env
php artisan key:generate
````

(Required) Set your webhook endpoint in .env
```bash
SMS_WEBHOOK=
````

Run database migrations
```bash
php artisan migrate
````

Start a queue worker
```bash
php artisan queue:work --tries=3 --backoff=3
````

## ๐Ÿ” Authentication

Use a fixed Bearer token for all requests:

```
Authorization: Bearer test-key
```

## ๐Ÿ“ค Sending Messages

### Endpoint

```
POST /api/message
```

### Request Formats

#### โœ… JSON (application/json)

```js
{
"to": "254700123123", // or ["254700123123", "254711456789"] for queued bulk
"message": "Hello world!"
}
```

#### โœ… Form-Data (multipart/form-data)

```js
to: "254700123123",
// or for queued bulk
// to[] = 254700123123
// to[] = 254711456789
message = "Hello world!"
```

### Validation Rules

| Field | Type | Description |
| --------- | --------------- | --------------------------------------- |
| `to` | string or array | International phone number(s), required |
| `message` | string | Message body, required |

## ๐Ÿ“ฌ Message Status Lifecycle

Messages transition through the following statuses:

```php
enum MessageStatus: string {
case Queued = 'queued';
case Sent = 'sent';
case Delivered = 'delivered';
case Failed = 'failed';
}
```

## ๐Ÿ“ก Webhook Configuration

Set your webhook URL in `.env`:

```
SMS_WEBHOOK=https://your-app.test/webhook
```

### Webhook Payload

```js
{
'event' => ...,
'data' => [
...
],
}
```

## ๐Ÿ” Webhook Retry Strategy

* โฑ **Every 5 seconds** for 1 minute
* โฑ **Every 1 minute** for 5 minutes
* โฑ **Every 5 minutes** for 55 minutes
* โฑ **Every hour** until 24 hours total
* โŒ **Stop retrying** after 24 hours

Polling stops once a `200 OK` response is received.

## ๐Ÿงต Job Classes

| Job Class | Description |
| ------------------------ | -------------------------------------------- |
| `MockMessageSendJob` | Simulates transition to `sent` |
| `MockMessageDeliveryJob` | Simulates transition to `delivered`/`failed` |
| `PollDeliveryWebhookJob` | Polls the webhook URL |