twillight

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 8 Imported by: 0

README

TWILIGHT 🦅

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

tenor

INSTALLATION

To use this in your project, Run the following command
$ go get -u github.com/Ghvstcode/twilight

With this project, you can interact with the following Twilio APIs

  • SMS API
  • Verify API
  • Lookup API
USAGE

The full examples can be found here

  • To get started with this library, you have to first authenticate. You can do this by calling the NewAuth function and passing your Account SID & Auth Token gotten from your Twilio console.
  • Next, You have to create a client for the API you intend to interact with. The created clients implement the interface the core functions require as their first argument
  • 5 digit error codes are Twilio errors. 0 error codes are my fault. You could check here for a list of all Twilio error codes

This is an example showning how to use this library to send an SMS

	a := twillight.NewAuth("ACxxxxxxx", "f7xxxxxxxxx")

	smsClient := a.NewSmsClient()

	res, err := twillight.NewOutgoingMessage(smsClient, "+443566778", "+1543222", "HelloWorld")

	if err != nil {
		er := err.(*app.ErrorResponse)
			fmt.Println("An Error Occured! status Code is", er.ErrorCode())
		
		fmt.Println(err.Error())
	}
	
	fmt.Println(res.Status)
Issues & Contributions
  • You encountered any issues while using this[Or just want to mess around]? Go ahead and create a new Issue!
  • I would love to see this project grow, If you have any contributions or ideas, please let me know! Send in your PR's
Notes/To-Do
  • Improve Test Coverage
  • Add more API's

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompletePsd2Verification

func CompletePsd2Verification(service verify.InternalVerification, to, code, amount, payee string) (*verify.ResponseConfirmVerification, error)

CompletePsd2Verification will check whether the user-provided token for the transaction is correct.

func CompleteVerification

func CompleteVerification(service verify.InternalVerification, to, code string) (*verify.ResponseConfirmVerification, error)

CompleteVerification will check whether the user-provided token is correct.

func DeleteMessage

func DeleteMessage(s sms.InternalSMSInterface, messageSid string) error

DeleteMessage deletes a Message record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs! On successful deletion, It returns No error. https://www.twilio.com/docs/sms/api/message-resource#delete-a-message-resource

func DeleteMessageMedia

func DeleteMessageMedia(s sms.InternalSMSInterface, messageSid, mediaSid string) error

DeleteMessageMedia deletes the specified media record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs! On successful deletion, It returns NO error - An Error value of NIL. https://www.twilio.com/docs/sms/api/message-resource#message-media-subresources

func LookupPhoneNumber

func LookupPhoneNumber(LookupClient lookup.InternalLookup, phoneNumber string, addons ...LookupAddon) (*lookup.ResponseLookup, error)

LookupPhoneNumber Is used to get information about a specified phone number. https://www.twilio.com/docs/lookup/api Lookup also supports Twilio Add-ons, enabling you to retrieve information from a multitude of 3rd party data sources, available via the Twilio Marketplace. You can add Lookup-supported add-ons by visiting the Twilio console to enabling the add-on, making sure you have 'Lookups' selected!

func NewOutgoingMediaMessage

func NewOutgoingMediaMessage(s sms.InternalSMSInterface, to string, from string, msgbody string, mediaUrl string, opts ...SmsOptions) (*sms.ResponseSms, error)

NewOutgoingMediaMessage sends a new MMS. While you can send text-only messages almost anywhere on the planet, sending media is currently only available in the US and Canada. Sending an MMS message looks a lot like sending an SMS, but it includes a new parameter, MediaUrl. This parameter specifies the URL of the media you want to include with your message.Twilio supports .gif, .png, or .jpeg content and will format the image on your recipient's device. Messages sent via Twilio can include up to 10 media files that have a total size of up to 5MB. Twilio will resize images as necessary for successful delivery based on carrier specifications. Messages with over 5MB of media will not be accepted.

func NewOutgoingMessage

func NewOutgoingMessage(s sms.InternalSMSInterface, to string, from string, body string, opts ...SmsOptions) (*sms.ResponseSms, error)

NewOutgoingMessage sends a new SMS message to the numbers provided. You can pass additional options! If you want to send messages while in trial mode, you must first verify your 'To' phone number with Twilio. You can verify your phone number by adding it to your Verified Caller IDs in the console. If the body of your message is more than 160 GSM-7 characters (or 70 UCS-2characters), Twilio will send the message as a segmented SMS and charge your account accordingly.

func NewOutgoingWhatsappMessage

func NewOutgoingWhatsappMessage(s sms.InternalSMSInterface, to string, from string, body string, opts ...SmsOptions) (*sms.ResponseSms, error)

NewOutgoingWhatsappMessage sends a new whatsapp message to a registered whatsapp Number. WhatsApp requires that your application implement explicit user opt-ins to deliver messages over WhatsApp. https://www.twilio.com/docs/whatsapp/api?code-sample=code-send-a-whatsapp-message-and-specify-a-statuscallback-url&code-language=Node.js&code-sdk-version=3.x#using-twilio-phone-numbers-with-whatsapp

func RetrieveAllMessages

func RetrieveAllMessages(s sms.InternalSMSInterface) (*sms.ResponseGetAllMessages, error)

RetrieveAllMessages Returns a list of messages associated with your account. If you are using this library, the list includes paging information. you may want to use the provided nextpageuri. Using the NextPageURI ensures that your next request picks up where it left off and can prevent you from retrieving duplicate data if you are actively sending or receiving messages. When getting the list of all messages, results will be sorted on the DateSent field with the most recent messages appearing first.

func RetrieveAllMessagesMedia

func RetrieveAllMessagesMedia(s sms.InternalSMSInterface, messageSid string) (*sms.ResponseAllMessageMedia, error)

RetrieveAllMessagesMedia Lists all media associated with the Account.

func RetrieveMessage

func RetrieveMessage(s sms.InternalSMSInterface, messageSid string) (*sms.ResponseSms, error)

RetrieveMessage retrieves a single message.

func SendMessageFeedback

func SendMessageFeedback(s sms.InternalSMSInterface, messageSid, outcome string) (*sms.ResponseSendMessageFeedback, error)

Message Feedback represents the user-reported outcome of a message. For Message Feedback to be sent, the provide feedback option should be set to true when the message is being sent. https://www.twilio.com/console/sms/insights/delivery?q=(activeInsightsView:overview,filters:!((field:feedback_outcome,filter_type:EQUALS,values:!(UNCONFIRMED))))

func StartPsd2Verification

func StartPsd2Verification(service verify.InternalVerification, to, channel, amount, payee string) (*verify.ResponseSendToken, error)

StartPsd2Verification is to verify a transaction. You will start by requesting to send a verification code to the user.

func StartVerification

func StartVerification(service verify.InternalVerification, to, channel string) (*verify.ResponseSendToken, error)

StartVerification will send a token to the end user through the specified channel. Newly created verifications will show a status of pending. Supported channels are sms, call, and email.

func UpdateMessage

func UpdateMessage(s sms.InternalSMSInterface, messageSid, body string) (*sms.ResponseSms, error)

UpdateMessage Updates the body of a Message resource. To redact a message, set the body property to an empty string https://www.twilio.com/docs/sms/api/message-resource#update-a-message-resource

Types

type Auth

type Auth struct {
	Client app.InternalAuth
}

func NewAuth

func NewAuth(accountSid, authToken string) *Auth

NewAuth creates an authenticated client that can be used to interact with Twilight.Your Account Sid and Auth Token from twilio.com/console.

func (*Auth) ConfigureHttp

func (a *Auth) ConfigureHttp(http *http.Client) *Auth

ConfigureHttp accepts a HTTP client that would be used for the client.

func (*Auth) DeleteService

func (a *Auth) DeleteService(serviceSid string) error

DeleteService Deletes the specified Service

func (*Auth) FetchService

func (a *Auth) FetchService(serviceSid string) (*verify.ResponseVerifyService, error)

FetchService Fetches a specific service.

func (*Auth) GetAccountInfo

func (a *Auth) GetAccountInfo() (*account.ResponseAccount, error)

GetAccountInfo Returns account information

func (*Auth) NewLookupClient

func (a *Auth) NewLookupClient() *lookup.ClientLookup

NewLookupClient creates a new Lookup function which can be used with the functions associated with phone number loookup

func (*Auth) NewSmsClient

func (a *Auth) NewSmsClient() *sms.MessageClient

NewSmsClient Creates a New SMSClient for performing SMS operations with Twilight. The returned MessageClient Implements the InternalSMSInterface Interface.

func (*Auth) NewVerificationService

func (a *Auth) NewVerificationService(FriendlyName string, opts ...ServiceOptions) (*verify.ResponseVerifyService, error)

NewVerificationService Creates a New Verification service which can be used to interact with twilio's verify API's through this library. A Verification Service is the set of common configurations used to create and check verifications. One verification service can be used to send multiple verification tokens. To create a PSD2 enabled service, add the OptEnablePsd2 option when creating a new service.

func (*Auth) UpdateCodeLength

func (a *Auth) UpdateCodeLength(serviceSid, codeLength string) (*verify.ResponseVerifyService, error)

UpdateCodeLength updates the length of the verification code Sent by a service.

func (*Auth) UpdateFriendlyName

func (a *Auth) UpdateFriendlyName(serviceSid, friendlyName string) (*verify.ResponseVerifyService, error)

UpdateFriendlyName Updates the "FriendlyName" of the service in question.

type LookupAddon

type LookupAddon func(opts *utils.LookupAddons)

func NomoroboSpamScoreAddon

func NomoroboSpamScoreAddon() LookupAddon

NomoroboSpamScoreAddon Detect Robocallers with Lookup and Nomorobo Spam Score Add-on

func PayfoneAddon

func PayfoneAddon() LookupAddon

PayfoneAddon is a Deterministic TCPA Compliance with Lookup and Payfone Add-on

func WhitePagesAddon

func WhitePagesAddon() LookupAddon

Get additional caller information with Lookup and Whitepages Pro Caller ID Add-on

type ServiceOptions

type ServiceOptions func(opts *utils.ServiceOpts)

func OptCodeLength

func OptCodeLength(codeLength string) ServiceOptions

OptCodeLength -- Specify the length of the verification code. The length of the verification code to generate. Must be an integer value between 4 and 10, inclusive.

func OptEnableCustomCode

func OptEnableCustomCode(enableCustomCode bool) ServiceOptions

OptEnableCustomCode specifies Whether to allow sending verifications with a custom code instead of a randomly generated one. Not available for all customers

func OptEnableDoNotShareWarning

func OptEnableDoNotShareWarning(enableWarning bool) ServiceOptions

OptEnableDoNotShareWarning specifies whether to add a security warning at the end of an SMS verification body. Disabled by default and applies only to SMS

func OptEnableLookup

func OptEnableLookup(lookup bool) ServiceOptions

OptEnableLookup is to specify whether to perform a lookup with each verification started and return info about the phone number.

func OptEnablePsd2

func OptEnablePsd2(enablePsd2 bool) ServiceOptions

OptEnablePsd2 specifies whether to pass PSD2 transaction parameters when starting a verification.

type SmsOptions

type SmsOptions func(opts *utils.SmsOpts)

func OptProvideFeedback

func OptProvideFeedback(feedback bool) SmsOptions

OptProvideFeedback Whether to confirm delivery of the message. Set this value to true if you are sending messages that have a trackable user action and you intend to confirm delivery of the message using the Message Feedback API. This parameter is false by default.

func OptStatusCallback

func OptStatusCallback(url string) SmsOptions

OptStatusCallback This is the URL Twilio should call using the status_callback_method to send status information to your application. If specified, we POST these message status changes to the URL: queued, failed, sent, delivered, or undelivered

func OptValidityPeriod

func OptValidityPeriod(period string) SmsOptions

OptValidityPeriod How long in seconds the message can remain in our outgoing message queue. After this period elapses, the message fails and we call your status callback. Can be between 1 and the default value of 14,400 seconds.

Directories

Path Synopsis
internal
app
sms

Jump to

Keyboard shortcuts

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