uni

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 18 Imported by: 0

README

Unimatrix Go SDK

PkgGoDev Release GitHub license

The Unimatrix Go SDK provides convenient access to integrate communication capabilities into your Go applications using the Unimatrix HTTP API. The SDK provides support for sending SMS, 2FA verification, and phone number lookup.

Getting started

Before you begin, you need an Unimatrix account. If you don't have one yet, you can sign up for an Unimatrix account and get free credits to get you started.

Documentation

Check out the documentation at unimtx.com/docs for a quick overview.

Installation

The Unimatrix SDK for Golang uses Go Modules, which is available from the public Github repository.

Run the following command to add uni-go-sdk as a dependency to your project:

go get github.com/unimtx/uni-go-sdk

Usage

The following example shows how to use the Unimatrix Go SDK to interact with Unimatrix services.

Initialize a client
package main

import (
    "fmt"
    "github.com/unimtx/uni-go-sdk"
)

func main() {
    client := uni.NewClient("your access key id", "your access key secret")
}

or you can configure your credentials by environment variables:

export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret
Send SMS

Send a text message to a single recipient.

package main

import (
    "fmt"
    "github.com/unimtx/uni-go-sdk"
)

func main() {
    client := uni.NewClient()

    res, err := client.Messages.Send(&uni.MessageSendParams{
        To: "+1206880xxxx",  // in E.164 format
        Text: "Your verification code is 2048.",
    })
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
Send verification code

Send a one-time passcode (OTP) to a recipient. The following example will automatically generate a verification code.

package main

import (
    "fmt"
    "github.com/unimtx/uni-go-sdk"
)

func main() {
    client := uni.NewClient()

    res, err := client.Otp.Send(&uni.OtpSendParams{
        To: "+1206880xxxx",
    })
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
Check verification code

Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.

package main

import (
    "fmt"
    "github.com/unimtx/uni-go-sdk"
)

func main() {
    client := uni.NewClient()

    res, err := client.Otp.Verify(&uni.OtpVerifyParams{
        To: "+1206880xxxx",
        Code: "123456", // the code user provided
    })
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res.Valid)
    }
}

Reference

Other Unimatrix SDKs

To find Unimatrix SDKs in other programming languages, check out the list below:

License

This library is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmpty added in v0.2.1

func IsEmpty(obj interface{}) bool

func StructToMap added in v0.2.1

func StructToMap(obj interface{}) map[string]interface{}

func ToLowerFirstChar added in v0.2.1

func ToLowerFirstChar(s string) string

Types

type MessageSendParams added in v0.2.1

type MessageSendParams struct {
	To           string
	Signature    string
	TemplateId   string
	TemplateData map[string]string
	Content      string
	Text         string
}

type MessageService

type MessageService struct {
	// contains filtered or unexported fields
}

func (*MessageService) Send added in v0.2.1

func (service *MessageService) Send(params *MessageSendParams) (response *UniResponse, err error)

type OtpSendParams added in v0.3.0

type OtpSendParams struct {
	To         string
	Code       string
	Ttl        int
	Digits     int
	Intent     string
	Channel    string
	Signature  string
	TemplateId string
}

type OtpService added in v0.3.0

type OtpService struct {
	// contains filtered or unexported fields
}

func (*OtpService) Send added in v0.3.0

func (service *OtpService) Send(params *OtpSendParams) (response *UniResponse, err error)

func (*OtpService) Verify added in v0.3.0

func (service *OtpService) Verify(params *OtpVerifyParams) (response *UniResponse, err error)

type OtpVerifyParams added in v0.3.0

type OtpVerifyParams struct {
	To     string
	Code   string
	Ttl    int
	Intent string
}

type UniClient

type UniClient struct {
	AccessKeyId      string
	AccessKeySecret  string
	Endpoint         string
	SigningAlgorithm string
	Messages         *MessageService
	Otp              *OtpService
}

func NewClient

func NewClient(params ...string) *UniClient

func (*UniClient) GenerateRandomString

func (c *UniClient) GenerateRandomString(n int) string

func (*UniClient) Request

func (c *UniClient) Request(action string, data map[string]interface{}) (response *UniResponse, err error)

func (*UniClient) SetEndpoint

func (c *UniClient) SetEndpoint(endpoint string)

func (*UniClient) Sign

func (c *UniClient) Sign(query url.Values) url.Values

type UniResponse

type UniResponse struct {
	Raw       *http.Response
	Status    int
	Code      string
	Message   string
	Data      map[string]interface{}
	RequestId string
	Valid     bool
}

func NewResponse

func NewResponse(res *http.Response) (*UniResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL