gotwilio

package module
v0.0.0-...-2dcd9ce Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: BSD-2-Clause Imports: 16 Imported by: 0

README

Overview

This is the start of a library for Twilio. Gotwilio supports making voice calls and sending text messages.

License

Gotwilio is licensed under a BSD license.

Installation

To install gotwilio, simply run go get github.com/sfreiberg/gotwilio.

SMS Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	message := "Welcome to gotwilio!"
	twilio.SendSMS(from, to, message, "", "")
}

MMS Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	message := "Welcome to gotwilio!"
	twilio.SendMMS(from, to, message, "http://host/myimage.gif", "", "")
}

Voice Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	callbackParams := gotwilio.NewCallbackParameters("http://example.com")
	twilio.CallWithUrlCallbacks(from, to, callbackParams)
}

Video example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	twilio.CreateVideoRoom(gotwilio.DefaultVideoRoomOptions)
}

Documentation

Overview

Package gotwilio is a library for interacting with http://www.twilio.com/ API.

Package gotwilio is a library for interacting with http://www.twilio.com/ API.

Package gotwilio is a library for interacting with http://www.twilio.com/ API.

Package gotwilio is a library for interacting with http://www.twilio.com/ API.

Index

Constants

View Source
const ProxyBaseUrl = "https://proxy.twilio.com/v1"

https://www.twilio.com/docs/proxy/api/pb-proxy-service

View Source
const VerifyBaseURL = "https://verify.twilio.com/v2/"

VerifyBaseURL ...

Variables

View Source
var DefaultVideoRoomOptions = &createRoomOptions{
	EnableTurn:                  true,
	MaxParticipants:             10,
	MediaRegion:                 USEastCoast,
	RecordParticipantsOnConnect: false,
	StatusCallback:              "",
	StatusCallbackMethod:        http.MethodPost,
	Type:                        Group,
	UniqueName:                  "",
	VideoCodecs:                 []VideoCodecs{H264},
}

DefaultVideoRoomOptions are the default options for creating a room.

Functions

func DecodeWebhook

func DecodeWebhook(data url.Values, out interface{}) error

Types

type AccessToken

type AccessToken struct {
	AccountSid   string
	APIKeySid    string
	APIKeySecret string

	NotBefore time.Time
	ExpiresAt time.Time
	Grants    []Grant
	Identity  string
}

AccessToken holds everything required to create authenticate the client SDKs. See https://www.twilio.com/docs/iam/access-tokens for further details.

func (*AccessToken) AddGrant

func (a *AccessToken) AddGrant(grant Grant) *AccessToken

AddGrant adds a given Grant to the Access Token.

func (*AccessToken) ToJWT

func (a *AccessToken) ToJWT() (string, error)

ToJWT creates a JSON Web Token from the Access Token to use in the Client SDKs. See https://en.wikipedia.org/wiki/JSON_Web_Token for the standard format.

type CallbackParameters

type CallbackParameters struct {
	Url                           string   // Required
	Method                        string   // Optional
	FallbackUrl                   string   // Optional
	FallbackMethod                string   // Optional
	StatusCallback                string   // Optional
	StatusCallbackMethod          string   // Optional
	StatusCallbackEvent           []string // Optional
	SendDigits                    string   // Optional
	IfMachine                     string   // False, Continue or Hangup; http://www.twilio.com/docs/errors/21207
	Timeout                       int      // Optional
	Record                        bool     // Optional
	RecordingChannels             string   // Optional
	RecordingStatusCallback       string   // Optional
	RecordingStatusCallbackMethod string   // Optional
	MachineDetection              string   // Optional
	MachineDetectionTimeout       int      // Optional
}

These are the paramters to use when you want Twilio to use callback urls. See http://www.twilio.com/docs/api/rest/making-calls for more info.

func NewCallbackParameters

func NewCallbackParameters(url string) *CallbackParameters

NewCallbackParameters returns a CallbackParameters type with the specified url and CallbackParameters.Timeout set to 60.

type Exception

type Exception struct {
	Status   int    `json:"status"`    // HTTP specific error code
	Message  string `json:"message"`   // HTTP error message
	Code     int    `json:"code"`      // Twilio specific error code
	MoreInfo string `json:"more_info"` // Additional info from Twilio
}

Exception is a representation of a twilio exception.

type FaxBase

type FaxBase struct {
	Sid         string `json:"sid"`
	AccountSid  string `json:"account_sid"`
	DateCreated string `json:"date_created"`
	DateUpdated string `json:"date_updated"`
}

func (*FaxBase) DateCreatedAsTime

func (d *FaxBase) DateCreatedAsTime() (time.Time, error)

DateCreatedAsTime returns FaxBase.DateCreated as a time.Time object instead of a string.

func (*FaxBase) DateUpdatesAsTime

func (d *FaxBase) DateUpdatesAsTime() (time.Time, error)

DateUpdatesAsTime returns FaxBase.DateUpdated as a time.Time object instead of a string.

type FaxMediaResource

type FaxMediaResource struct {
	FaxBase
	FaxSid      string `json:"fax_sid"`
	ContentType string `json:"content_type"`
	Url         string `json:"url"`
}

type FaxResource

type FaxResource struct {
	FaxBase
	From       string  `json:"from"`
	To         string  `json:"to"`
	Direction  string  `json:"direction"`
	NumPages   uint    `json:"num_pages,string"`
	Duration   uint    `json:"duration,string"`
	MediaSid   string  `json:"media_sid"`
	MediaUrl   string  `json:"media_url"`
	Status     string  `json:"status"`
	Quality    string  `json:"quality"`
	ApiVersion string  `json:"api_version"`
	Price      *string `json:"price,omitempty"`
	PriceUnit  *string `json:"price_unit,omitempty"`
}

type FaxResourcesList

type FaxResourcesList struct {
	ListResources
	Faxes []*FaxResource `json:"faxes"`
}

type Grant

type Grant interface {
	// contains filtered or unexported methods
}

Grant is a perimssion given to the Access Token. Types include Chat, Video etc.

type Interaction

type Interaction struct {
	InboundResourceStatus  string    `json:"inbound_resource_status"`
	InboundResourceSid     string    `json:"inbound_resource_sid"`
	OutboundResourceStatus string    `json:"outbound_resource_status"`
	OutboundResourceSid    string    `json:"outbound_resource_sid"`
	InboundResourceURL     string    `json:"inbound_resource_url"`
	Type                   string    `json:"type"`
	AccountSid             string    `json:"account_sid"`
	OutboundResourceType   string    `json:"outbound_resource_type"`
	DateCreated            time.Time `json:"date_created"`
	InboundResourceType    string    `json:"inbound_resource_type"`
	URL                    string    `json:"url"`
	DateUpdated            time.Time `json:"date_updated"`
	Sid                    string    `json:"sid"`
	OutboundParticipantSid string    `json:"outbound_participant_sid"`
	OutboundResourceURL    string    `json:"outbound_resource_url"`
	SessionSid             string    `json:"session_sid"`
	ServiceSid             string    `json:"service_sid"`
	Data                   string    `json:"data"`
	InboundParticipantSid  string    `json:"inbound_participant_sid"`
}

type InteractionData

type InteractionData struct {
	Body string `json:"body"`
}

type InteractionList

type InteractionList struct {
	Meta         Meta          `json:"meta"`
	Interactions []Interaction `json:"interactions"`
}

type ListResources

type ListResources struct {
	Uri             string `json:"uri"`
	FirstPageUri    string `json:"first_page_uri"`
	NextPageUri     string `json:"next_page_uri"`
	PreviousPageUri string `json:"previous_page_uri"`
	Page            uint   `json:"page"`
	PageSize        uint   `json:"page_size"`

	Faxes    []*FaxResource `json:"faxes"`
	Messages []*SmsResponse `json:"messages"`
	// contains filtered or unexported fields
}

ListResources contains Twilio paging information. See https://www.twilio.com/docs/usage/twilios-response#response-formats-list-paging-information

type ListVideoReponse

type ListVideoReponse struct {
	Rooms []*VideoResponse `json:"rooms"`
	Meta  struct {
		Page            int64  `json:"page"`
		PageSize        int64  `json:"page_size"`
		FirstPageUrl    string `json:"first_page_url"`
		PreviousPageUrl string `json:"previous_page_url"`
		NextPageUrl     string `json:"next_page_url"`
		Url             string `json:"url"`
		Key             string `json:"key"`
	} `json:"meta"`
}

ListVideoResponse is returned when listing rooms

type ListVideoRoomOptions

type ListVideoRoomOptions struct {
	DateCreatedAfter  time.Time   `json:"DateCreatedAfter"`
	DateCreatedBefore time.Time   `json:"DateCreatedBefore"`
	Status            VideoStatus `json:"Status"`
	UniqueName        string      `json:"EnableUniqueNameTurn"`
}

ListVideoRoomOptions are the options to query for a list of video rooms.

type MediaRegion

type MediaRegion string

MediaRegion is the locations of Twilio's TURN servers

const (
	Australia   MediaRegion = "au1"
	Brazil      MediaRegion = "br1"
	Germany     MediaRegion = "de1"
	Ireland     MediaRegion = "ie1"
	India       MediaRegion = "in1"
	Japan       MediaRegion = "jp1"
	Singapore   MediaRegion = "sg1"
	USEastCoast MediaRegion = "us1"
	USWestCoast MediaRegion = "us2"
)

type Meta

type Meta struct {
	Page            int         `json:"page"`
	PageSize        int         `json:"page_size"`
	FirstPageURL    string      `json:"first_page_url"`
	PreviousPageURL interface{} `json:"previous_page_url"`
	URL             string      `json:"url"`
	NextPageURL     interface{} `json:"next_page_url"`
	Key             string      `json:"key"`
}

type Participant

type Participant struct {
	Sid                string      `json:"sid"`
	Identifier         string      `json:"identifier"`
	DateUpdated        time.Time   `json:"date_updated"`
	FriendlyName       interface{} `json:"friendly_name"`
	DateDeleted        interface{} `json:"date_deleted"`
	AccountSid         string      `json:"account_sid"`
	URL                string      `json:"url"`
	ProxyIdentifier    string      `json:"proxy_identifier"`
	ProxyIdentifierSid string      `json:"proxy_identifier_sid"`
	DateCreated        time.Time   `json:"date_created"`
	ParticipantSid     string      `json:"Participant_sid"`
	ServiceSid         string      `json:"service_sid"`
	Links              struct {
		MessageInteractions string `json:"message_interactions"`
	} `json:"links"`
}

type ParticipantList

type ParticipantList struct {
	Participants []Participant `json:"participants"`
	Meta         Meta          `json:"meta"`
}

type ParticipantRequest

type ParticipantRequest struct {
	Identifier      string // mandatory
	ProxyIdentifier string // optional
	FriendlyName    string // optional
}

type ProxyCallbackWebhook

type ProxyCallbackWebhook struct {
	OutboundResourceStatus string    `form:"outboundResourceStatus"`
	OutboundResourceType   string    `form:"outboundResourceType"`
	InteractionDateUpdated time.Time `form:"interactionDateUpdated"`
	InteractionData        string    `form:"interactionData"`
	InteractionDateCreated time.Time `form:"interactionDateCreated"`
	InboundResourceURL     string    `form:"inboundResourceUrl"`
	InteractionServiceSid  string    `form:"interactionServiceSid"`
	OutboundParticipantSid string    `form:"outboundParticipantSid"`
	InteractionType        string    `form:"interactionType"`
	InteractionAccountSid  string    `form:"interactionAccountSid"`
	InboundParticipantSid  string    `form:"inboundParticipantSid"`
	InboundResourceStatus  string    `form:"inboundResourceStatus"`
	OutboundResourceSid    string    `form:"outboundResourceSid"`
	OutboundResourceURL    string    `form:"outboundResourceUrl"`
	InboundResourceType    string    `form:"inboundResourceType"`
	InboundResourceSid     string    `form:"inboundResourceSid"`
	InteractionSessionSid  string    `form:"interactionSessionSid"`
	InteractionSid         string    `form:"interactionSid"`
}

https://www.twilio.com/docs/proxy/api/proxy-webhooks#callbackurl These webhooks are fired for each new interaction and are informational only.

func (ProxyCallbackWebhook) GetInteractionData

func (p ProxyCallbackWebhook) GetInteractionData() (InteractionData, error)

type ProxyInterceptCallbackWebhook

type ProxyInterceptCallbackWebhook struct {
	InteractionDateUpdated time.Time `form:"interactionDateUpdated"`
	InteractionData        string    `form:"interactionData"`
	InteractionDateCreated time.Time `form:"interactionDateCreated"`
	InboundResourceURL     string    `form:"inboundResourceUrl"`
	InteractionServiceSid  string    `form:"interactionServiceSid"`
	InteractionType        string    `form:"interactionType"`
	InteractionAccountSid  string    `form:"interactionAccountSid"`
	InboundParticipantSid  string    `form:"inboundParticipantSid"`
	InboundResourceStatus  string    `form:"inboundResourceStatus"`
	InboundResourceType    string    `form:"inboundResourceType"`
	InboundResourceSid     string    `form:"inboundResourceSid"`
	InteractionSessionSid  string    `form:"interactionSessionSid"`
	InteractionSid         string    `form:"interactionSid"`
}

https://www.twilio.com/docs/proxy/api/proxy-webhooks#interceptcallbackurl Fires on each interaction. If responded to with a 403 to this webhook we will abort/block the interaction. Any other status or timeout the interaction continues

func (ProxyInterceptCallbackWebhook) GetInteractionData

func (p ProxyInterceptCallbackWebhook) GetInteractionData() (InteractionData, error)

type ProxyMessage

type ProxyMessage struct {
	Body     string // The text to send to the participant
	MediaUrl string // Url to media file
	Callback string // Webhook url to handle processed record.
}

type ProxyOutOfSessionCallbackWebhook

type ProxyOutOfSessionCallbackWebhook struct {
	AccountSid                 string    `form:"AccountSid"`
	SessionUniqueName          string    `form:"sessionUniqueName"`
	SessionAccountSid          string    `form:"sessionAccountSid"`
	SessionServiceSid          string    `form:"sessionServiceSid"`
	SessionSid                 string    `form:"sessionSid"`
	SessionStatus              string    `form:"sessionStatus"`
	SessionMode                string    `form:"sessionMode"`
	SessionDateCreated         time.Time `form:"sessionDateCreated"`
	SessionDateStarted         time.Time `form:"sessionDateStarted"`
	SessionDateUpdated         time.Time `form:"sessionDateUpdated"`
	SessionDateEnded           time.Time `form:"sessionDateEnded"`
	SessionDateLastInteraction time.Time `form:"sessionDateLastInteraction"`
	SessionClosedReason        string    `form:"sessionClosedReason"`
	TTL                        string    `form:"ttl"`

	// SMS Specific
	Body          string `form:"Body"`
	SmsSid        string `form:"SmsSid"`
	MessageSid    string `form:"MessageSid"`
	NumMedia      string `form:"NumMedia"`
	NumSegments   string `form:"NumSegments"`
	SmsStatus     string `form:"SmsStatus"`
	SmsMessageSid string `form:"SmsMessageSid"`

	To          string `form:"To"`
	ToCity      string `form:"ToCity"`
	ToState     string `form:"ToState"`
	ToZip       string `form:"ToZip"`
	ToCountry   string `form:"ToCountry"`
	From        string `form:"From"`
	FromCity    string `form:"FromCity"`
	FromState   string `form:"FromState"`
	FromZip     string `form:"FromZip"`
	FromCountry string `form:"FromCountry"`

	InboundParticipantSid                string    `form:"inboundParticipantSid"`
	InboundParticipantIdentifier         string    `form:"inboundParticipantIdentifier"`
	InboundParticipantFriendlyName       string    `form:"inboundParticipantFriendlyName"`
	InboundParticipantProxyIdentifier    string    `form:"inboundParticipantProxyIdentifier"`
	InboundParticipantProxyIdentifierSid string    `form:"inboundParticipantProxyIdentifierSid"`
	InboundParticipantAccountSid         string    `form:"inboundParticipantAccountSid"`
	InboundParticipantServiceSid         string    `form:"inboundParticipantServiceSid"`
	InboundParticipantSessionSid         string    `form:"inboundParticipantSessionSid"`
	InboundParticipantDateCreated        time.Time `form:"inboundParticipantDateCreated"`
	InboundParticipantDateUpdated        time.Time `form:"inboundParticipantDateUpdated"`

	OutboundParticipantSid                string    `form:"outboundParticipantSid"`
	OutboundParticipantIdentifier         string    `form:"outboundParticipantIdentifier"`
	OutboundParticipantFriendlyName       string    `form:"outboundParticipantFriendlyName"`
	OutboundParticipantProxyIdentifier    string    `form:"outboundParticipantProxyIdentifier"`
	OutboundParticipantProxyIdentifierSid string    `form:"outboundParticipantProxyIdentifierSid"`
	OutboundParticipantAccountSid         string    `form:"outboundParticipantAccountSid"`
	OutboundParticipantServiceSid         string    `form:"outboundParticipantServiceSid"`
	OutboundParticipantSessionSid         string    `form:"outboundParticipantSessionSid"`
	OutboundParticipantDateCreated        time.Time `form:"outboundParticipantDateCreated"`
	OutboundParticipantDateUpdated        time.Time `form:"outboundParticipantDateUpdated"`

	CallSid    string `form:"CallSid"`
	CallStatus string `form:"CallStatus"`

	Caller        string `form:"Caller"`
	CallerCity    string `form:"CallerCity"`
	CallerState   string `form:"CallerState"`
	CallerZip     string `form:"CallerZip"`
	CallerCountry string `form:"CallerCountry"`

	Called        string `form:"Called"`
	CalledCity    string `form:"CalledCity"`
	CalledState   string `form:"CalledState"`
	CalledZip     string `form:"CalledZip"`
	CalledCountry string `form:"CalledCountry"`

	Direction  string `form:"Direction"`
	AddOns     string `form:"AddOns"`
	APIVersion string `form:"ApiVersion"`
}

https://www.twilio.com/docs/proxy/api/proxy-webhooks#outofsessioncallbackurl A URL to send webhooks to when an action (inbound call or SMS) occurs where there is no session or a closed session. If your server (or a Twilio function) responds with valid TwiML, this will be processed. This means it is possible to e.g. play a message for a call, send an automated text message response, or redirect a call to another number.

type ProxyService

type ProxyService struct {
	Sid                     string      `json:"sid"`
	UniqueName              string      `json:"unique_name"`
	AccountSid              string      `json:"account_sid"`
	CallbackURL             string      `json:"callback_url"`
	DefaultTTL              int         `json:"default_ttl"`
	NumberSelectionBehavior string      `json:"number_selection_behavior"`
	GeoMatchLevel           string      `json:"geo_match_level"`
	InterceptCallbackURL    interface{} `json:"intercept_callback_url"`
	OutOfSessionCallbackURL interface{} `json:"out_of_session_callback_url"`
	DateCreated             time.Time   `json:"date_created"`
	DateUpdated             time.Time   `json:"date_updated"`
	URL                     string      `json:"url"`
	Links                   struct {
		PhoneNumbers string `json:"phone_numbers"`
		ShortCodes   string `json:"short_codes"`
		Sessions     string `json:"sessions"`
	} `json:"links"`
}

type ProxyServiceRequest

type ProxyServiceRequest struct {
	UniqueName              string // optional
	CallbackURL             string // optional
	OutOfSessionCallbackURL string // optional
	InterceptCallbackURL    string // optional
	GeoMatchLevel           string // Default: country Options: country, area-code, extended-area-code	optional
	NumberSelectionBehavior string // Default: prefer-sticky Options: prefer-sticky, avoid-sticky	optional
	DefaultTtl              int    // (seconds) Default: 0	optional
}

type ProxySession

type ProxySession struct {
	Sid                 string      `json:"sid"`
	Status              string      `json:"status"`
	UniqueName          string      `json:"unique_name"`
	ClosedReason        interface{} `json:"closed_reason"`
	DateEnded           interface{} `json:"date_ended"`
	TTL                 int         `json:"ttl"`
	DateExpiry          interface{} `json:"date_expiry"`
	AccountSid          string      `json:"account_sid"`
	DateUpdated         time.Time   `json:"date_updated"`
	Mode                string      `json:"mode"`
	DateLastInteraction interface{} `json:"date_last_interaction"`
	URL                 string      `json:"url"`
	DateCreated         time.Time   `json:"date_created"`
	DateStarted         time.Time   `json:"date_started"`
	ServiceSid          string      `json:"service_sid"`
	Links               struct {
		Participants string `json:"participants"`
		Interactions string `json:"interactions"`
	} `json:"links"`
	// contains filtered or unexported fields
}

func (*ProxySession) AddParticipant

func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error)

AddParticipant adds Participant to Session

func (*ProxySession) CreateInteraction

func (session *ProxySession) CreateInteraction(participantSid string, msg ProxyMessage) (response Interaction, exception *Exception, err error)

func (*ProxySession) DeleteParticipant

func (session *ProxySession) DeleteParticipant(participantID string) (exception *Exception, err error)

func (*ProxySession) GetInteractions

func (session *ProxySession) GetInteractions() (response InteractionList, exception *Exception, err error)

func (*ProxySession) GetParticipant

func (session *ProxySession) GetParticipant(participantID string) (response Participant, exception *Exception, err error)

func (*ProxySession) ListParticipants

func (session *ProxySession) ListParticipants() (response []Participant, exception *Exception, err error)

type ProxySessionRequest

type ProxySessionRequest struct {
	Status     string    // default: open, other values: closed	optional
	UniqueName string    // optional
	TTL        int       // default: 0 (No TTL)	optional
	DateExpiry time.Time // optional
	Mode       string    // default: voice-and-message, other values: voice-only, message-only	optional
}

type SmsResponse

type SmsResponse struct {
	Sid         string  `json:"sid"`
	DateCreated string  `json:"date_created"`
	DateUpdate  string  `json:"date_updated"`
	DateSent    string  `json:"date_sent"`
	AccountSid  string  `json:"account_sid"`
	To          string  `json:"to"`
	From        string  `json:"from"`
	MediaUrl    string  `json:"media_url"`
	Body        string  `json:"body"`
	Status      string  `json:"status"`
	Direction   string  `json:"direction"`
	ApiVersion  string  `json:"api_version"`
	Price       *string `json:"price,omitempty"`
	Url         string  `json:"uri"`
}

SmsResponse is returned after a text/sms message is posted to Twilio

func (*SmsResponse) DateCreatedAsTime

func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error)

DateCreatedAsTime returns SmsResponse.DateCreated as a time.Time object instead of a string.

func (*SmsResponse) DateSentAsTime

func (sms *SmsResponse) DateSentAsTime() (time.Time, error)

DateSentAsTime returns SmsResponse.DateSent as a time.Time object instead of a string.

func (*SmsResponse) DateUpdateAsTime

func (sms *SmsResponse) DateUpdateAsTime() (time.Time, error)

DateUpdateAsTime returns SmsResponse.DateUpdate as a time.Time object instead of a string.

type Twilio

type Twilio struct {
	AccountSid string
	AuthToken  string
	BaseUrl    string
	VideoUrl   string
	HTTPClient *http.Client

	APIKeySid    string
	APIKeySecret string
}

Twilio stores basic information important for connecting to the twilio.com REST api such as AccountSid and AuthToken.

func NewTwilioClient

func NewTwilioClient(accountSid, authToken string) *Twilio

Create a new Twilio struct.

func NewTwilioClientCustomHTTP

func NewTwilioClientCustomHTTP(accountSid, authToken string, HTTPClient *http.Client) *Twilio

Create a new Twilio client, optionally using a custom http.Client

func (*Twilio) CallWithApplicationCallbacks

func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error)

Place a voice call with an ApplicationSid specified.

func (*Twilio) CallWithUrlCallbacks

func (twilio *Twilio) CallWithUrlCallbacks(from, to string, callbackParameters *CallbackParameters) (*VoiceResponse, *Exception, error)

Place a voice call with a list of callbacks specified.

func (*Twilio) CancelFax

func (t *Twilio) CancelFax(faxSid string) (*Exception, error)

func (*Twilio) CheckRequestSignature

func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error)

CheckRequestSignature checks that the X-Twilio-Signature header on a request matches the expected signature defined by the GenerateSignature function.

The baseUrl parameter will be prepended to the request URL. It is useful for specifying the protocol and host parts of the server URL hosting your endpoint.

Passing a non-POST request or a request without the X-Twilio-Signature header is an error.

func (*Twilio) CreateVideoRoom

func (twilio *Twilio) CreateVideoRoom(options *createRoomOptions) (videoResponse *VideoResponse, exception *Exception, err error)

CreateVideoRoom creates a video communication session for participants to connect to. See https://www.twilio.com/docs/video/api/rooms-resource for more information.

func (*Twilio) DeleteFax

func (t *Twilio) DeleteFax(faxSid string) (*Exception, error)

func (*Twilio) DeleteProxyService

func (twilio *Twilio) DeleteProxyService(sid string) (exception *Exception, err error)

func (*Twilio) DeleteProxySession

func (twilio *Twilio) DeleteProxySession(serviceID, sessionID string) (exception *Exception, err error)

func (*Twilio) DeleteVerifyService

func (twilio *Twilio) DeleteVerifyService(sid string) (exception *Exception, err error)

DeleteVerifyService deletes a Verify service

func (*Twilio) EndVideoRoom

func (twilio *Twilio) EndVideoRoom(nameOrSid string) (videoResponse *VideoResponse, exception *Exception, err error)

EndVideoRoom stops a single video session by name or by Sid, and disconnects all participants. See https://www.twilio.com/docs/video/api/rooms-resource for more information.

func (*Twilio) GenerateSignature

func (twilio *Twilio) GenerateSignature(url string, form url.Values) ([]byte, error)

GenerateSignature computes the Twilio signature for verifying the authenticity of a request. It is based on the specification at: https://www.twilio.com/docs/security#validating-requests

func (*Twilio) GetCall

func (twilio *Twilio) GetCall(sid string) (*VoiceResponse, *Exception, error)

GetCall uses Twilio to get information about a voice call. See https://www.twilio.com/docs/voice/api/call

func (*Twilio) GetFax

func (t *Twilio) GetFax(faxSid string) (*FaxResource, *Exception, error)

func (*Twilio) GetFaxes

func (t *Twilio) GetFaxes(to, from, createdOnOrBefore, createdAfter string) ([]*FaxResource, *Exception, error)

GetFaxes gets faxes for a Twilio account. See https://www.twilio.com/docs/fax/api/faxes#fax-list-resource

func (*Twilio) GetProxyService

func (twilio *Twilio) GetProxyService(sid string) (response *ProxyService, exception *Exception, err error)

func (*Twilio) GetProxySession

func (twilio *Twilio) GetProxySession(serviceID, sessionID string) (response *ProxySession, exception *Exception, err error)

func (*Twilio) GetSMS

func (twilio *Twilio) GetSMS(sid string) (smsResponse *SmsResponse, exception *Exception, err error)

GetSMS uses Twilio to get information about a text message. See https://www.twilio.com/docs/api/rest/sms for more information.

func (*Twilio) GetUsage

func (twilio *Twilio) GetUsage(category, startDate, endDate string, includeSubaccounts bool) (*UsageResponse, *Exception, error)

func (*Twilio) GetVerification

func (twilio *Twilio) GetVerification(serviceID, verificationID string) (response *Verification, exception *Exception, err error)

GetVerification fetch a verification

func (*Twilio) GetVerifyService

func (twilio *Twilio) GetVerifyService(sid string) (response *VerifyService, exception *Exception, err error)

GetVerifyService fetch a Verify service

func (*Twilio) GetVideoRoom

func (twilio *Twilio) GetVideoRoom(nameOrSid string) (videoResponse *VideoResponse, exception *Exception, err error)

GetVideoRoom retrievs a single video session by name or by Sid. See https://www.twilio.com/docs/video/api/rooms-resource for more information.

func (*Twilio) ListVideoRooms

func (twilio *Twilio) ListVideoRooms(options *ListVideoRoomOptions) (videoResponse *ListVideoReponse, exception *Exception, err error)

ListVideoRooms returns a list of all video rooms. See https://www.twilio.com/docs/video/api/rooms-resource for more information.

func (*Twilio) NewAccessToken

func (twilio *Twilio) NewAccessToken() *AccessToken

NewAccessToken creates a new Access Token which can be used to authenticate Twilio Client SDKs for a short period of time.

func (*Twilio) NewProxyService

func (twilio *Twilio) NewProxyService(service ProxyServiceRequest) (response *ProxyService, exception *Exception, err error)

Create a new Twilio Service

func (*Twilio) NewProxySession

func (twilio *Twilio) NewProxySession(serviceID string, req ProxySessionRequest) (response *ProxySession, exception *Exception, err error)

Create a new Twilio Service

func (*Twilio) NewVerification

func (twilio *Twilio) NewVerification(serviceID string, req VerificationRequest) (response *Verification, exception *Exception, err error)

NewVerification represents a verification request

func (*Twilio) NewVerifyService

func (twilio *Twilio) NewVerifyService(service VerifyServiceRequest) (response *VerifyService, exception *Exception, err error)

NewVerifyService creates new Verify service

func (*Twilio) SendFax

func (t *Twilio) SendFax(to, from, mediaUrl, quality, statusCallback string, storeMedia bool) (*FaxResource, *Exception, error)

SendFax uses Twilio to send a fax. See https://www.twilio.com/docs/fax/api/faxes#list-post for more information.

func (*Twilio) SendMMS

func (twilio *Twilio) SendMMS(from, to, body, mediaUrl, statusCallback, applicationSid string) (smsResponse *SmsResponse, exception *Exception, err error)

SendMMS uses Twilio to send a multimedia message.

func (*Twilio) SendSMS

func (twilio *Twilio) SendSMS(from, to, body, statusCallback, applicationSid string) (smsResponse *SmsResponse, exception *Exception, err error)

SendSMS uses Twilio to send a text message. See http://www.twilio.com/docs/api/rest/sending-sms for more information.

func (*Twilio) SendSMSWithCopilot

func (twilio *Twilio) SendSMSWithCopilot(messagingServiceSid, to, body, statusCallback, applicationSid string) (smsResponse *SmsResponse, exception *Exception, err error)

SendSMSWithCopilot uses Twilio Copilot to send a text message. See https://www.twilio.com/docs/api/rest/sending-messages-copilot

func (*Twilio) UpdateProxyService

func (twilio *Twilio) UpdateProxyService(sid string, service ProxyServiceRequest) (response *ProxyService, exception *Exception, err error)

func (*Twilio) UpdateProxySession

func (twilio *Twilio) UpdateProxySession(serviceID, sessionID string, req ProxySessionRequest) (response *ProxySession, exception *Exception, err error)

func (*Twilio) UpdateVerification

func (twilio *Twilio) UpdateVerification(serviceID, verificationID string, req VerificationRequest) (response *Verification, exception *Exception, err error)

UpdateVerification use this endpoint only if using Custom Verification Codes

func (*Twilio) UpdateVerifyService

func (twilio *Twilio) UpdateVerifyService(sid string, service VerifyServiceRequest) (response *VerifyService, exception *Exception, err error)

UpdateVerifyService update a Verfiy service

func (*Twilio) WithAPIKey

func (twilio *Twilio) WithAPIKey(apiKeySid string, apiKeySecret string) *Twilio

type UsageParameters

type UsageParameters struct {
	Category           string // Optional
	StartDate          string // Optional, in YYYY-MM-DD or as offset
	EndDate            string // Optional, in YYYY-MM-DD or as offset
	IncludeSubaccounts bool   // Optional
}

These are the parameters to use when you are requesting account usage. See https://www.twilio.com/docs/usage/api/usage-record#read-multiple-usagerecord-resources for more info.

type UsageRecord

type UsageRecord struct {
	AccountSid  string `json:"account_sid"`
	Category    string `json:"category"`
	Description string `json:"description"`
	StartDate   string `json:"start_date"`
	EndDate     string `json:"end_date"`
	Price       string `json:"price"`
	PriceUnit   string `json:"price_unit"`
	Count       int    `json:"count,string"`
	CountUnit   string `json:"count_unit"`
	Usage       int    `json:"usage,string"`
	UsageUnit   string `json:"usage_unit"`
}

UsageRecord specifies the usage for a particular usage category. See https://www.twilio.com/docs/usage/api/usage-record#usagerecord-properties for more info.

type UsageResponse

type UsageResponse struct {
	PageSize     int           `json:"page_size"`
	Page         int           `json:"page"`
	UsageRecords []UsageRecord `json:"usage_records"`
}

UsageResponse contains information about account usage.

type Verification

type Verification struct {
	Sid         string    `json:"sid"`
	ServiceSid  string    `json:"service_sid"`
	AccountSid  string    `json:"account_sid"`
	To          string    `json:"to"`
	Chanel      string    `json:"channel"`
	Status      string    `json:"status"`
	Valid       bool      `json:"valid"`
	DateCreated time.Time `json:"date_created"`
	DateUpdate  time.Time `json:"date_updated"`
	Lookup      struct {
		Carrier struct {
			ErrorCode         string `json:"error_code"`
			Name              string `json:"name"`
			MobileCountryCode string `json:"mobile_country_code"`
			MobileNetworkCode string `json:"mobile_network_code"`
			Type              string `json:"mobile"`
		} `json:"carrier"`
	} `json:"lookup"`
	Amount string `json:"amount"`
	Payee  string `json:"payee"`
	URL    string `json:"url"`
	// contains filtered or unexported fields
}

Verification verification request

type VerificationRequest

type VerificationRequest struct {
	ServiceSid    string          // Required
	To            string          // Required
	Channel       string          // Required
	CustomMessage string          // Optional
	SendDigits    string          // Optional
	Locale        string          // Optional
	CustomCode    string          // Optional
	Amount        string          // Optional
	Payee         string          // Optional
	RateLimits    VerifyRateLimit // Optional
}

VerificationRequest resource

type VerifyRateLimit

type VerifyRateLimit struct {
	Sid         string            `json:"sid"`
	ServiceSid  string            `json:"service_sid"`
	AccountSid  string            `json:"account_sid"`
	UniqueName  string            `json:"unique_name"`
	Description string            `json:"description"`
	DateCreated time.Time         `json:"date_created"`
	DateUpdated time.Time         `json:"date_updated"`
	URL         string            `json:"url"`
	Links       map[string]string `json:"links"`
}

VerifyRateLimit ...

type VerifyRateLimitRequest

type VerifyRateLimitRequest struct {
	ServiceSid  string // Required
	UniqueName  string // Required
	Description string // Optional
}

VerifyRateLimitRequest ...

type VerifyService

type VerifyService struct {
	Sid                string    `json:"sid"`
	AccountSid         string    `json:"account_sid"`
	FriendlyName       string    `json:"friendly_name"`
	CodeLength         int       `json:"code_length"`
	LookupEnabled      bool      `json:"lookup_enabled"`
	PSD2Enabled        bool      `json:"psd2_enabled"`
	SkipSMSToLandlines bool      `json:"skip_sms_to_landlines"`
	DTMFInputRequired  bool      `json:"dtmf_input_required"`
	TTSname            string    `json:"tts_name"`
	DateCreated        time.Time `json:"date_created"`
	DateUpdated        time.Time `json:"date_updated"`
	URL                string    `json:"url"`
	Links              struct {
		VerificationChecks      string `json:"verification_checks"`
		Verifications           string `json:"verifications"`
		RateLimits              string `json:"rate_limits"`
		MessagingConfigurations string `json:"messaging_configurations"`
	} `json:"links"`
}

VerifyService ...

type VerifyServiceRequest

type VerifyServiceRequest struct {
	FriendlyName       string // Required
	CodeLength         int    // Optional
	LookupEnabled      bool   // Optional
	SkipSMSToLandlines bool   // Optional
	DTMFInputRequired  bool   // Optional
	TTSName            string // Optional
	PSD2Enabled        bool   // Optional
}

VerifyServiceRequest ..

type VideoCodecs

type VideoCodecs string

VideoCodecs are the supported codecs when publishing a track to the room.

const (
	VP8  VideoCodecs = "VP8"
	H264 VideoCodecs = "H264"
)

type VideoGrant

type VideoGrant struct {
	Room string `json:"room,omitempty"`
}

VideoGrant is the permission to use the Video API which can be given to an Access Token.

type VideoResponse

type VideoResponse struct {
	AccountSid                  string        `json:"account_sid"`
	DateCreated                 time.Time     `json:"date_created"`
	DateUpdated                 time.Time     `json:"date_updated"`
	Duration                    time.Duration `json:"duration"`
	EnableTurn                  bool          `json:"enable_turn"`
	EndTime                     time.Time     `json:"end_time"`
	MaxParticipants             int64         `json:"max_participants"`
	MediaRegion                 MediaRegion   `json:"media_region"`
	RecordParticipantsOnConnect bool          `json:"record_participants_on_connect"`
	Sid                         string        `json:"sid"`
	Status                      VideoStatus   `json:"status"`
	StatusCallback              string        `json:"status_callback"`
	StatusCallbackMethod        string        `json:"status_callback_method"`
	Type                        VideoRoomType `json:"type"`
	UniqueName                  string        `json:"unique_name"`
	URL                         string        `json:"url"`
}

VideoResponse is returned for a single room

type VideoRoomType

type VideoRoomType string

VideoRoomType is how the participants connect to each other, whether peer-to-peer of routed through a TURN server.

const (
	PeerToPeer VideoRoomType = "peer-to-peer"
	Group      VideoRoomType = "group"
)

type VideoStatus

type VideoStatus string

VideoStatus is the status of a video room

const (
	InProgress VideoStatus = "in-progress"
	Failed     VideoStatus = "failed"
	Completed  VideoStatus = "completed"
)

type VoiceResponse

type VoiceResponse struct {
	Sid            string  `json:"sid"`
	DateCreated    string  `json:"date_created"`
	DateUpdated    string  `json:"date_updated"`
	ParentCallSid  string  `json:"parent_call_sid"`
	AccountSid     string  `json:"account_sid"`
	To             string  `json:"to"`
	ToFormatted    string  `json:"to_formatted"`
	From           string  `json:"from"`
	FromFormatted  string  `json:"from_formatted"`
	PhoneNumberSid string  `json:"phone_number_sid"`
	Status         string  `json:"status"`
	StartTime      string  `json:"start_time"`
	EndTime        string  `json:"end_time"`
	Duration       int     `json:"duration,string"`
	PriceUnit      string  `json:"price_unit"`
	Price          *string `json:"price,omitempty"`
	Direction      string  `json:"direction"`
	AnsweredBy     string  `json:"answered_by"`
	ApiVersion     string  `json:"api_version"`
	Annotation     string  `json:"annotation"`
	ForwardedFrom  string  `json:"forwarded_from"`
	GroupSid       string  `json:"group_sid"`
	CallerName     string  `json:"caller_name"`
	Uri            string  `json:"uri"`
}

VoiceResponse contains the details about successful voice calls.

func (*VoiceResponse) DateCreatedAsTime

func (vr *VoiceResponse) DateCreatedAsTime() (time.Time, error)

DateCreatedAsTime returns VoiceResponse.DateCreated as a time.Time object instead of a string.

func (*VoiceResponse) DateUpdatedAsTime

func (vr *VoiceResponse) DateUpdatedAsTime() (time.Time, error)

DateUpdatedAsTime returns VoiceResponse.DateUpdated as a time.Time object instead of a string.

func (*VoiceResponse) EndTimeAsTime

func (vr *VoiceResponse) EndTimeAsTime() (time.Time, error)

EndTimeAsTime returns VoiceResponse.EndTime as a time.Time object instead of a string.

func (*VoiceResponse) StartTimeAsTime

func (vr *VoiceResponse) StartTimeAsTime() (time.Time, error)

StartTimeAsTime returns VoiceResponse.StartTime as a time.Time object instead of a string.

Jump to

Keyboard shortcuts

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