Skip to content
This repository has been archived by the owner on Dec 17, 2019. It is now read-only.
/ smsender Public archive

A Go server for sending SMS

License

Notifications You must be signed in to change notification settings

minchao/smsender

Repository files navigation

SMSender

Build Status Go Report Card

A SMS server written in Go (Golang).

  • Support various SMS providers.
  • Support routing, uses routes to determine which provider to send SMS.
  • Support command line to send a single SMS.
  • Support to receive delivery receipts from provider.
  • SMS delivery worker.
  • SMS delivery records.
  • RESTful API.
  • Admin Console UI.

Requirements

  • Go >= 1.11
  • MySQL >= 5.7

Installing

Getting the project:

go get github.com/minchao/smsender

Using the Dep to install dependency packages:

dep ensure

Creating a Configuration file:

cp ./config/config.default.yml ./config.yml

Setup the MySQL DSN:

store:
  name: "sql"
  sql:
    driver: "mysql"
    dsn: "user:password@tcp(localhost:3306)/dbname?parseTime=true&loc=Local"

Registering providers on the sender server.

Add the provider key and secret to config.yml:

providers:
  nexmo:
    key: "NEXMO_KEY"
    secret: "NEXMO_SECRET"

Build:

go build -o bin/smsender

Run:

./bin/smsender

Running smsender server in docker container

You can use the docker-compose to launch the preview version of SMSender, It will start the app and db in separate containers:

docker-compose up

Vagrant development environment

Start the vagrant machine

vagrant up

SSH into the vagrant machine

vagrant ssh

Run the smsender server

go run main.go -c config/config.yml

Providers

Support providers

Need another provider? Just implement the Provider interface.

Routing

Route can be define a regexp phone number pattern to be matched with provider.

Example:

Name Regular expression Provider Description
Dummy \+12345678900 dummy For testing
User1 \+886987654321 aws For specific user
Taiwan \+886 nexmo
USA \+1 twilio
Default .* nexmo Default

Commands

./bin/smsender -h
A SMS server written in Go (Golang)

Usage:
  smsender [flags]
  smsender [command]

Available Commands:
  help        Help about any command
  routes      List all routes
  send        Send message

Flags:
  -c, --config string   Configuration file path
  -d, --debug           Enable debug mode
  -h, --help            help for smsender

Use "smsender [command] --help" for more information about a command.

Example of sending a single SMS to one destination

./bin/smsender send --to +12345678900 --from Gopher --body "Hello, 世界" --provider dummy

RESTful API

The API document is written in YAML and found in the openapi.yaml. You can use the Swagger Editor to open the document.

Example of creating a Dummy route

Request:

curl -X POST http://localhost:8080/api/routes \
    -H "Content-Type: application/json" \
    -d '{"name": "Dummy", "pattern": "\\+12345678900", "provider": "dummy", "is_active", true}'

Response format:

{
  "name": "Dummy",
  "pattern": "\\+12345678900",
  "provider": "dummy",
  "from": "",
  "is_active": true
}

Example of sending a single SMS to one destination

Request:

curl -X POST http://localhost:8080/api/messages \
    -H "Content-Type: application/json" \
    -d '{"to": ["+12345678900"],"from": "Gopher","body": "Hello, 世界"}'

Response format:

{
    "data": [
        {
            "id": "b3oe98ent9k002f6ajp0",
            "to": "+12345678900",
            "from": "Gopher",
            "body": "Hello, 世界",
            "async": false,
            "route": "Dummy",
            "provider": "dummy",
            "provider_message_id": "b3oe98ent9k002f6ajp0",
            "steps": [
                {
                    "stage": "platform",
                    "data": null,
                    "status": "accepted",
                    "created_time": "2017-04-14T15:02:57.123202Z"
                },
                {
                    "stage": "queue",
                    "data": null,
                    "status": "sending",
                    "created_time": "2017-04-14T15:02:57.123556Z"
                },
                {
                    "stage": "queue.response",
                    "data": null,
                    "status": "delivered",
                    "created_time": "2017-04-14T15:02:57.123726Z"
                }
            ],
            "status": "delivered",
            "created_time": "2017-04-14T15:02:57.123202Z",
            "updated_time": "2017-04-14T15:02:57.123726Z"
        }
    ]
}

Admin Console UI

The Console Web UI allows you to manage routes and monitor messages (at http://localhost:8080/console/).

logs screenshot

router screenshot

License

See the LICENSE file for license rights and limitations (MIT).