IPPANEL SMS api SDK
This repository contains open source Go client for ippanel
api. Documentation can be found at: http://docs.ippanel.com.
Installation
If you are using go modules, just install it with go mod install
or go build .
, Otherwise you can use go get ./...
go get github.com/ippanel/go-rest-sdk
Examples
After installing ippanel sdk with above methods, you can import it in your project like this:
import "github.com/ippanel/go-rest-sdk"
For using sdk, after importing, you have to create a client instance that gives you available methods on API
apiKey := "api-key"
sms := ippanel.New(apiKey)
...
Credit check
credit, err := sms.GetCredit()
if err != nil {
t.Error("error occurred ", err)
}
Send one to many
For sending sms, obviously you need originator
number, recipients
and message
.
bulkID, err := sms.Send("+9810001", []string{"98912xxxxxxx"}, "ippanel is awesome")
if err != nil {
t.Error("error occurred ", err)
}
If send is successful, a unique tracking code returned and you can track your message status with that.
Get message summery
bulkID := "message-tracking-code"
message, err := sms.GetMessage(bulkID)
if err != nil {
t.Error("error occurred ", err)
}
fmt.Println(message.Status)
fmt.Println(message.Cost)
fmt.Println(message.Payack)
Get message delivery statuses
bulkID := "message-tracking-code"
paginationParams := ippanel.ListParams{Page: 0, Limit: 10}
statuses, paginationInfo, err := sms.FetchStatuses(bulkID, paginationParams)
if err != nil {
t.Error("error occurred ", err)
}
for _, status := range statuses {
fmt.Printf("Recipient: %s, Status: %s", status.Recipient, status.Status)
}
fmt.Println("Total: ", paginationInfo.Total)
Inbox fetch
fetch inbox messages
paginationParams := ippanel.ListParams{Page: 0, Limit: 10}
messages, paginationInfo, err := sms.FetchInbox(paginationParams)
if err != nil {
t.Error("error occurred ", err)
}
Pattern create
For sending messages with predefined pattern(e.g. verification codes, ...), you hav to create a pattern. a pattern at least have a parameter. parameters defined with %param_name%
.
pattern, err := sms.CreatePattern("%name% is awesome", false)
if err != nil {
t.Error("error occurred ", err)
}
Send with pattern
patternValues := map[string]string{
"name": "IPPANEL",
}
bulkID, err := sms.SendPattern(
"t2cfmnyo0c",
"+9810001",
"98912xxxxxxx",
patternValues,
)
if err != nil {
t.Error("error occurred ", err)
}
Error checking
_, err := sms.Send("9810001", []string{"98912xxxxx"}, "ippanel is awesome")
if err != nil {
if e, ok := err.(Error); ok {
switch e.Code {
case ErrUnprocessableEntity:
fieldErrors := e.Message.(FieldErrs)
for field, fieldError := range fieldErrors {
t.Log(field, fieldError)
}
default:
errMsg := e.Message.(string)
t.Log(errMsg)
}
}
}