项目作者: umahmood

项目描述 :
Clockwork a Go library which sends SMS messages using the Clockwork SMS service.
高级语言: Go
项目地址: git://github.com/umahmood/clockwork.git
创建时间: 2017-02-24T15:38:39Z
项目社区:https://github.com/umahmood/clockwork

开源协议:MIT License

下载


Clockwork

Clockwork is a Go library which allows you to send SMS messages using the Clockwork SMS service.

Installation

Requires Go version 1.7+.

$ go get github.com/umahmood/clockwork

$ cd $GOPATH/src/github.com/umahmood/clockwork

$ go test ./…

Usage

Send an SMS message:

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/umahmood/clockwork"
  5. )
  6. func main() {
  7. cw := clockwork.New("API-KEY")
  8. msg := clockwork.SMS{
  9. To: clockwork.Numbers{"44123456789", "44987654321"},
  10. From: "Gopher",
  11. Content: "Gophers rule!",
  12. }
  13. resp, err := cw.Send(msg)
  14. if err != nil {
  15. // ...
  16. }
  17. // print each valid number an SMS was sent to and its assigned message id
  18. for num, meta := range resp {
  19. fmt.Println(num, meta["ID"])
  20. }
  21. }

Delivery receipts let you know whether a message has been delivered:

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/umahmood/clockwork"
  5. )
  6. func OnDeliveryReceipt(r clockwork.Receipt) {
  7. if r.Err != nil {
  8. //...
  9. }
  10. fmt.Println("ID", r.ID, "Status", r.Status, "To", r.To, "Time", r.Time)
  11. }
  12. func main() {
  13. clockwork.DeliveryReceiptListen(&clockwork.ReceiptHandler{
  14. Path: "/receipts",
  15. Port: 9090,
  16. Callback: OnDeliveryReceipt,
  17. })
  18. }

Output:

  1. ID LA_422342 Status Enroute To 441234567890 Time 2017-03-17 17:21:27.667238018 +0000 UTC

Documentation

http://godoc.org/github.com/umahmood/clockwork

License

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