Skip to content

Latest commit

 

History

History
96 lines (72 loc) · 2.54 KB

README.md

File metadata and controls

96 lines (72 loc) · 2.54 KB

go-mitake

GoDoc Go Report Card Continuous Integration codecov

go-mitake is a Go client library for accessing the Mitake SMS v2 API (Taiwan mobile phone number only).

Installation

go get -u github.com/minchao/go-mitake/v2

Usage

import "github.com/minchao/go-mitake/v2"

Construct a new Mitake SMS client, then use to access the Mitake API. For example:

client := mitake.NewClient("USERNAME", "PASSWORD", nil)

// Retrieving your account balance
balance, err := client.QueryAccountPoint(context.Background())

Send an SMS:

message := mitake.MessageParams{
    Message: Message{
        Dstaddr: "0987654321",
        Smbody:  "Message ...",
	},
}

response, err := client.Send(context.Background(), message)

Send multiple SMS:

messages := mitake.BatchMessagesParams{
	Messages: []mitake.Message{
        {
		    ClientID: "0aab",
            Dstaddr: "0987654321",
            Smbody:  "Message ...",
        },
        // ...
	},
}

response, err := client.SendBatch(context.Background(), messages)

Query the status of messages:

messages := mitake.MessageStatusParams{
    MessageIDs: []string{"MESSAGE_ID1", "MESSAGE_ID2"},
}

response, err := client.QueryMessageStatus(context.Background(), messages)

Cancel the scheduled message:

resp, err := client.CancelScheduledMessages(context.Background(), []string{"MESSAGE_ID1", "MESSAGE_ID2"})

Use webhook to receive the delivery receipts of the messages:

http.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {
    receipt, err := mitake.ParseMessageReceipt(r)
    if err != nil {
        // Handle error...
        return
    }
    // Process message receipt...
})
// The callback URL port number must be standard 80 (HTTP) or 443 (HTTPS).
if err := http.ListenAndServe(":80", nil); err != nil {
    log.Printf("ListenAndServe error: %v", err)
}

License

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