Skip to main content

uSpeedo

Check out our API reference documentation and quickstarts. From using the SDK to sample apps for Web, iOS, and Android, you'll get what you need.

Quickly send SMS

Check out the documentation, sample code, and developer tools you need to build exactly what you want, quickly. We'll handle the complexities of mobile operators and global regulations. Let's start building.

Golang SDK

package main

import (
"fmt"
"time"

"github.com/uspeedo/uspeedo-sdk-go/services/asms"
"github.com/uspeedo/uspeedo-sdk-go/services/asms/models"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo/auth"
"github.com/uspeedo/uspeedo-sdk-go/uspeedo/log"
)

func TestTemplateApi() {
asmsClient := getAsmsClient()

// Create Template

createTemplateReq := asmsClient.NewCreateUSMSTemplateReq()
createTemplateReq.Template = uspeedo.String("Your verification code is {1}")
createTemplateReq.Purpose = uspeedo.Int(1)
createTemplateReq.Remark = uspeedo.String("this is a test template")
createTemplateReq.TemplateName = uspeedo.String("test template")

createTemplateResp, err := asmsClient.CreateUSMSTemplate(createTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", createTemplateResp)
}

// Query Template

queryTemplateReq := asmsClient.NewQueryUSMSTemplateReq()
queryTemplateReq.TemplateId = []string{"UTAXXXXXXXXXXX"}
queryTemplateResp, err := asmsClient.QueryUSMSTemplate(queryTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", queryTemplateResp)
}

// Update Template

updateTemplateReq := asmsClient.NewUpdateUSMSTemplateReq()
updateTemplateReq.TemplateId = uspeedo.String("UTAXXXXXXXXXXX")
updateTemplateReq.Template = uspeedo.String("Your verification code is {1},thanks")
updateTemplateResp, err := asmsClient.UpdateUSMSTemplate(updateTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", updateTemplateResp)
}

// Delete Template

deleteTemplateReq := asmsClient.NewDeleteUSMSTemplateReq()
deleteTemplateReq.TemplateIds = []string{"UTAXXXXXXXXXXX"}
deleteTemplateResp, err := asmsClient.DeleteUSMSTemplate(deleteTemplateReq)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", deleteTemplateResp)
}

}

func getAsmsClient() *asms.AsmsClient {
cfg := uspeedo.NewConfig()
cfg.LogLevel = log.DebugLevel
cfg.Timeout = 5 * time.Second
cfg.MaxRetries = 1

credential := auth.NewCredential()

credential.PublicKey = "Get the access key id from console.uspeedo.com"
credential.PrivateKey = "Get the access key secret from console.uspeedo.com"

asmsClient := asms.NewClient(&cfg, &credential)

return asmsClient
}

func TestSendMessage() {
asmsClient := getAsmsClient()
req := asmsClient.NewSendBatchUSMSMessageReq()
req.TaskContent = []models.SendInfo{
{
TemplateId: uspeedo.String("UTAXXXXXXXXXXX"),
SenderId: uspeedo.String("uspeedo"),
Target: []models.TargetPhone{
{
Phone: uspeedo.String("(11)11111111"),
TemplateParams: []string{"111111"},
},
},
},
}

// send request
resp, err := asmsClient.SendBatchUSMSMessage(req)
if err != nil {
fmt.Printf("something bad happened: %s
", err)
} else {
fmt.Printf("response of the request: %v
", resp)
}
}

func main() {
TestTemplateApi()
TestSendMessage()
}