telphin

package module
v0.0.0-...-16e5c50 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2018 License: MIT Imports: 11 Imported by: 0

README

Telphin-SDK

Go Report Card GoDoc

golang lib api Telphin billing

Installation

~ $ go get -u gopkg.in/OrlovEvgeny/telphin-sdk.v1

Example Trusted auth

func main() {
        //OAuth type
        trusted := &telphin.Trusted {
    		GrantType:    "client_credentials",
    		ClientID:     <your client_id>,
    		ClientSecret: <your client_secret>,
    	}
        
        //New api
    	api, err := telphin.NewAPI(trusted)
    	if err != nil {
    		fmt.Println(err)
    	}
    
    	fmt.Println("You telphin access token: ", api.AccessToken)
    	fmt.Println("You telphin token expires in: ", api.ExpiresIn)
    	fmt.Println("You telphin Login: ", api.User.Login)
    	fmt.Println("You telphin Clinet ID: ", api.User.ClientId)
    	fmt.Println("You telphin is Admin: ", api.User.IsAdmin)
}
	

Example get Extension list


    exten, err := api.ExtensionList(api.User.ClientId, true)
    if err != nil {
        fmt.Println(err)
    }
    
    for _, e := range exten {
	fmt.Printf("Extension id: %d, Extension name: %s \n", e.ID, e.Name)

    }

Example download records

    
    exten, err := api.ExtensionList(api.User.ClientId, true)
    if err != nil {
       fmt.Println(err)
    }
    
    t := time.Now()
    rounded := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
    recordList, err := api.GetRecordList(exten[0].ID, rounded, time.Now(), "asc")
    if err != nil {
	fmt.Println(err)
    }
    
    for _, v := range recordList {
	api.DownloadRecord(v.RecordUUID, "./downloads/")
    }

All methods:

License:

MIT

Documentation

Index

Constants

View Source
const (
	API_URL        = "https://apiproxy.telphin.ru"
	API_VERSION    = "/api/ver1.0"
	DATE_FORMAT    = "2006-01-02 15:04:05"
	EXPIRES_OFFSET = 400
	API            = API_URL + API_VERSION
)

Variables

This section is empty.

Functions

func HeartBeat

func HeartBeat(refresh func() (*OAuth, error))

Types

type Authorizer

type Authorizer interface {
	Authorization() (*OAuth, error)
}

type Did

type Did struct {
	ID          uint32 `json:"id"`
	Name        string `json:"name"`
	Domain      string `json:"domain"`
	ExtensionId uint32 `json:"extension_id"`
	ClientId    uint32 `json:"client_id"`
}

type EventResp

type EventResp struct {
	Url       string `json:"url"`
	EventType string `json:"event_type"`
	Method    string `json:"method"`
	ID        uint32 `json:"id"`
}

type Extension

type Extension struct {
	Status             string `json:"status"`
	Domain             string `json:"domain"`
	CreateDate         string `json:"create_date"`
	Name               string `json:"name"`
	RFCid              bool   `json:"rfc_public_caller_id_number"`
	ExtensionGroupId   uint32 `json:"extension_group_id"`
	PublicCallerId     uint32 `json:"public_caller_id_number"`
	Label              string `json:"label"`
	CallerId           uint32 `json:"caller_id_name"`
	ClientId           uint32 `json:"client_id"`
	FromCallerId       bool   `json:"from_public_caller_id_number"`
	ExtraParams        string `json:"extra_params"`
	DialRuleLimit      string `json:"dial_rule_limit"`
	DialRuleId         string `json:"dial_rule_id"`
	AniRFC3325         bool   `json:"ani_rfc3325"`
	Type               string `json:"type"`
	ID                 uint32 `json:"id"`
	DidAsTransCallerId uint32 `json:"did_as_transfer_caller_id"`
	ExtensionNumber    string
}

type IVR

type IVR struct {
	LifetimeExpAction      string `json:"lifetime_exp_action"`
	EntryContext           uint64 `json:"entry_context"`
	LifetimeExpTransferDst string `json:"lifetime_exp_transfer_dst"`
	VmEnabled              bool   `json:"vm_enabled"`
	VmGreeting             uint64 `json:"vm_greeting"`
	Lifetime               uint64 `json:"lifetime"`
	VmAttachFile           bool   `json:"vm_attach_file"`
	SleepTime              uint64 `json:"sleep_time"`
	VmMailto               string `json:"vm_mailto"`
}

type OAuth

type OAuth struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   uint32 `json:"expires_in"`
	Scope       string `json:"scope"`
	User        *User
}

func NewAPI

func NewAPI(a Authorizer) (*OAuth, error)

func (*OAuth) AddEvent

func (oauth *OAuth) AddEvent(extensionId uint32, callbackUrl string, method string, eventType string) (*EventResp, error)

func (*OAuth) DeleteEventAll

func (oauth *OAuth) DeleteEventAll(extensionId uint32) error

func (*OAuth) DeleteEventByID

func (oauth *OAuth) DeleteEventByID(extensionId uint32, eventId uint32) error

func (*OAuth) DownloadRecord

func (oauth *OAuth) DownloadRecord(recordUUID string, path string) (string, error)

func (*OAuth) ExtensionList

func (oauth *OAuth) ExtensionList(ClientId uint32, setExtensionNumber ...bool) ([]Extension, error)

func (*OAuth) GetDidById

func (oauth *OAuth) GetDidById(didId uint64) (*Did, error)

func (*OAuth) GetDidList

func (oauth *OAuth) GetDidList() ([]Did, error)

func (*OAuth) GetEventByID

func (oauth *OAuth) GetEventByID(extensionId uint32, eventId uint32) (*EventResp, error)

func (*OAuth) GetEventList

func (oauth *OAuth) GetEventList(extensionId uint32) ([]EventResp, error)

func (*OAuth) GetIVR

func (oauth *OAuth) GetIVR(extensionId uint32) (*IVR, error)

func (*OAuth) GetQueue

func (oauth *OAuth) GetQueue(extensionId uint32) (*Queue, error)

func (*OAuth) GetRecordList

func (oauth *OAuth) GetRecordList(extensionId uint32, startDate time.Time, endDate time.Time, order string) ([]RecordList, error)

func (*OAuth) GetRecordStorageUrl

func (oauth *OAuth) GetRecordStorageUrl(recordUUID string) string

func (*OAuth) UpdateDidById

func (oauth *OAuth) UpdateDidById(didId uint64, ExtensionId uint32) (*Did, error)

func (*OAuth) UpdateEventByID

func (oauth *OAuth) UpdateEventByID(extensionId uint32, callbackUrl string, method string, eventType string, eventId uint32) (*EventResp, error)

func (*OAuth) UpdateIVR

func (oauth *OAuth) UpdateIVR(extensionId uint32, object ...interface{}) (*IVR, error)

func (*OAuth) UpdateQueue

func (oauth *OAuth) UpdateQueue(extensionId uint32, object ...interface{}) (*IVR, error)

type PasswordAuth

type PasswordAuth struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Username     string `json:"username"`
	Password     string `json:"password"`
}

func (*PasswordAuth) Authorization

func (p *PasswordAuth) Authorization() (*OAuth, error)

type Queue

type Queue struct {
	Sound                     uint64 `json:"sound"`
	TierRulesApply            bool   `json:"tier_rules_apply"`
	ExitKey                   string `json:"exit_key"`
	TimeoutTransferDst        string `json:"timeout_transfer_dst"`
	MaxWaitTime               uint64 `json:"max_wait_time"`
	RecordEnabled             bool   `json:"record_enabled"`
	MaxWaitTimeWithNoAgent    uint64 `json:"max_wait_time_with_no_agent"`
	Strategy                  string `json:"strategy"`
	TierRuleWaitMultiplyLevel bool   `json:"tier_rule_wait_multiply_level"`
	ExtensionID               uint64 `json:"extension_id"`
	AnnounceFrequency         uint64 `json:"announce_frequency"`
	ExitTransferDst           string `json:"exit_transfer_dst"`
	SoundType                 string `json:"sound_type"`
	TierRuleWaitSecond        uint64 `json:"tier_rule_wait_second"`
	AnnounceSound             uint64 `json:"announce_sound"`
	StartSound                uint64 `json:"start_sound"`
}

type RecordList

type RecordList struct {
	ToUsername            string `json:"to_username"`
	SourceNumber          string `json:"source_number"`
	Result                string `json:"result"`
	Duration              uint32 `json:"duration"`
	ToDomain              string `json:"to_domain"`
	DidNumber             string `json:"did_number"`
	HangupTimeGMT         string `json:"hangup_time_gmt"`
	RecordFileSize        uint64 `json:"record_file_size"`
	FromUsername          string `json:"from_username"`
	Application           string `json:"application"`
	StartTimeGMT          string `json:"start_time_gmt"`
	ExtNumberReg          string `json:"ext_number_reg"`
	HangupCause           string `json:"hangup_cause"`
	ExtensionGroupOwnerID uint64 `json:"extension_group_owner_id"`
	InitTimeGMT           string `json:"init_time_gmt"`
	DestDomain            string `json:"dest_domain"`
	RecordUUID            string `json:"record_uuid"`
	FromDomain            string `json:"from_domain"`
	SourceDomain          string `json:"source_domain"`
	ExtensionType         string `json:"extension_type"`
	DidDomain             string `json:"did_domain"`
	FromScreenName        string `json:"from_screen_name"`
	ExtensionName         string `json:"extension_name"`
	Flow                  string `json:"flow"`
	DestNumber            string `json:"dest_number"`
	ExtensionId           uint32 `json:"extension_id"`
	CallUUID              string `json:"call_uuid"`
	ClientOwnerID         uint64 `json:"client_owner_id"`
}

type Storage

type Storage struct {
	Url string `json:"record_url"`
}

type Trusted

type Trusted struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

func (*Trusted) Authorization

func (t *Trusted) Authorization() (*OAuth, error)

type User

type User struct {
	DealerID         string `json:"dealer_id"`
	IsAdmin          bool   `json:"admin"`
	Access           string `json:"access"`
	ExtensionId      uint32 `json:"extension_id"`
	ClientId         uint32 `json:"client_id"`
	ExtensionGroupID uint32 `json:"extension_group_id"`
	Timezone         string `json:"timezone"`
	Login            string `json:"login"`
	Id               uint32 `json:"id"`
}

Jump to

Keyboard shortcuts

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