telzarsms

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

README

019_sms

SMS API client for Telzar (019) - Israeli SMS Company using Golang

Documentation

Index

Constants

View Source
const (
	ProdAPIAddress  = `https://www.019sms.co.il/api`
	DevAPIAddress   = `https://www.019sms.co.il:8090/api/test`
	HTTPContentType = `text/xml; charset=utf-8`
	HTTPMethod      = "POST"
	DateFormat      = "01/02/2006 15:04:05"
)

Basic Addresses for contacting Telzar

Variables

This section is empty.

Functions

func Callback

func Callback(h smshandler.HTTPHandler, path string, mux *http.ServeMux,
	onCallback func(http.ResponseWriter, *http.Request, *DLRPush, error))

Callback execute on getting Push SMS back from Telzar

Types

type Bool

type Bool bool

Bool represents the boolean value for XML

func (Bool) MarshalXML

func (b Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implement the interface for XML Marshaling

func (*Bool) Scan

func (b *Bool) Scan(src interface{}) error

Scan implements the database interface for Scan

func (Bool) String

func (b Bool) String() string

func (*Bool) UnmarshalXML

func (b *Bool) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the interface for unmarshaling xml

func (Bool) Value

func (b Bool) Value() (driver.Value, error)

Value implements the database interface of Value

type DLRPush

type DLRPush struct {
	ExternalID string
	Status     Status
	HeMessage  string
	EnMessage  string
	Date       time.Time
	Phone      string
	Operator   string
	ShipmentID string
}

DLRPush holds information arrived from DLR sent as Push notification

func URLToDLRPush

func URLToDLRPush(values url.Values) *DLRPush

URLToDLRPush translate url.Values to DLRPush struct

type DLRStatus

type DLRStatus int

DLRStatus holds the Delivery report (DLR) information

const (
	DLRStatusArrived                DLRStatus = 0
	DLRStatusFailed1                DLRStatus = 1
	DLRStatusTimeout                DLRStatus = 2
	DLRStatusFailed2                DLRStatus = 3
	DLRStatusCellularFailed1        DLRStatus = 4
	DLRStatusFailed3                DLRStatus = 5
	DLRStatusFailed4                DLRStatus = 6
	DLRStatusCellularFailed2        DLRStatus = 14
	DLRStatusKosherNumber           DLRStatus = 15
	DLRStatusDeliveryTimePermission DLRStatus = 16
	DLRStatusNotArrived1            DLRStatus = 101
	DLRStatusArrivedDestination     DLRStatus = 102
	DLRStatusExpired                DLRStatus = 103
	DLRStatusDeleted                DLRStatus = 104
	DLRStatusNotArrived2            DLRStatus = 105
	DLRStatusNotArrived3            DLRStatus = 106
	DLRStatusNotArrived4            DLRStatus = 107
	DLRStatusRejected               DLRStatus = 108
	DLRStatusNotArrived5            DLRStatus = 109
	DLRStatusBlockedOnRequest       DLRStatus = 201
	DLRStatusPermissionDenied       DLRStatus = 998
	DLRStatusUnknownCause           DLRStatus = 999
)

DLR status codes

func (DLRStatus) MarshalXML

func (dlr DLRStatus) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implement the interface for XML Marshaling

func (*DLRStatus) Scan

func (dlr *DLRStatus) Scan(src interface{}) error

Scan implements the database interface for Scan

func (DLRStatus) String

func (dlr DLRStatus) String() string

func (*DLRStatus) UnmarshalXML

func (dlr *DLRStatus) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the interface for unmarshaling xml

func (DLRStatus) Value

func (dlr DLRStatus) Value() (driver.Value, error)

Value implements the database interface of Value

type DestinationXML

type DestinationXML struct {
	XMLName xml.Name `xml:"destinations"`
	ClID    []string `xml:"cl_id,omitempty"`
	Phone   []Phone  `xml:"phone"`
}

DestinationXML represent the XML structure of destination

type HTTPHandler

type HTTPHandler struct {
	Client *http.Client
}

HTTPHandler perform HTTP actions, and implement

func (HTTPHandler) DoHTTP

func (h HTTPHandler) DoHTTP(
	method, contentType, address string, fields url.Values, body []byte) (resp *http.Response, err error)

DoHTTP sends an HTTP Request for sending an SMS

func (HTTPHandler) OnGettingSMS

func (h HTTPHandler) OnGettingSMS(path string, mux *http.ServeMux, httpHandler http.HandlerFunc)

OnGettingSMS is an HTTP server handler when incoming SMS arrives. If mux exists, it will use it for a server, otherwise it will use http.HandleFunc.

type MessagesBulkXML

type MessagesBulkXML struct {
	XMLName  xml.Name     `xml:"messages"`
	SMS      []SMSBulkXML `xml:"sms"`
	Timing   string       `xml:"timing,omitempty"`
	Response Bool         `xml:"response"`
}

MessagesBulkXML holds a list of SMS messages for bulk sending

type Phone

type Phone struct {
	Phone string `xml:",chardata"`
	ID    string `xml:"id,attr"`
}

Phone represent the phone number as expected

type SMSBulkXML

type SMSBulkXML struct {
	XMLName     xml.Name       `xml:"sms"`
	Source      string         `xml:"source"`
	Destination DestinationXML `xml:"destination"`
	Message     string         `xml:"message"`
}

SMSBulkXML holds SMS message for bulk messages

type SMSError

type SMSError struct {
	Status     Status
	Message    string
	ShipmentID string
}

SMSError holds information about sending information

func (SMSError) Error

func (e SMSError) Error() string

type Status

type Status int

Status is the response status arrive back

const (
	ErrorOK                              Status = 0
	ErrorXMLParsing                      Status = 1
	ErrorMissingRequiredXMLField         Status = 2
	ErrorIncorrectUserNameOrPassword     Status = 3
	ErrorNotEnoughCredit                 Status = 4
	ErrorNoPermissionForSMS              Status = 5
	ErrorInvalidPhone                    Status = 933
	ErrorSomeNumbersNotBlacklisted       Status = 944
	ErrorCamppaignAlreadyCanceled        Status = 955
	ErrorCampaignAlreadySent             Status = 966
	ErrorInvalidGivenCampaign            Status = 977
	ErrorCantUseMultipleContactLists     Status = 987
	ErrorContactListNotExist             Status = 988
	ErrorInvalidMessageLength            Status = 989
	ErrorAmountIsTooHighForCurrentCredit Status = 990
	ErrorNonIntegerValuesForAmount       Status = 991
	ErrorInvalidSourceLength             Status = 992
	ErrorInvalidPasswordLength           Status = 993
	ErrorUsernameAlreadyExists           Status = 994
	ErrorInvalidUsernameLength           Status = 995
	ErrorInvalidNameLength               Status = 996
	ErrorInvalidCommand                  Status = 997
	ErrorUnknownErrorInRequest           Status = 998
	ErrorContactSupport                  Status = 999
)

Error Codes

func StrToStatus

func StrToStatus(str string) Status

StrToStatus converts status that arrives as string to Status type. On error return -1

func (Status) MarshalXML

func (s Status) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implement the interface for XML Marshaling

func (*Status) Scan

func (s *Status) Scan(src interface{}) error

Scan implements the database interface for Scan

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalXML

func (s *Status) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the interface for unmarshaling xml

func (Status) Value

func (s Status) Value() (driver.Value, error)

Value implements the database interface of Value

type TelzarBulkXML

type TelzarBulkXML struct {
	XMLName  xml.Name `xml:"bulk"`
	User     UserAuth
	Messages MessagesBulkXML
}

TelzarBulkXML holds full bulk XML

type TelzarXML

type TelzarXML struct {
	XMLName        xml.Name       `xml:"sms"`
	User           UserAuth       `xml:"user"`
	Source         string         `xml:"source"`
	Destinations   DestinationXML `xml:"destinations"`
	Tag            string         `xml:"tag,omitempty"`
	Message        string         `xml:"message"`
	AddDynamic     Bool           `xml:"add_dynamic,omitempty"`
	Timing         string         `xml:"timing,omitempty"`
	AddUnsubscribe Unsubscribe    `xml:"add_unsubscribe"`
	Response       Bool           `xml:"response,omitempty"`
}

TelzarXML Holds a single SMS message to send

func (TelzarXML) SendSMS

func (x TelzarXML) SendSMS(h HTTPHandler) (*http.Response, error)

SendSMS sends the given SMS to InforU based on HTTP client

type Unsubscribe

type Unsubscribe uint8

Unsubscribe holds the type of unsubscribing methods to use

const (
	UnsubscribeOff Unsubscribe = iota + 1
	UnsubscribeByReturnSMS
	UnsubscribeByLink
)

Supported types of Unsubscribe

func (Unsubscribe) MarshalXML

func (u Unsubscribe) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implement the interface for XML Marshaling

func (*Unsubscribe) Scan

func (u *Unsubscribe) Scan(src interface{}) error

Scan implements the database interface for Scan

func (Unsubscribe) String

func (u Unsubscribe) String() string

func (*Unsubscribe) UnmarshalXML

func (u *Unsubscribe) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements the interface for unmarshaling xml

func (Unsubscribe) Value

func (u Unsubscribe) Value() (driver.Value, error)

Value implements the database interface of Value

type UserAuth

type UserAuth struct {
	XMLName  xml.Name `xml:"user"`
	Username string   `xml:"username"`
	Password string   `xml:"password"`
}

UserAuth holds authentication info for a request

type XMLResponse

type XMLResponse struct {
	XMLName        xml.Name    `xml:"sms"`
	Status         Status      `xml:"status"`
	Message        string      `xml:"message"`
	ShipmentID     string      `xml:"shipment_id"`
	AddUnsubscribe Unsubscribe `xml:"add_unsubscribe,omitempty"`
}

XMLResponse holds information about the given response back from the server

func (*XMLResponse) FromResponse

func (r *XMLResponse) FromResponse(buf []byte) error

FromResponse turns the body to XMLResponse, or error if something bad happened

func (XMLResponse) IsOK

func (r XMLResponse) IsOK() bool

IsOK return true if the return status is OK

func (XMLResponse) ToError

func (r XMLResponse) ToError() error

ToError converts XMLResponse to SMSError. If everything is ok, it will return nil

Jump to

Keyboard shortcuts

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