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.
- Go >= 1.11
- MySQL >= 5.7
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
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
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
Support providers
Need another provider? Just implement the Provider interface.
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 |
./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.
./bin/smsender send --to +12345678900 --from Gopher --body "Hello, 世界" --provider dummy
The API document is written in YAML and found in the openapi.yaml. You can use the Swagger Editor to open the document.
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
}
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"
}
]
}
The Console Web UI allows you to manage routes and monitor messages (at http://localhost:8080/console/).
See the LICENSE file for license rights and limitations (MIT).