Help us shape the future of Go! Take the 2026 Go Developer Survey

telesign

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 15 Imported by: 0

README

telesign-sdk

telesign Golang SDK

quick start

import (
	"github.com/lcr2000/telesign-sdk"
	"log"
)

func main() {
	client, err := telesign.NewClient("your customerID", "your apiKey")
	if err != nil {
		log.Printf("NewClient fail, err=%v", err)
		return
	}
	req := &telesign.SendSmsVerifyReq{
		PhoneNumber:   "",
		UcID:          "",
		OriginatingIP: "",
		Language:      "",
		VerifyCode:    "",
		Template:      "",
		SenderID:      "",
		CallbackURL:   "",
		IsPrimary:     "",
	}
	resp, err := client.SendSmsVerify(req)
	if err != nil || resp == nil {
		log.Printf("SendSmsVerify fail, resp=%+v, err=%v", resp, err)
		return
	}
	log.Printf("SendSmsVerify resp=%+v", resp)
}

Documentation

Index

Constants

View Source
const (
	// EnvStandard is the standard env
	EnvStandard = "Standard"
	// EnvEnterprise is the enterprise env
	EnvEnterprise = "Enterprise"
)

API ENV

View Source
const (
	SmsVerifyURI = "/v1/verify/sms"
	SmsURI       = "/v1/messaging"
)

URI

View Source
const (
	// MessageTypeARN type
	MessageTypeARN = "ARN"
	// MessageTypeMKT type
	MessageTypeMKT = "MKT"
	// MessageTypeOTP type
	MessageTypeOTP = "OTP"
)

MessageType

View Source
const (
	IsPrimaryTrue  = "true"
	IsPrimaryFalse = "false"
)

IsPrimary

View Source
const (
	// DefaultHTTPTimeout Default http interface timeout
	DefaultHTTPTimeout = 10
)
View Source
const (
	// ErrorCodeAccountLimitReached 已达到账号限额
	ErrorCodeAccountLimitReached = -30003
)

Error Code Docs: https://developer.telesign.com/enterprise/docs/all-status-and-error-codes

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalInfo

type AdditionalInfo struct {
	CodeEntered       string `json:"code_entered"`
	MessagePartsCount int    `json:"message_parts_count"`
}

AdditionalInfo returned by telesign API

type Client

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

Client telesign client

func NewClient

func NewClient(customerID, apiKey string, opts ...*Options) (*Client, error)

NewClient Create a new telesign client instance. customerID and apiKey is required

func (*Client) SendSms

func (c *Client) SendSms(req *SendSmsReq) (*SendSmsResp, error)

SendSms Send an SMS message Docs: https://developer.telesign.com/enterprise/reference/post_v1-messaging

func (*Client) SendSmsVerify

func (c *Client) SendSmsVerify(req *SendSmsVerifyReq) (*SendSmsVerifyResp, error)

SendSmsVerify Send SMS Verification Code Docs: https://developer.telesign.com/enterprise/reference/sendsmsverificationcode

type Error

type Error struct {
	Code        int    `json:"code"`
	Description string `json:"description"`
}

Error returned by telesign API

type MainResponse

type MainResponse struct {
	StatusCode  int
	ResourceURI string         `json:"resource_uri"`
	ReferenceID string         `json:"reference_id"`
	Status      StatusResponse `json:"status"`
}

MainResponse returned by telesign API

type Options

type Options struct {
	Env         string
	HttpTimeout int
}

Options optional parameter

type Requester

type Requester interface {
	GetMethod() string
	GetURI() string
	GetPath() string
	GetBody() string
}

Requester interface

type SendSmsReq

type SendSmsReq struct {
	PhoneNumber           string `schema:"phone_number"`            // required 包含国家/地区代码的最终用户电话号码. 避免使用特殊字符和空格.
	Message               string `schema:"message"`                 // required 要发送给最终用户的消息文本. 您被限制为 1600 个字符. 如果您发送很长的消息, TeleSign 会将您的消息拆分为单独的部分. TeleSign 建议尽可能不要发送需要多条 SMS 的消息.
	MessageType           string `schema:"message_type"`            // required 此参数指定消息中发送的流量类型. 您可以提供以下值之一: OTP(一次性密码) ARN(警报、提醒和通知) MKT(营销流量).
	AccountLifecycleEvent string `schema:"account_lifecycle_event"` // 此参数允许您指示您在发送交易时处于生命周期的哪个阶段. 此参数的选项是 - create - 用于创建新帐户 登录 最终用户登录其帐户时. 交易 - 当最终用户在其帐户中完成交易时 update - 执行更新时, 例如更新帐户信息或类似信息. 删除 - 删除帐户时.
	SenderID              string `schema:"sender_id"`               // 指定要在 SMS 消息上显示给最终用户的发件人 ID. 在使用它之前, 请将您可能想要使用的任何发件人 ID 提供给我们的客户支持团队, 以便我们可以将它们添加到我们的允许列表中. 如果此字段中的发件人 ID 不在此列表中, 则不使用它. 我们不保证会使用您指定的发件人 ID; TeleSign 可能会覆盖此值以提高交付质量或遵循特定国家/地区的 SMS 法规。我们建议将值限制为 0-9 和 AZ, 因为对其他 ASCII 字符的支持因运营商而异.
	ExternalID            string `schema:"external_id"`             // 客户为此交易生成的 ID. 响应只是回显为此参数提供的值.
	OriginatingIP         string `schema:"originating_ip"`          // 您的最终用户的 IP 地址(不要发送您自己的 IP 地址). 此值必须采用 Internet 工程任务组 (IETF) 在标题为 IPv4 和 IPv6 地址的文本表示的 Internet 草案文档中定义的格式.
	CallbackURL           string `schema:"callback_url"`            // 您希望发送与您的请求相关的交付报告的 URL. 这会覆盖您之前设置的任何默认回调 URL. 覆盖仅持续此请求.
	IsPrimary             string `schema:"is_primary"`              // 无论您是使用此服务作为主要提供者发送此消息 ( ”true”) 还是在主要提供者失败后作为备份 ( ”false”). 我们使用这些数据来优化消息路由.
}

SendSmsReq object

func (*SendSmsReq) GetBody

func (r *SendSmsReq) GetBody() string

GetBody return body request

func (*SendSmsReq) GetMethod

func (r *SendSmsReq) GetMethod() string

GetMethod return method request

func (*SendSmsReq) GetPath

func (r *SendSmsReq) GetPath() string

GetPath return path request

func (*SendSmsReq) GetURI

func (r *SendSmsReq) GetURI() string

GetURI return uri request

type SendSmsResp

type SendSmsResp struct {
	MainResponse
	AdditionalInfo AdditionalInfo `json:"additional_info"`
}

SendSmsResp returned by telesign API

type SendSmsVerifyReq

type SendSmsVerifyReq struct {
	PhoneNumber   string `schema:"phone_number"`   // required 您要向其发送消息的最终用户的电话号码,以不带空格或特殊字符的数字形式, 以国家/地区拨号代码开头.
	UcID          string `schema:"ucid"`           // 场景 A code specifying the use case you are making the request for.
	OriginatingIP string `schema:"originating_ip"` // 您的最终用户的 IP 地址(不要发送您自己的 IP 地址). 这用于帮助 TeleSign 改进我们的服务. 支持 IPv4 和 IPv6.
	Language      string `schema:"language"`       // 指定您希望使用的预定义模板的语言的代码. 有关代码的完整列表, 请参阅支持的语言部分. 如果您在 template 参数中提供覆盖消息文本, 则不使用此字段.
	VerifyCode    string `schema:"verify_code"`    // 用于代码质询的验证码. 默认情况下,TeleSign 会为您随机生成一个七位数的数值. 您可以通过在此参数中包含您自己的数字代码来覆盖默认行为, 其值介于000和之间9999999. 无论哪种方式,验证码都会替换消息模板中的变量$$CODE$$.
	Template      string `schema:"template"`       // 覆盖预定义消息模板内容的文本. 包含 $$CODE$$ 变量以自动插入验证码, 最多可包含 1600 个字符.
	SenderID      string `schema:"sender_id"`      // 指定要在 SMS 消息上显示给最终用户的发件人 ID. 在使用它之前, 请将您可能想要使用的任何发件人 ID 提供给我们的客户支持团队, 以便我们可以将它们添加到我们的允许列表中. 如果此字段中的发件人 ID 不在此列表中, 则不使用它. 我们不保证会使用您指定的发件人 ID; TeleSign 可能会覆盖此值以提高交付质量或遵循特定国家/地区的 SMS 法规. TeleSign 建议将值限制为 0-9 和 AZ, 因为对其他 ASCII 字符的支持因运营商而异
	CallbackURL   string `schema:"callback_url"`   // 您希望发送与您的请求相关的交付报告的 URL. 这会覆盖您之前设置的任何默认回调 URL. 覆盖仅持续此请求.
	IsPrimary     string `schema:"is_primary"`     // 无论您是使用此服务作为主要提供者发送此消息 ( ”true”) 还是在主要提供者失败后作为备份 ( ”false”). 我们使用这些数据来优化消息路由.
}

SendSmsVerifyReq object

func (*SendSmsVerifyReq) GetBody

func (r *SendSmsVerifyReq) GetBody() string

GetBody return body request

func (*SendSmsVerifyReq) GetMethod

func (r *SendSmsVerifyReq) GetMethod() string

GetMethod return method request

func (*SendSmsVerifyReq) GetPath

func (r *SendSmsVerifyReq) GetPath() string

GetPath return path request

func (*SendSmsVerifyReq) GetURI

func (r *SendSmsVerifyReq) GetURI() string

GetURI return uri request

type SendSmsVerifyResp

type SendSmsVerifyResp struct {
	MainResponse
	SubResource string  `json:"sub_resource"`
	Errors      []Error `json:"errors"`
	SmsVerify   struct {
		CodeState   string `json:"code_state"`
		CodeEntered string `json:"code_entered"`
	} `json:"verify"`
	ExternalID      string `json:"external_id"`
	SignatureString string `json:"signature_string"`
}

SendSmsVerifyResp returned by telesign API

type StatusResponse

type StatusResponse struct {
	Code        int    `json:"code"`
	UpdatedOn   string `json:"updated_on"`
	Description string `json:"description"`
}

StatusResponse returned by telesign API

Jump to

Keyboard shortcuts

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