sms

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	DefaultApi *DefaultApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the SMS API API v1.0.5 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

ChangeBasePath changes base path to allow switching to mocks

func (*APIClient) GetConfig

func (c *APIClient) GetConfig() *Configuration

Allow modification of underlying config for alternate implementations and testing Caution: modifying the configuration while live can cause data races and potentially unwanted behavior

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

APIResponse stores the API response returned by the server.

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

NewAPIResponse returns a new APIResonse object.

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

NewAPIResponseWithError returns a new APIResponse object with the provided error message.

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client
}

Configuration stores the configuration of the API client

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration returns a new Configuration object

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

AddDefaultHeader adds a new HTTP header to the default header in the request

type DefaultApiService

type DefaultApiService service

DefaultApiService DefaultApi service

func (*DefaultApiService) SendAnSms

func (a *DefaultApiService) SendAnSms(ctx _context.Context, format string, apiKey string, from string, to string, localVarOptionals *SendAnSmsOpts) (Sms, *_nethttp.Response, error)

SendAnSms Send an SMS Send an outbound SMS from your Nexmo account

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param format The format of the response
  • @param apiKey Your API key
  • @param from The name or number the message should be sent from. Alphanumeric senderID's are not supported in all countries, see [Global Messaging](https://developer.nexmo.com/messaging/sms/guides/global-messaging#country-specific-features) for more details. If alphanumeric, spaces will be ignored. Numbers are specified in E.164 format.
  • @param to The number that the message should be sent to. Numbers are specified in E.164 format.
  • @param optional nil or *SendAnSmsOpts - Optional Parameters:
  • @param "ApiSecret" (optional.String) - Your API secret. Required unless `sig` is provided
  • @param "Sig" (optional.String) - The hash of the request parameters in alphabetical order, a timestamp and the signature secret. See [Signing Requests](/concepts/guides/signing-messages) for more details.
  • @param "Text" (optional.String) - The body of the message being sent. If your message contains characters that can be encoded according to the GSM Standard and Extended tables then you can set the `type` to `text`. If your message contains characters outside this range, then you will need to set the `type` to `unicode`.
  • @param "Ttl" (optional.Int32) - **Advanced**: The duration in milliseconds the delivery of an SMS will be attempted.§§ By default Nexmo attempt delivery for 72 hours, however the maximum effective value depends on the operator and is typically 24 - 48 hours. We recommend this value should be kept at its default or at least 30 minutes.
  • @param "StatusReportReq" (optional.Bool) - **Advanced**: Boolean indicating if you like to receive a [Delivery Receipt](https://developer.nexmo.com/messaging/sms/building-blocks/receive-a-delivery-receipt).
  • @param "Callback" (optional.String) - **Advanced**: The webhook endpoint the delivery receipt for this sms is sent to. This parameter overrides the webhook endpoint you set in Dashboard.
  • @param "MessageClass" (optional.Int32) - **Advanced**: The Data Coding Scheme value of the message
  • @param "Type_" (optional.String) - **Advanced**: The format of the message body
  • @param "Vcard" (optional.String) - **Advanced**: A business card in [vCard format](https://en.wikipedia.org/wiki/VCard). Depends on `type` parameter having the value `vcard`.
  • @param "Vcal" (optional.String) - **Advanced**: A calendar event in [vCal format](https://en.wikipedia.org/wiki/VCal). Depends on `type` parameter having the value `vcal`.
  • @param "Body" (optional.String) - **Advanced**: Hex encoded binary data. Depends on `type` parameter having the value `binary`.
  • @param "Udh" (optional.String) - **Advanced**: Your custom Hex encoded [User Data Header](https://en.wikipedia.org/wiki/User_Data_Header). Depends on `type` parameter having the value `binary`.
  • @param "ProtocolId" (optional.Int32) - **Advanced**: The value of the [protocol identifier](https://en.wikipedia.org/wiki/GSM_03.40#Protocol_Identifier) to use. Ensure that the value is aligned with `udh`.
  • @param "Title" (optional.String) - **Advanced**: The title for a wappush SMS. Depends on `type` parameter having the value `wappush`.
  • @param "Url" (optional.String) - **Advanced**: The URL of your website. Depends on `type` parameter having the value `wappush`.
  • @param "Validity" (optional.String) - **Advanced**: The availability for an SMS in milliseconds. Depends on `type` parameter having the value `wappush`.
  • @param "ClientRef" (optional.String) - **Advanced**: You can optionally include your own reference of up to 40 characters.
  • @param "AccountRef" (optional.String) - **Advanced**: An optional string used to identify separate accounts using the SMS endpoint for billing purposes. To use this feature, please email [support@nexmo.com](mailto:support@nexmo.com)

@return Sms

type DeliveryReceipt

type DeliveryReceipt struct {
	// The number the message was sent to. Numbers are specified in E.164 format.
	Msisdn string `json:"msisdn,omitempty"`
	// The SenderID you set in `from` in your request.
	To string `json:"to,omitempty"`
	// The Mobile Country Code Mobile Network Code (MCCMNC) of the carrier this phone number is registered with.
	NetworkCode string `json:"network-code,omitempty"`
	// The Nexmo ID for this message.
	MessageId string `json:"messageId,omitempty"`
	// The cost of the message
	Price string `json:"price,omitempty"`
	// A code that explains where the message is in the delivery process.
	Status string `json:"status,omitempty"`
	// When the DLR was received from the carrier in the following format `YYMMDDHHMM`. For example, `2001011400` is at `2020-01-01 14:00`
	Scts string `json:"scts,omitempty"`
	// The status of the request. Will be a non `0` value if there has been an error. See the [Delivery Receipt documentation](https://developer.nexmo.com/messaging/sms/guides/delivery-receipts#dlr-error-codes) for more details
	ErrCode string `json:"err-code,omitempty"`
	// The time when Nexmo started to push this Delivery Receipt to your webhook endpoint.
	MessageTimestamp string `json:"message-timestamp,omitempty"`
}

DeliveryReceipt struct for DeliveryReceipt

type Error

type Error struct {
	// The amount of messages in the request
	MessageCount string         `json:"message-count,omitempty"`
	Messages     []ErrorMessage `json:"messages,omitempty"`
}

Error struct for Error

type ErrorMessage

type ErrorMessage struct {
	// The error status of the message
	Status string `json:"status,omitempty"`
	// The description of the error
	ErrorText string `json:"error-text,omitempty"`
}

ErrorMessage struct for ErrorMessage

type GenericOpenAPIError

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

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

type InboundMessage

type InboundMessage struct {
	// The phone number that this inbound message was sent from. Numbers are specified in E.164 format.
	Msisdn string `json:"msisdn"`
	// The phone number the message was sent to. **This is your virtual number**. Numbers are specified in E.164 format.
	To string `json:"to"`
	// The ID of the message
	MessageId string `json:"messageId"`
	// The message body for this inbound message.
	Text string `json:"text"`
	// Possible values are:    - `text` - standard text.   - `unicode` - URLencoded   unicode  . This is valid for standard GSM, Arabic, Chinese, double-encoded characters and so on.   - `binary` - a binary message.
	Type string `json:"type"`
	// The first word in the message body. Converted to upper case.
	Keyword string `json:"keyword"`
	// The time when Nexmo started to push this Delivery Receipt to your webhook endpoint.
	MessageTimestamp string `json:"message-timestamp"`
	// A unix timestamp representation of message-timestamp.
	Timestamp string `json:"timestamp,omitempty"`
	// A random string that forms part of the signed set of parameters, it adds an extra element of unpredictability into the signature for the request. You use the nonce and timestamp parameters with your shared secret to calculate and validate the signature for inbound messages.
	Nonce string `json:"nonce,omitempty"`
	// True - if this is a concatenated message. This field does not exist if it is a single message
	Concat string `json:"concat,omitempty"`
	// The transaction reference. All parts of this message share this value.
	ConcatRef string `json:"concat-ref,omitempty"`
	// The number of parts in this concatenated message.
	ConcatTotal string `json:"concat-total,omitempty"`
	// The number of this part in the message. Counting starts at 1.
	ConcatPart string `json:"concat-part,omitempty"`
	// The content of this message, if type is binary.
	Data *os.File `json:"data,omitempty"`
	// The hex encoded User Data Header, if type is binary
	Udh string `json:"udh,omitempty"`
}

InboundMessage struct for InboundMessage

type Message

type Message struct {
	// The number the message was sent to. Numbers are specified in E.164 format.
	To string `json:"to,omitempty"`
	// The ID of the message
	MessageId string `json:"message-id,omitempty"`
	// The status of the message. See [Troubleshooting Failed SMS](https://developer.nexmo.com/messaging/sms/guides/troubleshooting-sms).
	Status string `json:"status,omitempty"`
	// Your remaining balance
	RemainingBalance string `json:"remaining-balance,omitempty"`
	// The cost of the message
	MessagePrice string `json:"message-price,omitempty"`
	// The ID of the network of the recipient
	Network string `json:"network,omitempty"`
	// **Advanced**: An optional string used to identify separate accounts using the SMS endpoint for billing purposes. To use this feature, please email [support@nexmo.com](mailto:support@nexmo.com)
	AccountRef string `json:"account-ref,omitempty"`
}

Message struct for Message

type MessageXmlWrapper

type MessageXmlWrapper struct {
	Messages []Message `json:"messages,omitempty"`
}

MessageXmlWrapper struct for MessageXmlWrapper

type NewMessage

type NewMessage struct {
	// Your API key
	ApiKey string `json:"api_key"`
	// Your API secret. Required unless `sig` is provided
	ApiSecret string `json:"api_secret,omitempty"`
	// The hash of the request parameters in alphabetical order, a timestamp and the signature secret. See [Signing Requests](/concepts/guides/signing-messages) for more details.
	Sig string `json:"sig,omitempty"`
	// The name or number the message should be sent from. Alphanumeric senderID's are not supported in all countries, see [Global Messaging](https://developer.nexmo.com/messaging/sms/guides/global-messaging#country-specific-features) for more details. If alphanumeric, spaces will be ignored. Numbers are specified in E.164 format.
	From string `json:"from"`
	// The number that the message should be sent to. Numbers are specified in E.164 format.
	To string `json:"to"`
	// The body of the message being sent. If your message contains characters that can be encoded according to the GSM Standard and Extended tables then you can set the `type` to `text`. If your message contains characters outside this range, then you will need to set the `type` to `unicode`.
	Text string `json:"text,omitempty"`
	// **Advanced**: The duration in milliseconds the delivery of an SMS will be attempted.§§ By default Nexmo attempt delivery for 72 hours, however the maximum effective value depends on the operator and is typically 24 - 48 hours. We recommend this value should be kept at its default or at least 30 minutes.
	Ttl int32 `json:"ttl,omitempty"`
	// **Advanced**: Boolean indicating if you like to receive a [Delivery Receipt](https://developer.nexmo.com/messaging/sms/building-blocks/receive-a-delivery-receipt).
	StatusReportReq bool `json:"status-report-req,omitempty"`
	// **Advanced**: The webhook endpoint the delivery receipt for this sms is sent to. This parameter overrides the webhook endpoint you set in Dashboard.
	Callback string `json:"callback,omitempty"`
	// **Advanced**: The Data Coding Scheme value of the message
	MessageClass int32 `json:"message-class,omitempty"`
	// **Advanced**: The format of the message body
	Type string `json:"type,omitempty"`
	// **Advanced**: A business card in [vCard format](https://en.wikipedia.org/wiki/VCard). Depends on `type` parameter having the value `vcard`.
	Vcard string `json:"vcard,omitempty"`
	// **Advanced**: A calendar event in [vCal format](https://en.wikipedia.org/wiki/VCal). Depends on `type` parameter having the value `vcal`.
	Vcal string `json:"vcal,omitempty"`
	// **Advanced**: Hex encoded binary data. Depends on `type` parameter having the value `binary`.
	Body string `json:"body,omitempty"`
	// **Advanced**: Your custom Hex encoded [User Data Header](https://en.wikipedia.org/wiki/User_Data_Header). Depends on `type` parameter having the value `binary`.
	Udh string `json:"udh,omitempty"`
	// **Advanced**: The value of the [protocol identifier](https://en.wikipedia.org/wiki/GSM_03.40#Protocol_Identifier) to use. Ensure that the value is aligned with `udh`.
	ProtocolId int32 `json:"protocol-id,omitempty"`
	// **Advanced**: The title for a wappush SMS. Depends on `type` parameter having the value `wappush`.
	Title string `json:"title,omitempty"`
	// **Advanced**: The URL of your website. Depends on `type` parameter having the value `wappush`.
	Url string `json:"url,omitempty"`
	// **Advanced**: The availability for an SMS in milliseconds. Depends on `type` parameter having the value `wappush`.
	Validity string `json:"validity,omitempty"`
	// **Advanced**: You can optionally include your own reference of up to 40 characters.
	ClientRef string `json:"client-ref,omitempty"`
	// **Advanced**: An optional string used to identify separate accounts using the SMS endpoint for billing purposes. To use this feature, please email [support@nexmo.com](mailto:support@nexmo.com)
	AccountRef string `json:"account-ref,omitempty"`
}

NewMessage struct for NewMessage

type SendAnSmsOpts

type SendAnSmsOpts struct {
	ApiSecret       optional.String
	Sig             optional.String
	Text            optional.String
	Ttl             optional.Int32
	StatusReportReq optional.Bool
	Callback        optional.String
	MessageClass    optional.Int32
	Type_           optional.String
	Vcard           optional.String
	Vcal            optional.String
	Body            optional.String
	Udh             optional.String
	ProtocolId      optional.Int32
	Title           optional.String
	Url             optional.String
	Validity        optional.String
	ClientRef       optional.String
	AccountRef      optional.String
}

SendAnSmsOpts Optional parameters for the method 'SendAnSms'

type Sms

type Sms struct {
	// The amount of messages in the request
	MessageCount string    `json:"message-count,omitempty"`
	Messages     []Message `json:"messages,omitempty"`
}

Sms struct for Sms

Jump to

Keyboard shortcuts

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