voice

package
v5.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2018 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	ID          string
	Status      CallStatus
	Source      string
	Destination string
	NumberID    string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	EndedAt     *time.Time
}

A Call describes a voice call which is made to a number.

A call has legs which are incoming or outgoing voice connections. An incoming leg is created when somebody calls a number. Outgoing legs are created when a call is transferred.

func CallByID

func CallByID(client *messagebird.Client, id string) (*Call, error)

CallByID fetches a call by it's ID.

An error is returned if no such call flow exists or is accessible.

func InitiateCall

func InitiateCall(client *messagebird.Client, source, destination string, callflow CallFlow, webhook *Webhook) (*Call, error)

InitiateCall initiates an outbound call.

When placing a call, you pass the source (the caller ID), the destination (the number/address that will be called), and the callFlow (the call flow to execute when the call is answered).

func (*Call) Delete

func (call *Call) Delete(client *messagebird.Client) error

Delete deletes the Call.

If the call is in progress, it hangs up all legs.

func (*Call) Legs

func (call *Call) Legs(client *messagebird.Client) *Paginator

Legs returns a paginator over all Legs associated with a call.

func (Call) MarshalJSON

func (call Call) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Call) UnmarshalJSON

func (call *Call) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlow

type CallFlow struct {
	ID    string
	Title string

	// Each object in the steps array in a call flow describes an operation
	// that executes during a call, e.g. transferring a call or playing back an
	// audio file.
	Steps []CallFlowStep

	// Record instructs the Voice system to record the entire call.
	//
	// Note that this is distinct from the Record CallFlow step which records
	// only a single message from the callee.
	Record bool

	CreatedAt time.Time
	UpdatedAt time.Time
}

A CallFlow describes the flow of operations (steps) to be executed when handling an incoming call.

Example
callflow := CallFlow{
	Title: "My CallFlow",
	Steps: []CallFlowStep{
		&CallFlowSayStep{
			Payload:  "Hello",
			Voice:    "male",
			Language: "en-US",
		},
		&CallFlowPauseStep{
			Length: time.Second * 4,
		},
		&CallFlowTransferStep{
			Destination: "31600000000",
		},
	},
}
_ = callflow
Output:

func CallFlowByID

func CallFlowByID(client *messagebird.Client, id string) (*CallFlow, error)

CallFlowByID fetches a callflow by it's ID.

An error is returned if no such call flow exists or is accessible.

func (*CallFlow) Create

func (callflow *CallFlow) Create(client *messagebird.Client) error

Create creates the callflow remotely.

The callflow is updated in-place.

func (*CallFlow) Delete

func (callflow *CallFlow) Delete(client *messagebird.Client) error

Delete deletes the CallFlow.

func (CallFlow) MarshalJSON

func (callflow CallFlow) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlow) UnmarshalJSON

func (callflow *CallFlow) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*CallFlow) Update

func (callflow *CallFlow) Update(client *messagebird.Client) error

Update updates the call flow by overwriting it.

An error is returned if no such call flow exists or is accessible.

type CallFlowFetchStep

type CallFlowFetchStep struct {
	CallFlowStepBase

	// The URL to fetch the call flow from.
	URL string
}

A CallFlowFetchStep fetches a call flow from a remote URL.

For more information on dynamic call flows, see: https://developers.messagebird.com/docs/voice-calling#dynamic-call-flows

Any steps following this tag are ignored.

func (*CallFlowFetchStep) MarshalJSON

func (step *CallFlowFetchStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowFetchStep) UnmarshalJSON

func (step *CallFlowFetchStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowHangupStep

type CallFlowHangupStep struct {
	CallFlowStepBase
}

A CallFlowHangupStep ends the call.

func (*CallFlowHangupStep) MarshalJSON

func (step *CallFlowHangupStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowHangupStep) UnmarshalJSON

func (step *CallFlowHangupStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowPauseStep

type CallFlowPauseStep struct {
	CallFlowStepBase

	// The length of the pause.
	//
	// Truncated to seconds.
	Length time.Duration
}

A CallFlowPauseStep Pauses (silently) for a given duration.

func (*CallFlowPauseStep) MarshalJSON

func (step *CallFlowPauseStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowPauseStep) UnmarshalJSON

func (step *CallFlowPauseStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowPlayStep

type CallFlowPlayStep struct {
	CallFlowStepBase

	// The URL of the media file to play. The media file should be a WAV file
	// (8 kHz, 16 bit).
	Media string
}

A CallFlowPlayStep plays back an audio file.

func (*CallFlowPlayStep) MarshalJSON

func (step *CallFlowPlayStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowPlayStep) UnmarshalJSON

func (step *CallFlowPlayStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowRecordStep

type CallFlowRecordStep struct {
	CallFlowStepBase

	// Setting the MaxLength limits the duration of the recording.
	//
	// Optional with the default value being 0 which imposes no limit.
	//
	// Truncated to seconds.
	MaxLength time.Duration

	// The duration of a moment of silence allowed before a recording is
	// stopped.
	//
	// If you omit this parameter, silence detection is disabled.
	//
	// Truncated to seconds.
	Timeout time.Duration

	// Key DTMF input to terminate recording.
	//
	// Values allowed are: "any", "#", "*", "none" (default).
	FinishOnKey string

	// Set this to get a transcription of a recording in the specified language
	// after the recording has finished.
	//
	// Allowed values: de-DE, en-AU, en-UK, en-US, es-ES, es-LA, fr-FR, it-IT, nl-NL, pt-BR.
	TranscribeLanguage string
}

A CallFlowRecordStep initiates an audio recording during a call, e.g. for capturing a user response.

Note that this is distinct from CallFlow.Record which records the entire call.

func (*CallFlowRecordStep) MarshalJSON

func (step *CallFlowRecordStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowRecordStep) UnmarshalJSON

func (step *CallFlowRecordStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowSayStep

type CallFlowSayStep struct {
	CallFlowStepBase

	// The text to pronounce.
	Payload string

	// The voice to use for pronouncing text.
	//
	// Allowed values: male, female.
	Voice string

	// The language of the text that is to be pronounced in <2 letter lang>-<2
	// letter country> format.
	//
	// Allowed values: cy-GB, da-DK, de-DE, en-AU, en-GB, en-GB-WLS, en-IN,
	// en-US, es-ES, es-US, fr-CA, fr-FR, is-IS, it-IT, ja-JP, nb-NO, nl-NL,
	// pl-PL, pt-BR, pt-PT, ro-RO, ru-RU, sv-SE, tr-TR.
	//
	// Please refer to the online documentation for an up to date list.
	Language string

	// The amount of times to repeat the payload.
	//
	// Allowed values: Between 1 and 10.
	Repeat int

	// Determines what happens if a machine picks up the phone.
	//
	// Possible values are: "continue": do not check, just play the message.
	// "delay": (default) if a machine answers, wait until the machine stops
	// talking. "hangup": Hangup when a machine answers.
	IfMachine string

	// The time to analyze if a machine has picked up the phone.
	//
	// Used in combination with the delay and hangup values of the ifMachine
	// attribute. Minimum: 400ms, maximum: 10s.
	//
	// Optional. The default is 7 seconds.
	//
	// Truncated to milliseconds
	MachineTimeout time.Duration
}

A CallFlowSayStep pronounces a text message with a given voice and language.

func (*CallFlowSayStep) MarshalJSON

func (step *CallFlowSayStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowSayStep) UnmarshalJSON

func (step *CallFlowSayStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallFlowStep

type CallFlowStep interface {
	json.Marshaler
	json.Unmarshaler
}

A CallFlowStep is a single step that can be taken in a callflow.

It can be any of CallflowTransferStep, CallFlowSayStep, CallFlowPlayStep, CallFlowPauseStep, CallFlowRecordStep, CallFlowFetchStep, CallFlowHangupStep.

This interface is provided for clarity and not meant to be implemented by other (external) types.

type CallFlowStepBase

type CallFlowStepBase struct {
	ID string `json:"id,omitempty"`

	OnKeypressGoto string `json:"onKeypressGoto,omitempty"`
	OnKeypressVar  string `json:"onKeypressVar,omitempty"`

	Conditions []struct {
		Variable string `json:"variable"`
		Operator string `json:"operator"`
		Value    string `json:"value"`
	} `json:"conditions,omitempty"`
}

CallFlowStepBase contains all common properties for call flow steps.

type CallFlowTransferStep

type CallFlowTransferStep struct {
	CallFlowStepBase

	// The destination (E.164 formatted number or SIP URI) to transfer a call
	// to. E.g. 31612345678 or sip:foobar@example.com.
	Destination string

	// Record sets the the side of the call that should be recorded.
	//
	// Optional. Available options are "in", "out" and "both". "in" can be used
	// to record the voice of the destination, "out" records the source. "both"
	// records both source and destination individually.
	Record string
}

A CallFlowTransferStep transfers the call to a different phone/server.

func (*CallFlowTransferStep) MarshalJSON

func (step *CallFlowTransferStep) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CallFlowTransferStep) UnmarshalJSON

func (step *CallFlowTransferStep) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type CallStatus

type CallStatus string

CallStatus enumerates all valid values for a call status.

const (
	// CallStatusStarting is the status of a call that is currently being set up.
	CallStatusStarting CallStatus = "starting"
	// CallStatusOngoing indicates that a call is active.
	CallStatusOngoing CallStatus = "ongoing"
	// CallStatusEnded indicates that a call has been terminated.
	CallStatusEnded CallStatus = "ended"
)

type Leg

type Leg struct {
	// The unique ID of the leg.
	ID string
	// The unique ID of the call that this leg belongs to.
	CallID string
	// The number/SIP URL that is making the connection.
	Source string
	// The number/SIP URL that a connection is made to.
	Destination string
	// The status of the leg. Possible values: starting, ringing, ongoing,
	// busy, no_answer, failed and hangup.
	Status LegStatus
	// The direction of the leg, indicating if it's an incoming connection or
	// outgoing (e.g. for transferring a call). Possible values: incoming,
	// outgoing.
	Direction LegDirection
	// The cost of the leg. The amount relates to the currency parameter.
	Cost float64
	// The three-letter currency code (ISO 4217) related to the cost of the
	// leg.
	Currency string
	// The duration of the leg.
	//
	// Truncated to seconds.
	Duration time.Duration
	// The date-time the leg was created.
	CreatedAt time.Time
	// The date-time the leg was last updated.
	UpdatedAt time.Time
	// The date-time the leg was answered.
	AnsweredAt *time.Time
	// The date-time the leg ended.
	EndedAt *time.Time
}

A Leg describes a leg object (inbound or outbound) that belongs to a call.

At least one leg exists per call. Inbound legs are being created when an incoming call to a Number is being initiated. Outgoing legs are created when a call is transferred or when a call is being originated from the API.

func (*Leg) Recordings

func (leg *Leg) Recordings(client *messagebird.Client) *Paginator

Recordings retrieves the Recording objects associated with a leg.

func (*Leg) UnmarshalJSON

func (leg *Leg) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type LegDirection

type LegDirection string

LegDirection indicates the direction of some leg in a call.

const (
	// LegDirectionOutgoing is the direction of a leg that are created when a
	// call is transferred.
	LegDirectionOutgoing LegDirection = "outgoing"
	// LegDirectionIncoming is the direction of a leg that is created when a
	// number is called.
	LegDirectionIncoming LegDirection = "incoming"
)

type LegStatus

type LegStatus string

LegStatus enumerates all valid values for a leg status.

const (
	// LegStatusStarting indicates that a leg is currently starting.
	LegStatusStarting LegStatus = "starting"
	// LegStatusRinging indicates that a leg is connected and ringing.
	LegStatusRinging LegStatus = "ringing"
	// LegStatusOngoing indicates a healthy leg that is currently participating
	// in a call.
	LegStatusOngoing LegStatus = "ongoing"
	// LegStatusBusy indicates that a leg could not be established because the
	// other side is busy.
	LegStatusBusy LegStatus = "busy"
	// LegStatusNoAnswer indicates that a leg could not be established because
	// the other side did not pick up.
	LegStatusNoAnswer LegStatus = "no_answer"
	// LegStatusFailed indicates some kind of failure of a leg.
	LegStatusFailed LegStatus = "failed"
	// LegStatusHangup indicates that a leg has been hung up.
	LegStatusHangup LegStatus = "hangup"
)

type Paginator

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

A Paginator is used to stream the contents of a collection of some type from the MessageBird API.

Paginators are single use and can therefore not be reset.

func CallFlows

func CallFlows(client *messagebird.Client) *Paginator

CallFlows returns a Paginator which iterates over all CallFlows.

func Calls

func Calls(client *messagebird.Client) *Paginator

Calls returns a Paginator which iterates over all Calls.

func Webhooks

func Webhooks(client *messagebird.Client) *Paginator

Webhooks returns a paginator over all webhooks.

func (*Paginator) NextPage

func (pag *Paginator) NextPage() (interface{}, error)

NextPage queries the next page from the MessageBird API.

The interface{} contains a slice of the type this paginator handles.

When no more items are available, an empty slice and io.EOF are returned. If another kind of error occurs, nil and and the error are returned.

func (*Paginator) Stream

func (pag *Paginator) Stream() <-chan interface{}

Stream creates a channel which streams the contents of all remaining pages ony by one.

The Paginator is consumed in the process, meaning that after elements have been received, NextPage will return EOF. It is invalid to mix calls to NextPage an Stream, even after the stream channel was closed.

If an error occurs, the next item sent over the channel will be an error instead of a regular value. The channel is closed directly after this.

type Recording

type Recording struct {
	// The unique ID of the recording.
	ID string
	// The format of the recording. Supported formats are: wav.
	Format string
	// The ID of the leg that the recording belongs to.
	LegID string
	// The status of the recording. Available statuses are: initialised, recording, done and failed
	Status RecordingStatus
	// The duration of the recording.
	//
	// Truncated to seconds.
	Duration time.Duration
	// The date-time the call was created.
	CreatedAt time.Time
	// The date-time the call was last updated.
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

A Recording describes a voice recording of a leg.

You can initiate a recording of a leg by having a step in your callflow with the record action set.

func (*Recording) DownloadFile

func (rec *Recording) DownloadFile(client *messagebird.Client) (io.ReadCloser, error)

DownloadFile streams the recorded WAV file.

func (*Recording) Transcriptions

func (rec *Recording) Transcriptions(client *messagebird.Client) *Paginator

Transcriptions returns a paginator for retrieving all Transcription objects.

func (*Recording) UnmarshalJSON

func (rec *Recording) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type RecordingStatus

type RecordingStatus string

RecordingStatus enumerates all valid values for the status of a recording.

const (
	// RecordingStatusInitialised indicates that the recording has been created
	// but has not begun just yet.
	RecordingStatusInitialised RecordingStatus = "initialised"
	// RecordingStatusRecording indicates that recording is currently in progress.
	RecordingStatusRecording RecordingStatus = "recording"
	// RecordingStatusDone indicates that a recording is completed and may be downloaded.
	RecordingStatusDone RecordingStatus = "done"
	// RecordingStatusFailed indicates that something went wrong while
	// recording a leg.
	RecordingStatusFailed RecordingStatus = "failed"
)

type Transcription

type Transcription struct {
	// The unique ID of the transcription.
	ID string
	// The ID of the recording that the transcription belongs to.
	RecordingID string
	// In case that an error was occurred while executing the transcription
	// request, it appears here.
	Error string
	// The date-time the transcription was created/requested.
	CreatedAt time.Time
	// The date-time the transcription was last updated.
	UpdatedAt time.Time
	// contains filtered or unexported fields
}

A Transcription is a textual representation of a recording as text.

You can request an automated transcription for a recording by doing a POST request to the API.

func (*Transcription) Contents

func (trans *Transcription) Contents(client *messagebird.Client) (string, error)

Contents gets the transcription file.

This is a plain text file.

func (*Transcription) UnmarshalJSON

func (trans *Transcription) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Webhook

type Webhook struct {
	ID        string
	URL       string
	Token     string
	CreatedAt time.Time
	UpdatedAt time.Time
}

A Webhook is an HTTP callback to your platform. They are sent when calls are created and updated.

func CreateWebHook

func CreateWebHook(client *messagebird.Client, url, token string) (*Webhook, error)

CreateWebHook creates a new webhook the specified url that will be called and security token.

func (*Webhook) Delete

func (wh *Webhook) Delete(client *messagebird.Client) error

Delete deletes a webhook.

func (Webhook) MarshalJSON

func (wh Webhook) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Webhook) UnmarshalJSON

func (wh *Webhook) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Webhook) Update

func (wh *Webhook) Update(client *messagebird.Client) error

Update syncs hte local state of a webhook to the MessageBird API.

Jump to

Keyboard shortcuts

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